|
| 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