Skip to content

Commit 4f11339

Browse files
authored
Merge pull request #1917 from ragul-engg/1910-add-infix-iterable-samples
[Infix] Add samples for iterableLikeToContainInAnyOrderCreators
2 parents 3109ca3 + 7338b40 commit 4f11339

File tree

2 files changed

+176
-1
lines changed

2 files changed

+176
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import ch.tutteli.atrium.logic.utils.toVarArg
2424
*
2525
* @return an [Expect] for the subject of `this` expectation.
2626
*
27+
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.IterableLikeToContainInAnyOrderCreatorSamples.value
28+
*
2729
* @since 0.14.0 -- API existed for [Iterable] but not for [IterableLike].
2830
*/
2931
infix fun <E, T : IterableLike> CheckerStep<E, T, InAnyOrderSearchBehaviour>.value(expected: E): Expect<T> =
@@ -49,6 +51,8 @@ infix fun <E, T : IterableLike> CheckerStep<E, T, InAnyOrderSearchBehaviour>.val
4951
*
5052
* @return an [Expect] for the subject of `this` expectation.
5153
*
54+
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.IterableLikeToContainInAnyOrderCreatorSamples.values
55+
*
5256
* @since 0.14.0 -- API existed for [Iterable] but not for [IterableLike].
5357
*/
5458
infix fun <E, T : IterableLike> CheckerStep<E, T, InAnyOrderSearchBehaviour>.the(values: Values<E>): Expect<T> =
@@ -67,6 +71,8 @@ infix fun <E, T : IterableLike> CheckerStep<E, T, InAnyOrderSearchBehaviour>.the
6771
*
6872
* @return an [Expect] for the subject of `this` expectation.
6973
*
74+
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.IterableLikeToContainInAnyOrderCreatorSamples.entry
75+
*
7076
* @since 0.14.0 -- API existed for [Iterable] but not for [IterableLike].
7177
*/
7278
infix fun <E : Any, T : IterableLike> CheckerStep<out E?, T, InAnyOrderSearchBehaviour>.entry(
@@ -86,6 +92,8 @@ infix fun <E : Any, T : IterableLike> CheckerStep<out E?, T, InAnyOrderSearchBeh
8692
*
8793
* @return an [Expect] for the subject of `this` expectation.
8894
*
95+
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.IterableLikeToContainInAnyOrderCreatorSamples.entries
96+
*
8997
* @since 0.14.0 -- API existed for [Iterable] but not for [IterableLike].
9098
*/
9199
infix fun <E : Any, T : IterableLike> CheckerStep<out E?, T, InAnyOrderSearchBehaviour>.the(
@@ -112,7 +120,7 @@ infix fun <E : Any, T : IterableLike> CheckerStep<out E?, T, InAnyOrderSearchBeh
112120
*
113121
* @since 0.13.0
114122
*
115-
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.IterableLikeToContainInAnyOrderCreatorSamples.elementsOf
123+
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.IterableLikeToContainInAnyOrderCreatorSamples.elementsOf
116124
*/
117125
inline infix fun <reified E, T : IterableLike> CheckerStep<E, T, InAnyOrderSearchBehaviour>.elementsOf(
118126
expectedIterableLike: IterableLike
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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.elementsOf
6+
import ch.tutteli.atrium.api.infix.en_GB.entries
7+
import ch.tutteli.atrium.api.infix.en_GB.entry
8+
import ch.tutteli.atrium.api.infix.en_GB.exactly
9+
import ch.tutteli.atrium.api.infix.en_GB.inAny
10+
import ch.tutteli.atrium.api.infix.en_GB.it
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.the
14+
import ch.tutteli.atrium.api.infix.en_GB.toContain
15+
import ch.tutteli.atrium.api.infix.en_GB.toEqual
16+
import ch.tutteli.atrium.api.infix.en_GB.value
17+
import ch.tutteli.atrium.api.infix.en_GB.values
18+
import ch.tutteli.atrium.api.verbs.expect
19+
import kotlin.test.Test
20+
21+
class IterableLikeToContainInAnyOrderCreatorSamples {
22+
@Test
23+
fun value() {
24+
expect(listOf("A", "B")) toContain o inAny order exactly 1 value "A"
25+
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 value ("A")
26+
expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 value "B"
27+
28+
fails {
29+
expect(listOf("A", "B")) toContain o inAny order exactly 2 value "A"
30+
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 value "A"
31+
expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 value "B"
32+
}
33+
}
34+
35+
@Test
36+
fun values() {
37+
expect(listOf("A", "B")) toContain o inAny order exactly 1 the values("B", "A")
38+
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 the values("B", "A")
39+
expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 the values("B", "A")
40+
41+
fails {
42+
expect(listOf("A", "B")) toContain o inAny order exactly 2 the values("B", "A")
43+
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 the values("B", "A")
44+
expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 the values("B", "A")
45+
}
46+
}
47+
48+
@Test
49+
fun entry() {
50+
expect(listOf("A", "B")) toContain o inAny order exactly 1 entry {
51+
it toEqual "A"
52+
}
53+
54+
expect(listOf("A", null, null)) toContain o inAny order exactly 2 entry null // null is identified
55+
56+
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 entry {
57+
it toEqual "A"
58+
}
59+
60+
expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 entry {
61+
it toEqual "A"
62+
}
63+
64+
fails { // because the count of "A" is not 2
65+
expect(listOf("A", "B")) toContain o inAny order exactly 2 entry {
66+
it toEqual "A"
67+
}
68+
}
69+
70+
fails { // because all elements are not null
71+
expect(listOf("A", "B", "C")) toContain o inAny order exactly 1 entry null
72+
}
73+
74+
fails { // because assertionCreatorOrNull is non-null and has no expectation
75+
expect(listOf("A", "B", "A", "B")) toContain o inAny order exactly 1 entry {
76+
/* do nothing */
77+
}
78+
}
79+
80+
fails { // because the count of "A" is less than 3
81+
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 entry {
82+
it toEqual "A"
83+
}
84+
}
85+
86+
fails { // because the count of "B" is more than 2
87+
expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 entry {
88+
it toEqual "B"
89+
}
90+
}
91+
}
92+
93+
@Test
94+
fun entries() {
95+
expect(listOf("A", "B")) toContain o inAny order exactly 1 the entries(
96+
{ it toEqual "B" },
97+
{ it toEqual "A" }
98+
)
99+
100+
expect(listOf("A", null, "A", null)) toContain o inAny order exactly 2 the entries(
101+
null,
102+
{ it toEqual "A" }
103+
)
104+
105+
expect(listOf(null, null)) toContain o inAny order exactly 2 the entries(
106+
null
107+
)
108+
109+
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 the entries(
110+
{ it toEqual "B" },
111+
{ it toEqual "A" }
112+
)
113+
114+
expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 the entries(
115+
{ it toEqual "B" },
116+
{ it toEqual "A" }
117+
)
118+
119+
fails { // because the count of "A" is not 2
120+
expect(listOf("A", "B", "B")) toContain o inAny order exactly 2 the entries(
121+
{ it toEqual "A" },
122+
{ it toEqual "B" }
123+
)
124+
}
125+
126+
fails { // because all elements are not null
127+
expect(listOf("A", "B", "C")) toContain o inAny order exactly 1 the entries(
128+
{ it toEqual "A" },
129+
null
130+
)
131+
}
132+
133+
fails { // because otherAssertionCreatorsOrNulls contains a lambda which is non-null and has no expectation
134+
expect(listOf("A", "B")) toContain o inAny order exactly 1 the entries(
135+
{ it toEqual "A" },
136+
{ /* do nothing */ }
137+
)
138+
}
139+
140+
fails { // because the count of "A" is less than 2
141+
expect(listOf("A", "B", "B")) toContain o inAny order atLeast 2 the entries(
142+
{ it toEqual "B" },
143+
{ it toEqual "A" }
144+
)
145+
}
146+
147+
fails { // because the count of "B" is more than 2
148+
expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 the entries(
149+
{ it toEqual "B" },
150+
{ it toEqual "A" }
151+
)
152+
}
153+
}
154+
155+
@Test
156+
fun elementsOf() {
157+
expect(listOf("A", "B")) toContain o inAny order exactly 1 elementsOf listOf("A", "B")
158+
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 elementsOf listOf("A", "B")
159+
expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 elementsOf listOf("A", "B")
160+
161+
fails {
162+
expect(listOf("A", "B")) toContain o inAny order exactly 2 elementsOf listOf("A", "B")
163+
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 elementsOf listOf("A", "B")
164+
expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 elementsOf listOf("A", "B")
165+
}
166+
}
167+
}

0 commit comments

Comments
 (0)