Add tests for SIZE_BYTES and SIZE_BITS constants

#KT-8247 Fixed
This commit is contained in:
Ilya Gorbunov
2018-06-29 13:00:34 +03:00
parent fa2f1311d7
commit 92e149fa40
@@ -173,5 +173,23 @@ class NumbersTest {
}
}
@Test fun sizeInBitsAndBytes() {
fun testSizes(companion: Any, sizeBytes: Int, sizeBits: Int, expectedSizeBytes: Int) {
assertEquals(expectedSizeBytes, sizeBytes, companion.toString())
assertEquals(expectedSizeBytes * 8, sizeBits, companion.toString())
}
testSizes(Char, Char.SIZE_BYTES, Char.SIZE_BITS, 2)
testSizes(Byte, Byte.SIZE_BYTES, Byte.SIZE_BITS, 1)
testSizes(Short, Short.SIZE_BYTES, Short.SIZE_BITS, 2)
testSizes(Int, Int.SIZE_BYTES, Int.SIZE_BITS, 4)
testSizes(Long, Long.SIZE_BYTES, Long.SIZE_BITS, 8)
testSizes(UByte, UByte.SIZE_BYTES, UByte.SIZE_BITS, 1)
testSizes(UShort, UShort.SIZE_BYTES, UShort.SIZE_BITS, 2)
testSizes(UInt, UInt.SIZE_BYTES, UInt.SIZE_BITS, 4)
testSizes(ULong, ULong.SIZE_BYTES, ULong.SIZE_BITS, 8)
}
}