
commonMain.io.kotest.matchers.collections.bounds.kt Maven / Gradle / Ivy
package io.kotest.matchers.collections
import io.kotest.matchers.Matcher
import io.kotest.matchers.MatcherResult
import io.kotest.matchers.should
infix fun > Iterable.shouldHaveUpperBound(t: T): Iterable {
toList().shouldHaveUpperBound(t)
return this
}
infix fun > Array.shouldHaveUpperBound(t: T): Array {
asList().shouldHaveUpperBound(t)
return this
}
infix fun , C : Collection> C.shouldHaveUpperBound(t: T): C {
this should haveUpperBound(t)
return this
}
fun , C : Collection> haveUpperBound(t: T) = object : Matcher {
override fun test(value: C) = MatcherResult(
value.all { it <= t },
{ "Collection should have upper bound $t" },
{ "Collection should not have upper bound $t" })
}
infix fun > Iterable.shouldHaveLowerBound(t: T): Iterable {
toList().shouldHaveLowerBound(t)
return this
}
infix fun > Array.shouldHaveLowerBound(t: T): Array {
asList().shouldHaveLowerBound(t)
return this
}
infix fun , C : Collection> C.shouldHaveLowerBound(t: T): C {
this should haveLowerBound(t)
return this
}
fun , C : Collection> haveLowerBound(t: T) = object : Matcher {
override fun test(value: C) = MatcherResult(
value.all { t <= it },
{ "Collection should have lower bound $t" },
{ "Collection should not have lower bound $t" })
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy