Add tests for open ranges

#KT-52932
This commit is contained in:
Ilya Gorbunov
2022-06-26 03:17:48 +03:00
committed by Space
parent 8584fe2725
commit 4475b15037
2 changed files with 71 additions and 1 deletions
@@ -40,11 +40,17 @@ public class URangeTest {
assertTrue(12u as UInt? in range)
assertFalse((-3).toUInt() as UInt? in range)
val closedRange = 1u..9u
val openRange = 1u until 10u
assertTrue(9u in openRange)
assertFalse(10u in openRange)
assertEquals(closedRange, openRange)
val openRange2 = 1u..<10u
assertEquals(closedRange, openRange2)
assertTrue((1u until UInt.MIN_VALUE).isEmpty())
assertFailsWith<IllegalStateException> { (1u..UInt.MAX_VALUE).endExclusive }
}
@Test
@@ -77,6 +83,8 @@ public class URangeTest {
val openRange = 1.toUByte() until 10.toUByte()
assertTrue(9.toUByte() in openRange)
assertFalse(10.toUByte() in openRange)
val openRange2 = 1.toUByte()..<10.toUByte()
assertEquals(openRange, openRange2)
assertTrue((UByte.MAX_VALUE until UByte.MIN_VALUE).isEmpty())
}
@@ -111,6 +119,8 @@ public class URangeTest {
val openRange = 1.toUShort() until 10.toUShort()
assertTrue(9.toUShort() in openRange)
assertFalse(10.toUShort() in openRange)
val openRange2 = 1.toUShort()..<10.toUShort()
assertEquals(openRange, openRange2)
assertTrue((0.toUShort() until UShort.MIN_VALUE).isEmpty())
}
@@ -144,11 +154,17 @@ public class URangeTest {
assertTrue(12uL as ULong? in range)
assertFalse((-3).toULong() as ULong? in range)
val closedRange = 1uL..9uL
val openRange = 1uL until 10uL
assertTrue(9uL in openRange)
assertFalse(10uL in openRange)
assertEquals(closedRange, openRange)
val openRange2 = 1uL..<10uL
assertEquals(closedRange, openRange2)
assertTrue((0uL until ULong.MIN_VALUE).isEmpty())
assertFailsWith<IllegalStateException> { (1uL..ULong.MAX_VALUE).endExclusive }
}
@Suppress("EmptyRange")
@@ -183,6 +199,7 @@ public class URangeTest {
assertTrue(0uL downTo (-1).toULong() == (-2).toULong() downTo (-1).toULong())
assertFalse(0u..1u == UIntRange.EMPTY)
assertTrue(0u..<0u == UIntRange.EMPTY)
}
@Suppress("EmptyRange")