diff --git a/apis/fluent/atrium-api-fluent/src/commonTest/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/IterableLikeToContainCheckerSamples.kt b/apis/fluent/atrium-api-fluent/src/commonTest/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/IterableLikeToContainCheckerSamples.kt index 6bbd3a49f1..381ec8cfc3 100644 --- a/apis/fluent/atrium-api-fluent/src/commonTest/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/IterableLikeToContainCheckerSamples.kt +++ b/apis/fluent/atrium-api-fluent/src/commonTest/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/IterableLikeToContainCheckerSamples.kt @@ -6,6 +6,44 @@ import kotlin.test.Test import kotlin.collections.* class IterableLikeToContainCheckerSamples { + + @Test + fun atLeast() { + expect(listOf("A", "B", "C", "A", "B", "B")).toContain.inAnyOrder.atLeast(3).entry { + toEqual("B") + } + + expect(listOf(1, 2, 3, 4, 5, 6, 4)).toContain.inAnyOrder.atLeast(2).entry { + toBeGreaterThan(4) + } + + fails { // because "A" is only 1 in the List + expect(listOf("A", "B", "C")).toContain.inAnyOrder.atLeast(2).entry { + toEqual("A") + } + } + } + + + @Test + fun butAtMost() { + expect(listOf("A", "B", "C", "A", "B", "B")).toContain.inAnyOrder.atLeast(1).butAtMost(2).entry { + toEqual("A") + } + + fails { // because "B" is three times in the List + expect(listOf("A", "B", "C", "A", "B", "B")).toContain.inAnyOrder.atLeast(1).butAtMost(2).entry { + toEqual("B") + } + } + + fails { // because "C" is not in the List + expect(listOf("A", "B", "C", "A", "B", "B")).toContain.inAnyOrder.atLeast(1).butAtMost(2).entry { + toEqual("D") + } + } + } + @Test fun exactly() { expect(listOf("A", "B", "A")).toContain.inAnyOrder.exactly(2).entry { @@ -16,13 +54,13 @@ class IterableLikeToContainCheckerSamples { toBeGreaterThan(1) } - fails { - expect(listOf("A", "B", "A", "C")).toContain.inAnyOrder.exactly(2).entry { + fails { // because "B" is more than twice in the List + expect(listOf("A", "B", "B", "B")).toContain.inAnyOrder.exactly(2).entry { toEqual("B") } } - fails { + fails { // because only 1 element is less than or equal to 1 expect(listOf(1, 2, 3)).toContain.inAnyOrder.exactly(2).entry { toBeLessThanOrEqualTo(1) } @@ -47,67 +85,39 @@ class IterableLikeToContainCheckerSamples { } } - fails { // because there are 3 items greater than 1 + fails { // because there are 3 elements greater than 1 expect(listOf(1, 2, 3, 3)).toContain.inAnyOrder.notOrAtMost(2).entry { toBeGreaterThan(1) } } - } @Test fun atMost() { - expect(listOf("A,A,B,C,A,B,B")).toContain.inAnyOrder.atMost(2).entry{ - toEqual("C") + expect(listOf("A", "B", "B", "A", "B")).toContain.inAnyOrder.atMost(2).entry { + toEqual("A") } - expect(listOf(1,2,3,2,3,3)).toContain.inAnyOrder.atMost(2).entry{ + expect(listOf(1, 2, 3)).toContain.inAnyOrder.atMost(2).entry { toBeLessThanOrEqualTo(2) } - fails { - expect(listOf("A,A,B,B,C,C")).toContain.inAnyOrder.atMost(1).entry{ - toEqual("A") + fails { // because "B" is 3 times in the List + expect(listOf("A", "B", "B", "A", "B")).toContain.inAnyOrder.atMost(2).entry { + toEqual("B") } } - fails { - expect(listOf(1,2,3,2,3,3)).toContain.inAnyOrder.atMost(2).entry{ + fails { // because there are 3 elements which are greater than 2 + expect(listOf(1, 2, 3, 2, 4, 3)).toContain.inAnyOrder.atMost(2).entry { toBeGreaterThan(2) } } - } - - @Test - fun butAtMost() { - expect(listOf("A,B,C,A,B,B")).toContain.inAnyOrder.atLeast(2).butAtMost(2).entry{ - toEqual("A") - } - - expect(listOf(1,2,3,4,5,6,4,5,5,7,7,7,7)).toContain.inAnyOrder.atLeast(3).butAtMost(4).entry{ - toEqual(5) - } - fails { - expect(listOf("A,B,B,B,B,B,C,C")).toContain.inAnyOrder.atLeast(3).butAtMost(4).entry{ - toEqual("A") - } - } - } - - @Test - fun atLeast() { - expect(listOf("A,B,C,A,B,B")).toContain.inAnyOrder.atLeast(3).entry{ - toEqual("B") - } - - expect(listOf(1,2,3,4,5,6,4)).toContain.inAnyOrder.atLeast(2).entry{ - toEqual(4) - } - - fails { - expect(listOf("A,B,C")).toContain.inAnyOrder.atLeast(2).entry{ - toEqual("A") + fails { // because atMost always implicitly also means atLeast(1) and "C" is not in the List + // use notOrAtMost if you want such a behaviour + expect(listOf("A", "B")).toContain.inAnyOrder.atMost(2).entry { + toEqual("C") } } }