KT-5044 implement missing Range#contains tests and move it to separate package
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Value(val x: Int) : Comparable<Value> {
|
||||
override fun compareTo(other: Value): Int {
|
||||
throw AssertionError("Should not be called")
|
||||
}
|
||||
}
|
||||
|
||||
class ValueRange(override val start: Value,
|
||||
override val endInclusive: Value) : ClosedRange<Value> {
|
||||
|
||||
override fun contains(value: Value): Boolean {
|
||||
return value.x == 42
|
||||
}
|
||||
}
|
||||
|
||||
operator fun Value.rangeTo(other: Value): ClosedRange<Value> = ValueRange(this, other)
|
||||
|
||||
fun box(): String {
|
||||
assert(Value(42) in Value(1)..Value(2))
|
||||
assert(Value(41) !in Value(40)..Value(42))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user