com.github.spoptchev.kotlin.preconditions.matcher.ComparableMatcher.kt Maven / Gradle / Ivy
package com.github.spoptchev.kotlin.preconditions.matcher
import com.github.spoptchev.kotlin.preconditions.Condition
import com.github.spoptchev.kotlin.preconditions.Matcher
interface ComparableMatcher {
fun isLt(other: T) = isLessThan(other)
fun isLessThan(other: T) = object : Matcher>() {
override fun test(condition: Condition>) = condition.test {
withResult(value < other) { "$expectedTo be < $other" }
}
}
fun isLte(other: T) = isLessThanOrEqualTo(other)
fun isLessThanOrEqualTo(other: T) = object : Matcher>() {
override fun test(condition: Condition>) = condition.test {
withResult(value <= other) { "$expectedTo be <= $other" }
}
}
fun isGt(other: T) = isGreaterThan(other)
fun isGreaterThan(other: T) = object : Matcher>() {
override fun test(condition: Condition>) = condition.test {
withResult(value > other) { "$expectedTo be > $other" }
}
}
fun isGte(other: T) = isGreaterThanOrEqualTo(other)
fun isGreaterThanOrEqualTo(other: T) = object : Matcher>() {
override fun test(condition: Condition>) = condition.test {
withResult(value >= other) { "$expectedTo be >= $other" }
}
}
fun > isBetween(range: ClosedRange) = object : Matcher() {
override fun test(condition: Condition) = condition.test {
withResult(value in range) { "$expectedTo be in $range" }
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy