Provide until function to construct integer ranges with an end being excluded from range.
#KT-4665 Fixed
This commit is contained in:
@@ -85,6 +85,14 @@ public class RangeIterationTest {
|
||||
listOf<Float>(3.0.toFloat(), 4.0.toFloat(), 5.0.toFloat(), 6.0.toFloat(), 7.0.toFloat(), 8.0.toFloat(), 9.0.toFloat()))
|
||||
}
|
||||
|
||||
test fun openRange() {
|
||||
doTest(1 until 5, 1, 4, 1, listOf(1, 2, 3, 4))
|
||||
doTest(1.toByte() until 5.toByte(), 1.toByte(), 4.toByte(), 1, listOf<Byte>(1, 2, 3, 4))
|
||||
doTest(1.toShort() until 5.toShort(), 1.toShort(), 4.toShort(), 1, listOf<Short>(1, 2, 3, 4))
|
||||
doTest(1L until 5L, 1L, 4L, 1L, listOf<Long>(1, 2, 3, 4))
|
||||
doTest('a' until 'd', 'a', 'c', 1, listOf('a', 'b', 'c'))
|
||||
}
|
||||
|
||||
|
||||
test fun emptyDownto() {
|
||||
doTest(5 downTo 10, 5, 10, -1, listOf())
|
||||
|
||||
@@ -20,6 +20,12 @@ public class RangeTest {
|
||||
assertFalse(9000 in range)
|
||||
|
||||
assertFalse(range.isEmpty())
|
||||
|
||||
val openRange = 1 until 10
|
||||
assertTrue(9 in openRange)
|
||||
assertFalse(10 in openRange)
|
||||
|
||||
assertTrue(fails { 1 until Int.MIN_VALUE } is IllegalArgumentException)
|
||||
}
|
||||
|
||||
test fun byteRange() {
|
||||
@@ -38,6 +44,13 @@ public class RangeTest {
|
||||
assertFalse(111.toByte() in range)
|
||||
|
||||
assertFalse(range.isEmpty())
|
||||
|
||||
val openRange = 1.toByte() until 10.toByte()
|
||||
assertTrue(9.toByte() in openRange)
|
||||
assertFalse(10.toByte() in openRange)
|
||||
|
||||
assertTrue(fails { 0.toByte() until Byte.MIN_VALUE } is IllegalArgumentException)
|
||||
|
||||
}
|
||||
|
||||
test fun shortRange() {
|
||||
@@ -56,6 +69,12 @@ public class RangeTest {
|
||||
assertFalse(239.toShort() in range)
|
||||
|
||||
assertFalse(range.isEmpty())
|
||||
|
||||
val openRange = 1.toShort() until 10.toShort()
|
||||
assertTrue(9.toShort() in openRange)
|
||||
assertFalse(10.toShort() in openRange)
|
||||
|
||||
assertTrue(fails { 0.toShort() until Short.MIN_VALUE } is IllegalArgumentException)
|
||||
}
|
||||
|
||||
test fun longRange() {
|
||||
@@ -74,6 +93,13 @@ public class RangeTest {
|
||||
assertFalse(10000000L in range)
|
||||
|
||||
assertFalse(range.isEmpty())
|
||||
|
||||
val openRange = 1L until 10L
|
||||
assertTrue(9L in openRange)
|
||||
assertFalse(10L in openRange)
|
||||
|
||||
assertTrue(fails { 0L until Long.MIN_VALUE } is IllegalArgumentException)
|
||||
|
||||
}
|
||||
|
||||
test fun charRange() {
|
||||
@@ -92,6 +118,12 @@ public class RangeTest {
|
||||
assertFalse('\u1000' in range)
|
||||
|
||||
assertFalse(range.isEmpty())
|
||||
|
||||
val openRange = 'A' until 'Z'
|
||||
assertTrue('Y' in openRange)
|
||||
assertFalse('Z' in openRange)
|
||||
|
||||
assertTrue(fails { 'A' until '\u0000' } is IllegalArgumentException)
|
||||
}
|
||||
|
||||
test fun doubleRange() {
|
||||
|
||||
Reference in New Issue
Block a user