KT-5044 implement missing Range#contains tests and move it to separate package

This commit is contained in:
Vsevolod
2016-10-10 22:49:40 +03:00
committed by Dmitry Petrov
parent 0b3fb41eeb
commit d7ad27ac3b
13 changed files with 305 additions and 12 deletions
@@ -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"
}