Skip to content

Commit 07c9023

Browse files
authored
Merge pull request #1916 from ragul-engg/1909-add-infix-iterable-samples
[Infix] Add samples for iterableLikeToContainCheckers
2 parents 6dd566b + 9ce5abb commit 07c9023

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

apis/infix/atrium-api-infix/src/commonMain/kotlin/ch/tutteli/atrium/api/infix/en_GB/iterableLikeToContainCheckers.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import ch.tutteli.atrium.logic.creating.iterable.contains.steps.*
1818
* @throws IllegalArgumentException In case [times] is smaller than zero.
1919
* @throws IllegalArgumentException In case [times] is zero; use [notToContain] instead.
2020
*
21+
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.IterableLikeToContainCheckerSamples.atLeast
22+
*
2123
* @since 0.14.0 -- API existed for [Iterable] but not for [IterableLike].
2224
*/
2325
infix fun <E, T : IterableLike, S : InAnyOrderSearchBehaviour> IterableLikeContains.EntryPointStep<E, T, S>.atLeast(
@@ -40,6 +42,8 @@ infix fun <E, T : IterableLike, S : InAnyOrderSearchBehaviour> IterableLikeConta
4042
* @throws IllegalArgumentException In case [times] of this `at most` restriction equals to the number of the
4143
* `at least` restriction; use the [exactly] restriction instead.
4244
*
45+
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.IterableLikeToContainCheckerSamples.butAtMost
46+
*
4347
* @since 0.14.0 -- API existed for [Iterable] but not for [IterableLike].
4448
*/
4549
infix fun <E, T : IterableLike, S : InAnyOrderSearchBehaviour> AtLeastCheckerStep<E, T, S>.butAtMost(
@@ -65,6 +69,8 @@ infix fun <E, T : IterableLike, S : InAnyOrderSearchBehaviour> AtLeastCheckerSte
6569
* @throws IllegalArgumentException In case [times] is smaller than zero.
6670
* @throws IllegalArgumentException In case [times] is zero; use [notToContain] instead.
6771
*
72+
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.IterableLikeToContainCheckerSamples.exactly
73+
*
6874
* @since 0.14.0 -- API existed for [Iterable] but not for [IterableLike].
6975
*/
7076
infix fun <E, T : IterableLike, S : InAnyOrderSearchBehaviour> IterableLikeContains.EntryPointStep<E, T, S>.exactly(
@@ -88,6 +94,8 @@ infix fun <E, T : IterableLike, S : InAnyOrderSearchBehaviour> IterableLikeConta
8894
* @throws IllegalArgumentException In case [times] is zero; use [notToContain] instead.
8995
* @throws IllegalArgumentException In case [times] equals to one; use [exactly] instead.
9096
*
97+
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.IterableLikeToContainCheckerSamples.atMost
98+
*
9199
* @since 0.14.0 -- API existed for [Iterable] but not for [IterableLike].
92100
*/
93101
infix fun <E, T : IterableLike, S : InAnyOrderSearchBehaviour> IterableLikeContains.EntryPointStep<E, T, S>.atMost(
@@ -111,6 +119,8 @@ infix fun <E, T : IterableLike, S : InAnyOrderSearchBehaviour> IterableLikeConta
111119
* @throws IllegalArgumentException In case [times] is smaller than zero.
112120
* @throws IllegalArgumentException In case [times] is zero; use [notToContain] instead.
113121
*
122+
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.IterableLikeToContainCheckerSamples.notOrAtMost
123+
*
114124
* @since 0.14.0 -- API existed for [Iterable] but not for [IterableLike].
115125
*/
116126
infix fun <E, T : IterableLike, S : InAnyOrderSearchBehaviour> IterableLikeContains.EntryPointStep<E, T, S>.notOrAtMost(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package ch.tutteli.atrium.api.infix.en_GB.samples
2+
3+
import ch.tutteli.atrium.api.infix.en_GB.atLeast
4+
import ch.tutteli.atrium.api.infix.en_GB.atMost
5+
import ch.tutteli.atrium.api.infix.en_GB.butAtMost
6+
import ch.tutteli.atrium.api.infix.en_GB.entry
7+
import ch.tutteli.atrium.api.infix.en_GB.exactly
8+
import ch.tutteli.atrium.api.infix.en_GB.inAny
9+
import ch.tutteli.atrium.api.infix.en_GB.it
10+
import ch.tutteli.atrium.api.infix.en_GB.notOrAtMost
11+
import ch.tutteli.atrium.api.infix.en_GB.o
12+
import ch.tutteli.atrium.api.infix.en_GB.order
13+
import ch.tutteli.atrium.api.infix.en_GB.toBeGreaterThan
14+
import ch.tutteli.atrium.api.infix.en_GB.toBeLessThanOrEqualTo
15+
import ch.tutteli.atrium.api.infix.en_GB.toContain
16+
import ch.tutteli.atrium.api.infix.en_GB.toEqual
17+
import ch.tutteli.atrium.api.verbs.expect
18+
import kotlin.test.Test
19+
20+
class IterableLikeToContainCheckerSamples {
21+
22+
@Test
23+
fun atLeast() {
24+
expect(listOf("A", "B", "C", "A", "B", "B")) toContain o inAny order atLeast 3 entry {
25+
it toEqual "B"
26+
}
27+
28+
expect(listOf(1, 2, 3, 4, 5, 6, 4)) toContain o inAny order atLeast 2 entry {
29+
it toBeGreaterThan 4
30+
}
31+
32+
fails { // because "A" is only 1 in the List
33+
expect(listOf("A", "B", "C")) toContain o inAny order atLeast 2 entry {
34+
it toEqual "A"
35+
}
36+
}
37+
}
38+
39+
@Test
40+
fun butAtMost() {
41+
expect(listOf("A", "B", "C", "A", "B", "B")) toContain o inAny order atLeast 1 butAtMost 2 entry {
42+
it toEqual "A"
43+
}
44+
45+
fails { // because "B" is three times in the List
46+
expect(listOf("A", "B", "C", "A", "B", "B")) toContain o inAny order atLeast 1 butAtMost 2 entry {
47+
it toEqual "B"
48+
}
49+
}
50+
51+
fails { // because "C" is not in the List
52+
expect(listOf("A", "B", "C", "A", "B", "B")) toContain o inAny order atLeast 1 butAtMost 2 entry {
53+
it toEqual "D"
54+
}
55+
}
56+
}
57+
58+
@Test
59+
fun exactly() {
60+
expect(listOf("A", "B", "A")) toContain o inAny order exactly 2 entry {
61+
it toEqual "A"
62+
}
63+
64+
expect(listOf(1, 2, 3)) toContain o inAny order exactly 2 entry {
65+
it toBeGreaterThan 1
66+
}
67+
68+
fails { // because "B" is more than twice in the List
69+
expect(listOf("A", "B", "B", "B")) toContain o inAny order exactly 2 entry {
70+
it toEqual "B"
71+
}
72+
}
73+
74+
fails { // because only 1 element is less than or equal to 1
75+
expect(listOf(1, 2, 3)) toContain o inAny order exactly 2 entry {
76+
it toBeLessThanOrEqualTo 1
77+
}
78+
}
79+
}
80+
81+
@Test
82+
fun notOrAtMost() {
83+
expect(listOf("A", "A", "B", "C")) toContain o inAny order notOrAtMost 2 entry {
84+
it toEqual "A"
85+
}
86+
87+
expect(listOf(1, 2, 3)) toContain o inAny order notOrAtMost 2 entry {
88+
// none fulfils the expectation which is fine because we use notOrAtMost
89+
// use atMost if you want that at least one element matches
90+
it toBeGreaterThan 4
91+
}
92+
93+
fails { // because "B" is 3 times in the List
94+
expect(listOf("A", "B", "B", "B")) toContain o inAny order notOrAtMost 2 entry {
95+
it toEqual "B"
96+
}
97+
}
98+
99+
fails { // because there are 3 elements greater than 1
100+
expect(listOf(1, 2, 3, 3)) toContain o inAny order notOrAtMost 2 entry {
101+
it toBeGreaterThan 1
102+
}
103+
}
104+
}
105+
106+
@Test
107+
fun atMost() {
108+
expect(listOf("A", "B", "B", "A", "B")) toContain o inAny order atMost 2 entry {
109+
it toEqual "A"
110+
}
111+
112+
expect(listOf(1, 2, 3)) toContain o inAny order atMost 2 entry {
113+
it toBeLessThanOrEqualTo 2
114+
}
115+
116+
fails { // because "B" is 3 times in the List
117+
expect(listOf("A", "B", "B", "A", "B")) toContain o inAny order atMost 2 entry {
118+
it toEqual "B"
119+
}
120+
}
121+
122+
fails { // because there are 3 elements which are greater than 2
123+
expect(listOf(1, 2, 3, 2, 4, 3)) toContain o inAny order atMost 2 entry {
124+
it toBeGreaterThan 2
125+
}
126+
}
127+
128+
fails { // because atMost always implicitly also means atLeast(1) and "C" is not in the List
129+
// use notOrAtMost if you want such a behaviour
130+
expect(listOf("A", "B")) toContain o inAny order atMost 2 entry {
131+
it toEqual "C"
132+
}
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)