From 92e149fa4065655d234e45ac9dd6170186692ae6 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 29 Jun 2018 13:00:34 +0300 Subject: [PATCH] Add tests for SIZE_BYTES and SIZE_BITS constants #KT-8247 Fixed --- libraries/stdlib/test/numbers/NumbersTest.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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