Klitos Kyriacou
07/19/2023, 2:13 PMcontainsOnly
(or Kotest's shouldContainOnly
)?
Description from AssertK: "Asserts the iterable contains only the expected elements, in any order. Duplicate values in the expected and actual are ignored."Jakub Gwóźdź
07/19/2023, 3:08 PM.toSet()
before matching might be required)Klitos Kyriacou
07/19/2023, 3:15 PMassertThat(listOf(0,0,0)).containsOnly(0)
is
expectThat(listOf(0,0,0).toSet()).containsExactlyInAnyOrder(0)
which is a bit more cumbersome.christophsturm
07/19/2023, 5:17 PMfun <T : Iterable<E>, E> Assertion.Builder<T>.containsOnly(vararg elements: E): Assertion.Builder<T> =
assert("contains only $elements") {
if (it.toSet() == elements.toSet()) pass() else fail()
}