diff --git a/libraries/stdlib/test/numbers/NumbersTest.kt b/libraries/stdlib/test/numbers/NumbersTest.kt index aa093e3c3fe..02e4663d648 100644 --- a/libraries/stdlib/test/numbers/NumbersTest.kt +++ b/libraries/stdlib/test/numbers/NumbersTest.kt @@ -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) + } } \ No newline at end of file