
commonMain.io.kotest.matchers.collections.unique.kt Maven / Gradle / Ivy
package io.kotest.matchers.collections
import io.kotest.matchers.Matcher
import io.kotest.matchers.MatcherResult
import io.kotest.matchers.should
import io.kotest.matchers.shouldNot
fun Iterable.shouldBeUnique(): Iterable {
toList().shouldBeUnique()
return this
}
fun Array.shouldBeUnique(): Array {
asList().shouldBeUnique()
return this
}
fun Collection.shouldBeUnique(): Collection {
this should beUnique()
return this
}
fun Iterable.shouldNotBeUnique(): Iterable {
toList().shouldNotBeUnique()
return this
}
fun Array.shouldNotBeUnique(): Array {
asList().shouldNotBeUnique()
return this
}
fun Collection.shouldNotBeUnique(): Collection {
this shouldNot beUnique()
return this
}
fun beUnique() = object : Matcher> {
override fun test(value: Collection) = MatcherResult(
value.toSet().size == value.size,
{ "Collection should be Unique" },
{
"Collection should contain at least one duplicate element"
})
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy