Generate contains function for all combinations of primitive numeric ranges and arguments.
#KT-6361
This commit is contained in:
@@ -10,6 +10,216 @@ import java.util.*
|
||||
|
||||
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun IntRange.contains(item: Byte): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun LongRange.contains(item: Byte): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun ShortRange.contains(item: Byte): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun DoubleRange.contains(item: Byte): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun FloatRange.contains(item: Byte): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun IntRange.contains(item: Double): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun LongRange.contains(item: Double): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun ByteRange.contains(item: Double): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun ShortRange.contains(item: Double): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun FloatRange.contains(item: Double): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun IntRange.contains(item: Float): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun LongRange.contains(item: Float): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun ByteRange.contains(item: Float): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun ShortRange.contains(item: Float): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun DoubleRange.contains(item: Float): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun LongRange.contains(item: Int): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun ByteRange.contains(item: Int): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun ShortRange.contains(item: Int): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun DoubleRange.contains(item: Int): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun FloatRange.contains(item: Int): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun IntRange.contains(item: Long): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun ByteRange.contains(item: Long): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun ShortRange.contains(item: Long): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun DoubleRange.contains(item: Long): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun FloatRange.contains(item: Long): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun IntRange.contains(item: Short): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun LongRange.contains(item: Short): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun ByteRange.contains(item: Short): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun DoubleRange.contains(item: Short): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [item] belongs to this range.
|
||||
*/
|
||||
public fun FloatRange.contains(item: Short): Boolean {
|
||||
return start <= item && item <= end
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression from this value down to the specified [to] value with the increment -1.
|
||||
* The [to] value has to be less than this value.
|
||||
|
||||
@@ -21,6 +21,14 @@ public class RangeTest {
|
||||
|
||||
assertFalse(range.isEmpty())
|
||||
|
||||
assertTrue(1.toShort() in range)
|
||||
assertTrue(1.toByte() in range)
|
||||
assertTrue(1.toLong() in range)
|
||||
assertTrue(1.toFloat() in range)
|
||||
assertTrue(1.toDouble() in range)
|
||||
|
||||
assertFalse(Long.MAX_VALUE in range)
|
||||
|
||||
val openRange = 1 until 10
|
||||
assertTrue(9 in openRange)
|
||||
assertFalse(10 in openRange)
|
||||
@@ -42,9 +50,18 @@ public class RangeTest {
|
||||
|
||||
assertFalse(10.toByte() in range)
|
||||
assertFalse(111.toByte() in range)
|
||||
|
||||
|
||||
assertFalse(range.isEmpty())
|
||||
|
||||
|
||||
assertTrue(1.toShort() in range)
|
||||
assertTrue(1.toInt() in range)
|
||||
assertTrue(1.toLong() in range)
|
||||
assertTrue(1.toFloat() in range)
|
||||
assertTrue(1.toDouble() in range)
|
||||
|
||||
assertFalse(Long.MAX_VALUE in range)
|
||||
|
||||
val openRange = 1.toByte() until 10.toByte()
|
||||
assertTrue(9.toByte() in openRange)
|
||||
assertFalse(10.toByte() in openRange)
|
||||
@@ -70,6 +87,14 @@ public class RangeTest {
|
||||
|
||||
assertFalse(range.isEmpty())
|
||||
|
||||
assertTrue(1.toByte() in range)
|
||||
assertTrue(1.toInt() in range)
|
||||
assertTrue(1.toLong() in range)
|
||||
assertTrue(1.toFloat() in range)
|
||||
assertTrue(1.toDouble() in range)
|
||||
|
||||
assertFalse(Long.MAX_VALUE in range)
|
||||
|
||||
val openRange = 1.toShort() until 10.toShort()
|
||||
assertTrue(9.toShort() in openRange)
|
||||
assertFalse(10.toShort() in openRange)
|
||||
@@ -94,6 +119,14 @@ public class RangeTest {
|
||||
|
||||
assertFalse(range.isEmpty())
|
||||
|
||||
assertTrue(1.toByte() in range)
|
||||
assertTrue(1.toShort() in range)
|
||||
assertTrue(1.toInt() in range)
|
||||
assertTrue(1.toFloat() in range)
|
||||
assertTrue(1.toDouble() in range)
|
||||
|
||||
assertFalse(Double.MAX_VALUE in range)
|
||||
|
||||
val openRange = 1L until 10L
|
||||
assertTrue(9L in openRange)
|
||||
assertFalse(10L in openRange)
|
||||
@@ -144,6 +177,12 @@ public class RangeTest {
|
||||
assertFalse(1e200 in range)
|
||||
|
||||
assertFalse(range.isEmpty())
|
||||
|
||||
assertTrue(1.toByte() in range)
|
||||
assertTrue(1.toShort() in range)
|
||||
assertTrue(1.toInt() in range)
|
||||
assertTrue(1.toLong() in range)
|
||||
assertTrue(1.toFloat() in range)
|
||||
}
|
||||
|
||||
test fun floatRange() {
|
||||
@@ -164,6 +203,14 @@ public class RangeTest {
|
||||
assertFalse(1e30f in range)
|
||||
|
||||
assertFalse(range.isEmpty())
|
||||
|
||||
assertTrue(1.toByte() in range)
|
||||
assertTrue(1.toShort() in range)
|
||||
assertTrue(1.toInt() in range)
|
||||
assertTrue(1.toLong() in range)
|
||||
assertTrue(1.toDouble() in range)
|
||||
|
||||
assertFalse(Double.MAX_VALUE in range)
|
||||
}
|
||||
|
||||
test fun isEmpty() {
|
||||
|
||||
Reference in New Issue
Block a user