Tests for all kinds of ranges and sequences.
This commit is contained in:
@@ -0,0 +1,241 @@
|
||||
package language
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import org.junit.Test as test
|
||||
|
||||
public class RangeIterationTest {
|
||||
private fun <N> doTest(
|
||||
sequence: NumberSequence<N>,
|
||||
expectedStart: N,
|
||||
expectedEnd: N,
|
||||
expectedIncrement: Number,
|
||||
expectedElements: List<N>
|
||||
) {
|
||||
assertEquals(expectedStart, sequence.start)
|
||||
assertEquals(expectedEnd, sequence.end)
|
||||
assertEquals(expectedIncrement, sequence.increment)
|
||||
|
||||
assertEquals(expectedElements, sequence.toList())
|
||||
}
|
||||
|
||||
test fun emptyConstant() {
|
||||
doTest(IntRange.EMPTY, 1, 0, 1, listOf())
|
||||
doTest(ByteRange.EMPTY, 1.toByte(), 0.toByte(), 1, listOf())
|
||||
doTest(ShortRange.EMPTY, 1.toShort(), 0.toShort(), 1, listOf())
|
||||
doTest(LongRange.EMPTY, 1.toLong(), 0.toLong(), 1.toLong(), listOf())
|
||||
|
||||
doTest(CharRange.EMPTY, 1.toChar(), 0.toChar(), 1, listOf())
|
||||
|
||||
doTest(DoubleRange.EMPTY, 1.0, 0.0, 1.0, listOf())
|
||||
doTest(FloatRange.EMPTY, 1.0.toFloat(), 0.0.toFloat(), 1.0.toFloat(), listOf())
|
||||
}
|
||||
|
||||
test fun emptyRange() {
|
||||
doTest(10..5, 10, 5, 1, listOf())
|
||||
doTest(10.toByte()..-5.toByte(), 10.toByte(), -5.toByte(), 1, listOf())
|
||||
doTest(10.toShort()..-5.toShort(), 10.toShort(), -5.toShort(), 1, listOf())
|
||||
doTest(10.toLong()..-5.toLong(), 10.toLong(), -5.toLong(), 1.toLong(), listOf())
|
||||
|
||||
doTest('z'..'a', 'z', 'a', 1, listOf())
|
||||
|
||||
doTest(5.0..-1.0, 5.0, -1.0, 1.0, listOf())
|
||||
doTest(5.0.toFloat()..-1.0.toFloat(), 5.0.toFloat(), -1.0.toFloat(), 1.toFloat(), listOf())
|
||||
}
|
||||
|
||||
test fun oneElementRange() {
|
||||
doTest(5..5, 5, 5, 1, listOf(5))
|
||||
doTest(5.toByte()..5.toByte(), 5.toByte(), 5.toByte(), 1, listOf(5.toByte()))
|
||||
doTest(5.toShort()..5.toShort(), 5.toShort(), 5.toShort(), 1, listOf(5.toShort()))
|
||||
doTest(5.toLong()..5.toLong(), 5.toLong(), 5.toLong(), 1.toLong(), listOf(5.toLong()))
|
||||
|
||||
doTest('k'..'k', 'k', 'k', 1, listOf('k'))
|
||||
|
||||
doTest(5.0..5.0, 5.0, 5.0, 1.0, listOf(5.0))
|
||||
doTest(5.0.toFloat()..5.0.toFloat(), 5.0.toFloat(), 5.0.toFloat(), 1.toFloat(), listOf(5.0.toFloat()))
|
||||
}
|
||||
|
||||
test fun simpleRange() {
|
||||
doTest(3..9, 3, 9, 1, listOf(3, 4, 5, 6, 7, 8, 9))
|
||||
doTest(3.toByte()..9.toByte(), 3.toByte(), 9.toByte(), 1, listOf<Byte>(3, 4, 5, 6, 7, 8, 9))
|
||||
doTest(3.toShort()..9.toShort(), 3.toShort(), 9.toShort(), 1, listOf<Short>(3, 4, 5, 6, 7, 8, 9))
|
||||
doTest(3.toLong()..9.toLong(), 3.toLong(), 9.toLong(), 1.toLong(), listOf<Long>(3, 4, 5, 6, 7, 8, 9))
|
||||
|
||||
doTest('c'..'g', 'c', 'g', 1, listOf('c', 'd', 'e', 'f', 'g'))
|
||||
|
||||
doTest(3.0..9.0, 3.0, 9.0, 1.0, listOf(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))
|
||||
doTest(3.0.toFloat()..9.0.toFloat(), 3.0.toFloat(), 9.0.toFloat(), 1.toFloat(),
|
||||
listOf<Float>(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))
|
||||
}
|
||||
|
||||
|
||||
test fun emptyDownto() {
|
||||
doTest(5 downTo 10, 5, 10, -1, listOf())
|
||||
doTest(5.toByte() downTo 10.toByte(), 5.toByte(), 10.toByte(), -1, listOf())
|
||||
doTest(5.toShort() downTo 10.toShort(), 5.toShort(), 10.toShort(), -1, listOf())
|
||||
doTest(5.toLong() downTo 10.toLong(), 5.toLong(), 10.toLong(), -1.toLong(), listOf())
|
||||
|
||||
doTest('a' downTo 'z', 'a', 'z', -1, listOf())
|
||||
|
||||
doTest(-1.0 downTo 5.0, -1.0, 5.0, -1.0, listOf())
|
||||
doTest(-1.0.toFloat() downTo 5.0.toFloat(), -1.0.toFloat(), 5.0.toFloat(), -1.0.toFloat(), listOf())
|
||||
}
|
||||
|
||||
test fun oneElementDownTo() {
|
||||
doTest(5 downTo 5, 5, 5, -1, listOf(5))
|
||||
doTest(5.toByte() downTo 5.toByte(), 5.toByte(), 5.toByte(), -1, listOf(5.toByte()))
|
||||
doTest(5.toShort() downTo 5.toShort(), 5.toShort(), 5.toShort(), -1, listOf(5.toShort()))
|
||||
doTest(5.toLong() downTo 5.toLong(), 5.toLong(), 5.toLong(), -1.toLong(), listOf(5.toLong()))
|
||||
|
||||
doTest('k' downTo 'k', 'k', 'k', -1, listOf('k'))
|
||||
|
||||
doTest(5.0 downTo 5.0, 5.0, 5.0, -1.0, listOf(5.0))
|
||||
doTest(5.0.toFloat() downTo 5.0.toFloat(), 5.0.toFloat(), 5.0.toFloat(), -1.0.toFloat(), listOf(5.0.toFloat()))
|
||||
}
|
||||
|
||||
test fun simpleDownTo() {
|
||||
doTest(9 downTo 3, 9, 3, -1, listOf(9, 8, 7, 6, 5, 4, 3))
|
||||
doTest(9.toByte() downTo 3.toByte(), 9.toByte(), 3.toByte(), -1, listOf<Byte>(9, 8, 7, 6, 5, 4, 3))
|
||||
doTest(9.toShort() downTo 3.toShort(), 9.toShort(), 3.toShort(), -1, listOf<Short>(9, 8, 7, 6, 5, 4, 3))
|
||||
doTest(9.toLong() downTo 3.toLong(), 9.toLong(), 3.toLong(), -1.toLong(), listOf<Long>(9, 8, 7, 6, 5, 4, 3))
|
||||
|
||||
doTest('g' downTo 'c', 'g', 'c', -1, listOf('g', 'f', 'e', 'd', 'c'))
|
||||
|
||||
doTest(9.0 downTo 3.0, 9.0, 3.0, -1.0, listOf(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0))
|
||||
doTest(9.0.toFloat() downTo 3.0.toFloat(), 9.0.toFloat(), 3.0.toFloat(), -1.0.toFloat(),
|
||||
listOf<Float>(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0))
|
||||
}
|
||||
|
||||
|
||||
test fun simpleSteppedRange() {
|
||||
doTest(3..9 step 2, 3, 9, 2, listOf(3, 5, 7, 9))
|
||||
doTest(3.toByte()..9.toByte() step 2, 3.toByte(), 9.toByte(), 2, listOf<Byte>(3, 5, 7, 9))
|
||||
doTest(3.toShort()..9.toShort() step 2, 3.toShort(), 9.toShort(), 2, listOf<Short>(3, 5, 7, 9))
|
||||
doTest(3.toLong()..9.toLong() step 2.toLong(), 3.toLong(), 9.toLong(), 2.toLong(), listOf<Long>(3, 5, 7, 9))
|
||||
|
||||
doTest('c'..'g' step 2, 'c', 'g', 2, listOf('c', 'e', 'g'))
|
||||
|
||||
doTest(4.0..6.0 step 0.5, 4.0, 6.0, 0.5, listOf(4.0, 4.5, 5.0, 5.5, 6.0))
|
||||
doTest(4.0.toFloat()..6.0.toFloat() step 0.5.toFloat(), 4.0.toFloat(), 6.0.toFloat(), 0.5.toFloat(),
|
||||
listOf<Float>(4.0, 4.5, 5.0, 5.5, 6.0))
|
||||
}
|
||||
|
||||
test fun simpleSteppedDownTo() {
|
||||
doTest(9 downTo 3 step 2, 9, 3, -2, listOf(9, 7, 5, 3))
|
||||
doTest(9.toByte() downTo 3.toByte() step 2, 9.toByte(), 3.toByte(), -2, listOf<Byte>(9, 7, 5, 3))
|
||||
doTest(9.toShort() downTo 3.toShort() step 2, 9.toShort(), 3.toShort(), -2, listOf<Short>(9, 7, 5, 3))
|
||||
doTest(9.toLong() downTo 3.toLong() step 2.toLong(), 9.toLong(), 3.toLong(), -2.toLong(), listOf<Long>(9, 7, 5, 3))
|
||||
|
||||
doTest('g' downTo 'c' step 2, 'g', 'c', -2, listOf('g', 'e', 'c'))
|
||||
|
||||
doTest(6.0 downTo 4.0 step 0.5, 6.0, 4.0, -0.5, listOf(6.0, 5.5, 5.0, 4.5, 4.0))
|
||||
doTest(6.0.toFloat() downTo 4.0.toFloat() step 0.5.toFloat(), 6.0.toFloat(), 4.0.toFloat(), -0.5.toFloat(),
|
||||
listOf<Float>(6.0, 5.5, 5.0, 4.5, 4.0))
|
||||
}
|
||||
|
||||
|
||||
// 'inexact' means last element is not equal to sequence end
|
||||
test fun inexactSteppedRange() {
|
||||
doTest(3..8 step 2, 3, 8, 2, listOf(3, 5, 7))
|
||||
doTest(3.toByte()..8.toByte() step 2, 3.toByte(), 8.toByte(), 2, listOf<Byte>(3, 5, 7))
|
||||
doTest(3.toShort()..8.toShort() step 2, 3.toShort(), 8.toShort(), 2, listOf<Short>(3, 5, 7))
|
||||
doTest(3.toLong()..8.toLong() step 2.toLong(), 3.toLong(), 8.toLong(), 2.toLong(), listOf<Long>(3, 5, 7))
|
||||
|
||||
doTest('a'..'d' step 2, 'a', 'd', 2, listOf('a', 'c'))
|
||||
|
||||
doTest(4.0..5.8 step 0.5, 4.0, 5.8, 0.5, listOf(4.0, 4.5, 5.0, 5.5))
|
||||
doTest(4.0.toFloat()..5.8.toFloat() step 0.5.toFloat(), 4.0.toFloat(), 5.8.toFloat(), 0.5.toFloat(),
|
||||
listOf<Float>(4.0, 4.5, 5.0, 5.5))
|
||||
}
|
||||
|
||||
// 'inexact' means last element is not equal to sequence end
|
||||
test fun inexactSteppedDownTo() {
|
||||
doTest(8 downTo 3 step 2, 8, 3, -2, listOf(8, 6, 4))
|
||||
doTest(8.toByte() downTo 3.toByte() step 2, 8.toByte(), 3.toByte(), -2, listOf<Byte>(8, 6, 4))
|
||||
doTest(8.toShort() downTo 3.toShort() step 2, 8.toShort(), 3.toShort(), -2, listOf<Short>(8, 6, 4))
|
||||
doTest(8.toLong() downTo 3.toLong() step 2.toLong(), 8.toLong(), 3.toLong(), -2.toLong(), listOf<Long>(8, 6, 4))
|
||||
|
||||
doTest('d' downTo 'a' step 2, 'd', 'a', -2, listOf('d', 'b'))
|
||||
|
||||
doTest(5.5 downTo 3.7 step 0.5, 5.5, 3.7, -0.5, listOf(5.5, 5.0, 4.5, 4.0))
|
||||
doTest(5.5.toFloat() downTo 3.7.toFloat() step 0.5.toFloat(), 5.5.toFloat(), 3.7.toFloat(), -0.5.toFloat(),
|
||||
listOf<Float>(5.5, 5.0, 4.5, 4.0))
|
||||
}
|
||||
|
||||
|
||||
test fun reversedEmptyRange() {
|
||||
doTest((5..3).reversed(), 3, 5, -1, listOf())
|
||||
doTest((5.toByte()..3.toByte()).reversed(), 3.toByte(), 5.toByte(), -1, listOf())
|
||||
doTest((5.toShort()..3.toShort()).reversed(), 3.toShort(), 5.toShort(), -1, listOf())
|
||||
doTest((5.toLong()..3.toLong()).reversed(), 3.toLong(), 5.toLong(), -1.toLong(), listOf())
|
||||
|
||||
doTest(('c'..'a').reversed(), 'a', 'c', -1, listOf())
|
||||
|
||||
doTest((5.0..3.0).reversed(), 3.0, 5.0, -1.0, listOf())
|
||||
doTest((5.0.toFloat()..3.0.toFloat()).reversed(), 3.0.toFloat(), 5.0.toFloat(), -1.toFloat(), listOf())
|
||||
}
|
||||
|
||||
test fun reversedEmptyBackSequence() {
|
||||
doTest((3 downTo 5).reversed(), 5, 3, 1, listOf())
|
||||
doTest((3.toByte() downTo 5.toByte()).reversed(), 5.toByte(), 3.toByte(), 1, listOf())
|
||||
doTest((3.toShort() downTo 5.toShort()).reversed(), 5.toShort(), 3.toShort(), 1, listOf())
|
||||
doTest((3.toLong() downTo 5.toLong()).reversed(), 5.toLong(), 3.toLong(), 1.toLong(), listOf())
|
||||
|
||||
doTest(('a' downTo 'c').reversed(), 'c', 'a', 1, listOf())
|
||||
|
||||
doTest((3.0 downTo 5.0).reversed(), 5.0, 3.0, 1.0, listOf())
|
||||
doTest((3.0.toFloat() downTo 5.0.toFloat()).reversed(), 5.0.toFloat(), 3.0.toFloat(), 1.toFloat(), listOf())
|
||||
}
|
||||
|
||||
test fun reversedRange() {
|
||||
doTest((3..5).reversed(), 5, 3, -1, listOf(5, 4, 3))
|
||||
doTest((3.toByte()..5.toByte()).reversed(), 5.toByte(), 3.toByte(), -1, listOf<Byte>(5, 4, 3))
|
||||
doTest((3.toShort()..5.toShort()).reversed(), 5.toShort(), 3.toShort(), -1, listOf<Short>(5, 4, 3))
|
||||
doTest((3.toLong()..5.toLong()).reversed(), 5.toLong(), 3.toLong(), -1.toLong(), listOf<Long>(5, 4, 3))
|
||||
|
||||
doTest(('a'..'c').reversed(), 'c', 'a', -1, listOf('c', 'b', 'a'))
|
||||
|
||||
doTest((3.0..5.0).reversed(), 5.0, 3.0, -1.0, listOf(5.0, 4.0, 3.0))
|
||||
doTest((3.0.toFloat()..5.0.toFloat()).reversed(), 5.0.toFloat(), 3.0.toFloat(), -1.toFloat(),
|
||||
listOf<Float>(5.0, 4.0, 3.0))
|
||||
}
|
||||
|
||||
test fun reversedBackSequence() {
|
||||
doTest((5 downTo 3).reversed(), 3, 5, 1, listOf(3, 4, 5))
|
||||
doTest((5.toByte() downTo 3.toByte()).reversed(), 3.toByte(), 5.toByte(), 1, listOf<Byte>(3, 4, 5))
|
||||
doTest((5.toShort() downTo 3.toShort()).reversed(), 3.toShort(), 5.toShort(), 1, listOf<Short>(3, 4, 5))
|
||||
doTest((5.toLong() downTo 3.toLong()).reversed(), 3.toLong(), 5.toLong(), 1.toLong(), listOf<Long>(3, 4, 5))
|
||||
|
||||
doTest(('c' downTo 'a').reversed(), 'a', 'c', 1, listOf('a', 'b', 'c'))
|
||||
|
||||
doTest((5.0 downTo 3.0).reversed(), 3.0, 5.0, 1.0, listOf(3.0, 4.0, 5.0))
|
||||
doTest((5.0.toFloat() downTo 3.0.toFloat()).reversed(), 3.0.toFloat(), 5.0.toFloat(), 1.toFloat(),
|
||||
listOf<Float>(3.0, 4.0, 5.0))
|
||||
}
|
||||
|
||||
test fun reversedSimpleSteppedRange() {
|
||||
doTest((3..9 step 2).reversed(), 9, 3, -2, listOf(9, 7, 5, 3))
|
||||
doTest((3.toByte()..9.toByte() step 2).reversed(), 9.toByte(), 3.toByte(), -2, listOf<Byte>(9, 7, 5, 3))
|
||||
doTest((3.toShort()..9.toShort() step 2).reversed(), 9.toShort(), 3.toShort(), -2, listOf<Short>(9, 7, 5, 3))
|
||||
doTest((3.toLong()..9.toLong() step 2.toLong()).reversed(), 9.toLong(), 3.toLong(), -2.toLong(), listOf<Long>(9, 7, 5, 3))
|
||||
|
||||
doTest(('c'..'g' step 2).reversed(), 'g', 'c', -2, listOf('g', 'e', 'c'))
|
||||
|
||||
doTest((4.0..6.0 step 0.5).reversed(), 6.0, 4.0, -0.5, listOf(6.0, 5.5, 5.0, 4.5, 4.0))
|
||||
doTest((4.0.toFloat()..6.0.toFloat() step 0.5).reversed(), 6.0.toFloat(), 4.0.toFloat(), -0.5.toFloat(),
|
||||
listOf<Float>(6.0, 5.5, 5.0, 4.5, 4.0))
|
||||
}
|
||||
|
||||
// 'inexact' means last element is not equal to sequence end
|
||||
test fun reversedInexactSteppedDownTo() {
|
||||
doTest((8 downTo 3 step 2).reversed(), 3, 8, 2, listOf(3, 5, 7))
|
||||
doTest((8.toByte() downTo 3.toByte() step 2).reversed(), 3.toByte(), 8.toByte(), 2, listOf<Byte>(3, 5, 7))
|
||||
doTest((8.toShort() downTo 3.toShort() step 2).reversed(), 3.toShort(), 8.toShort(), 2, listOf<Short>(3, 5, 7))
|
||||
doTest((8.toLong() downTo 3.toLong() step 2.toLong()).reversed(), 3.toLong(), 8.toLong(), 2.toLong(), listOf<Long>(3, 5, 7))
|
||||
|
||||
doTest(('d' downTo 'a' step 2).reversed(), 'a', 'd', 2, listOf('a', 'c'))
|
||||
|
||||
doTest((5.8 downTo 4.0 step 0.5).reversed(), 4.0, 5.8, 0.5, listOf(4.0, 4.5, 5.0, 5.5))
|
||||
doTest((5.8.toFloat() downTo 4.0.toFloat() step 0.5).reversed(), 4.0.toFloat(), 5.8.toFloat(), 0.5.toFloat(),
|
||||
listOf<Float>(4.0, 4.5, 5.0, 5.5))
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,188 @@
|
||||
package language
|
||||
|
||||
import org.junit.Test as test
|
||||
import java.lang.Double as jDouble
|
||||
import java.lang.Float as jFloat
|
||||
import kotlin.test.*
|
||||
import org.junit.Test as test
|
||||
|
||||
class RangeTest {
|
||||
test fun upRange() {
|
||||
val range = 0.rangeTo(9)
|
||||
println("Have created up range: $range")
|
||||
assertTrue(range.contains(0))
|
||||
assertTrue(range.contains(1))
|
||||
assertTrue(range.contains(9))
|
||||
assertFalse(range.contains(10))
|
||||
public class RangeTest {
|
||||
test fun intRange() {
|
||||
val range = -5..9
|
||||
assertFalse(-1000 in range)
|
||||
assertFalse(-6 in range)
|
||||
|
||||
assertTrue(-5 in range)
|
||||
assertTrue(-4 in range)
|
||||
assertTrue(0 in range)
|
||||
assertTrue(3 in range)
|
||||
assertTrue(8 in range)
|
||||
assertTrue(9 in range)
|
||||
|
||||
assertFalse(10 in range)
|
||||
assertFalse(9000 in range)
|
||||
}
|
||||
|
||||
test fun downRange() {
|
||||
val range = 9.downTo(0)
|
||||
println("Have created down range: $range")
|
||||
assertTrue(range.contains(0))
|
||||
assertTrue(range.contains(1))
|
||||
assertTrue(range.contains(9))
|
||||
assertFalse(range.contains(10))
|
||||
test fun byteRange() {
|
||||
val range = -5.toByte()..9.toByte()
|
||||
assertFalse(-100.toByte() in range)
|
||||
assertFalse(-6.toByte() in range)
|
||||
|
||||
assertTrue(-5.toByte() in range)
|
||||
assertTrue(-4.toByte() in range)
|
||||
assertTrue(0.toByte() in range)
|
||||
assertTrue(3.toByte() in range)
|
||||
assertTrue(8.toByte() in range)
|
||||
assertTrue(9.toByte() in range)
|
||||
|
||||
assertFalse(10.toByte() in range)
|
||||
assertFalse(111.toByte() in range)
|
||||
}
|
||||
|
||||
test fun reversedRanges() {
|
||||
val intRange = 0..9
|
||||
val reversedIntRange = intRange.reversed()
|
||||
assertEquals(9, reversedIntRange.start)
|
||||
assertEquals(0, reversedIntRange.end)
|
||||
assertEquals(intRange.toList(), reversedIntRange.reversed().toList())
|
||||
test fun shortRange() {
|
||||
val range = -5.toShort()..9.toShort()
|
||||
assertFalse(-1000.toShort() in range)
|
||||
assertFalse(-6.toShort() in range)
|
||||
|
||||
val doubleRange = 0.0..9.0
|
||||
val reversedDoubleRange = doubleRange.reversed()
|
||||
assertEquals(9.0, reversedDoubleRange.start)
|
||||
assertEquals(0.0, reversedDoubleRange.end)
|
||||
assertEquals(doubleRange.toList(), reversedDoubleRange.reversed().toList())
|
||||
assertTrue(-5.toShort() in range)
|
||||
assertTrue(-4.toShort() in range)
|
||||
assertTrue(0.toShort() in range)
|
||||
assertTrue(3.toShort() in range)
|
||||
assertTrue(8.toShort() in range)
|
||||
assertTrue(9.toShort() in range)
|
||||
|
||||
assertFalse(10.toShort() in range)
|
||||
assertFalse(239.toShort() in range)
|
||||
}
|
||||
|
||||
test fun longRange() {
|
||||
val range = -5.toLong()..9.toLong()
|
||||
assertFalse(-10000000.toLong() in range)
|
||||
assertFalse(-6.toLong() in range)
|
||||
|
||||
assertTrue(-5.toLong() in range)
|
||||
assertTrue(-4.toLong() in range)
|
||||
assertTrue(0.toLong() in range)
|
||||
assertTrue(3.toLong() in range)
|
||||
assertTrue(8.toLong() in range)
|
||||
assertTrue(9.toLong() in range)
|
||||
|
||||
assertFalse(10.toLong() in range)
|
||||
assertFalse(10000000.toLong() in range)
|
||||
}
|
||||
|
||||
test fun charRange() {
|
||||
val range = 'c'..'w'
|
||||
assertFalse('0' in range)
|
||||
assertFalse('b' in range)
|
||||
|
||||
assertTrue('c' in range)
|
||||
assertTrue('d' in range)
|
||||
assertTrue('h' in range)
|
||||
assertTrue('m' in range)
|
||||
assertTrue('v' in range)
|
||||
assertTrue('w' in range)
|
||||
|
||||
assertFalse('z' in range)
|
||||
assertFalse('\u1000' in range)
|
||||
}
|
||||
|
||||
test fun doubleRange() {
|
||||
val range = -1.0..3.14159265358979
|
||||
assertFalse(jDouble.NEGATIVE_INFINITY in range)
|
||||
assertFalse(-1e200 in range)
|
||||
assertFalse(-100.0 in range)
|
||||
assertFalse(-1.00000000001 in range)
|
||||
|
||||
assertTrue(-1.0 in range)
|
||||
assertTrue(-0.99999999999 in range)
|
||||
assertTrue(0.0 in range)
|
||||
assertTrue(1.5 in range)
|
||||
assertTrue(3.1415 in range)
|
||||
assertTrue(3.14159265358979 in range)
|
||||
|
||||
assertFalse(3.15 in range)
|
||||
assertFalse(10.0 in range)
|
||||
assertFalse(1e200 in range)
|
||||
assertFalse(jDouble.POSITIVE_INFINITY in range)
|
||||
|
||||
assertFalse(jDouble.NaN in range)
|
||||
}
|
||||
|
||||
test fun floatRange() {
|
||||
val range = -1.0.toFloat()..3.14159.toFloat()
|
||||
assertFalse(jFloat.NEGATIVE_INFINITY in range)
|
||||
assertFalse(-1e30.toFloat() in range)
|
||||
assertFalse(-100.0.toFloat() in range)
|
||||
assertFalse(-1.00001.toFloat() in range)
|
||||
|
||||
assertTrue(-1.0.toFloat() in range)
|
||||
assertTrue(-0.99999.toFloat() in range)
|
||||
assertTrue(0.0.toFloat() in range)
|
||||
assertTrue(1.5.toFloat() in range)
|
||||
assertTrue(3.1415.toFloat() in range)
|
||||
assertTrue(3.14159.toFloat() in range)
|
||||
|
||||
assertFalse(3.15.toFloat() in range)
|
||||
assertFalse(10.0.toFloat() in range)
|
||||
assertFalse(1e30.toFloat() in range)
|
||||
assertFalse(jFloat.POSITIVE_INFINITY in range)
|
||||
|
||||
assertFalse(jFloat.NaN in range)
|
||||
}
|
||||
|
||||
test fun comparableRange() {
|
||||
val range1 = "island".."isle"
|
||||
assertTrue("island" in range1)
|
||||
assertTrue("isle" in range1)
|
||||
assertTrue("islandic" in range1)
|
||||
val range = "island".."isle"
|
||||
assertFalse("apple" in range)
|
||||
assertFalse("icicle" in range)
|
||||
|
||||
assertFalse("apple" in range1)
|
||||
assertFalse("icicle" in range1)
|
||||
assertTrue("island" in range)
|
||||
assertTrue("isle" in range)
|
||||
assertTrue("islandic" in range)
|
||||
|
||||
assertFalse("item" in range1)
|
||||
assertFalse("trail" in range1)
|
||||
assertFalse("item" in range)
|
||||
assertFalse("trail" in range)
|
||||
}
|
||||
|
||||
test fun illegalSequenceCreation() {
|
||||
// create sequence explicitly with increment = 0
|
||||
failsWith<IllegalArgumentException> { IntSequence(0, 5, 0) }
|
||||
failsWith<IllegalArgumentException> { ByteSequence(0, 5, 0) }
|
||||
failsWith<IllegalArgumentException> { ShortSequence(0, 5, 0) }
|
||||
failsWith<IllegalArgumentException> { LongSequence(0, 5, 0) }
|
||||
failsWith<IllegalArgumentException> { CharacterSequence('a', 'z', 0) }
|
||||
failsWith<IllegalArgumentException> { DoubleSequence(0.0, 5.0, 0.0) }
|
||||
failsWith<IllegalArgumentException> { FloatSequence(0.0.toFloat(), 5.0.toFloat(), 0.0.toFloat()) }
|
||||
|
||||
failsWith<IllegalArgumentException> { 0..5 step 0 }
|
||||
failsWith<IllegalArgumentException> { 0.toByte()..5.toByte() step 0 }
|
||||
failsWith<IllegalArgumentException> { 0.toShort()..5.toShort() step 0 }
|
||||
failsWith<IllegalArgumentException> { 0.toLong()..5.toLong() step 0.toLong() }
|
||||
failsWith<IllegalArgumentException> { 'a'..'z' step 0 }
|
||||
failsWith<IllegalArgumentException> { 0.0..5.0 step 0.0 }
|
||||
failsWith<IllegalArgumentException> { 0.0.toFloat()..5.0.toFloat() step 0.0.toFloat() }
|
||||
|
||||
failsWith<IllegalArgumentException> { 0 downTo -5 step 0 }
|
||||
failsWith<IllegalArgumentException> { 0.toByte() downTo -5.toByte() step 0 }
|
||||
failsWith<IllegalArgumentException> { 0.toShort() downTo -5.toShort() step 0 }
|
||||
failsWith<IllegalArgumentException> { 0.toLong() downTo -5.toLong() step 0.toLong() }
|
||||
failsWith<IllegalArgumentException> { 'z' downTo 'a' step 0 }
|
||||
failsWith<IllegalArgumentException> { 0.0 downTo -5.0 step 0.0 }
|
||||
failsWith<IllegalArgumentException> { 0.0.toFloat() downTo -5.0.toFloat() step 0.0.toFloat() }
|
||||
|
||||
failsWith<IllegalArgumentException> { 0..5 step -2 }
|
||||
failsWith<IllegalArgumentException> { 0.toByte()..5.toByte() step -2 }
|
||||
failsWith<IllegalArgumentException> { 0.toShort()..5.toShort() step -2 }
|
||||
failsWith<IllegalArgumentException> { 0.toLong()..5.toLong() step -2.toLong() }
|
||||
failsWith<IllegalArgumentException> { 'a'..'z' step -2 }
|
||||
failsWith<IllegalArgumentException> { 0.0..5.0 step -0.5 }
|
||||
failsWith<IllegalArgumentException> { 0.0.toFloat()..5.0.toFloat() step -0.5.toFloat() }
|
||||
|
||||
failsWith<IllegalArgumentException> { 0 downTo -5 step -2 }
|
||||
failsWith<IllegalArgumentException> { 0.toByte() downTo -5.toByte() step -2 }
|
||||
failsWith<IllegalArgumentException> { 0.toShort() downTo -5.toShort() step -2 }
|
||||
failsWith<IllegalArgumentException> { 0.toLong() downTo -5.toLong() step -2.toLong() }
|
||||
failsWith<IllegalArgumentException> { 'z' downTo 'a' step -2 }
|
||||
failsWith<IllegalArgumentException> { 0.0 downTo -5.0 step -0.5 }
|
||||
failsWith<IllegalArgumentException> { 0.0.toFloat() downTo -5.0.toFloat() step -0.5.toFloat() }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user