-
-
Notifications
You must be signed in to change notification settings - Fork 231
[Infix] Add samples for iterableLikeToContainInAnyOrderCreators #1917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
robstoll
merged 2 commits into
robstoll:main
from
ragul-engg:1910-add-infix-iterable-samples
Mar 7, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
...h/tutteli/atrium/api/infix/en_GB/samples/IterableLikeToContainInAnyOrderCreatorSamples.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| package ch.tutteli.atrium.api.infix.en_GB.samples | ||
|
|
||
| import ch.tutteli.atrium.api.infix.en_GB.atLeast | ||
| import ch.tutteli.atrium.api.infix.en_GB.atMost | ||
| import ch.tutteli.atrium.api.infix.en_GB.elementsOf | ||
| import ch.tutteli.atrium.api.infix.en_GB.entries | ||
| import ch.tutteli.atrium.api.infix.en_GB.entry | ||
| import ch.tutteli.atrium.api.infix.en_GB.exactly | ||
| import ch.tutteli.atrium.api.infix.en_GB.inAny | ||
| import ch.tutteli.atrium.api.infix.en_GB.it | ||
| import ch.tutteli.atrium.api.infix.en_GB.o | ||
| import ch.tutteli.atrium.api.infix.en_GB.order | ||
| import ch.tutteli.atrium.api.infix.en_GB.the | ||
| import ch.tutteli.atrium.api.infix.en_GB.toContain | ||
| import ch.tutteli.atrium.api.infix.en_GB.toEqual | ||
| import ch.tutteli.atrium.api.infix.en_GB.value | ||
| import ch.tutteli.atrium.api.infix.en_GB.values | ||
| import ch.tutteli.atrium.api.verbs.expect | ||
| import kotlin.test.Test | ||
|
|
||
| class IterableLikeToContainInAnyOrderCreatorSamples { | ||
| @Test | ||
| fun value() { | ||
| expect(listOf("A", "B")) toContain o inAny order exactly 1 value "A" | ||
| expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 value ("A") | ||
| expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 value "B" | ||
|
|
||
| fails { | ||
| expect(listOf("A", "B")) toContain o inAny order exactly 2 value "A" | ||
| expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 value "A" | ||
| expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 value "B" | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun values() { | ||
| expect(listOf("A", "B")) toContain o inAny order exactly 1 the values("B", "A") | ||
| expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 the values("B", "A") | ||
| expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 the values("B", "A") | ||
|
|
||
| fails { | ||
| expect(listOf("A", "B")) toContain o inAny order exactly 2 the values("B", "A") | ||
| expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 the values("B", "A") | ||
| expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 the values("B", "A") | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun entry() { | ||
| expect(listOf("A", "B")) toContain o inAny order exactly 1 entry { | ||
| it toEqual "A" | ||
| } | ||
|
|
||
| expect(listOf("A", null, null)) toContain o inAny order exactly 2 entry null // null is identified | ||
|
|
||
| expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 entry { | ||
| it toEqual "A" | ||
| } | ||
|
|
||
| expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 entry { | ||
| it toEqual "A" | ||
| } | ||
|
|
||
| fails { // because the count of "A" is not 2 | ||
| expect(listOf("A", "B")) toContain o inAny order exactly 2 entry { | ||
| it toEqual "A" | ||
| } | ||
| } | ||
|
|
||
| fails { // because all elements are not null | ||
| expect(listOf("A", "B", "C")) toContain o inAny order exactly 1 entry null | ||
| } | ||
|
|
||
| fails { // because assertionCreatorOrNull is non-null and has no expectation | ||
| expect(listOf("A", "B", "A", "B")) toContain o inAny order exactly 1 entry { | ||
| /* do nothing */ | ||
| } | ||
| } | ||
|
|
||
| fails { // because the count of "A" is less than 3 | ||
| expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 entry { | ||
| it toEqual "A" | ||
| } | ||
| } | ||
|
|
||
| fails { // because the count of "B" is more than 2 | ||
| expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 entry { | ||
| it toEqual "B" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun entries() { | ||
| expect(listOf("A", "B")) toContain o inAny order exactly 1 the entries( | ||
| { it toEqual "B" }, | ||
| { it toEqual "A" } | ||
| ) | ||
|
|
||
| expect(listOf("A", null, "A", null)) toContain o inAny order exactly 2 the entries( | ||
| null, | ||
| { it toEqual "A" } | ||
| ) | ||
|
|
||
| expect(listOf(null, null)) toContain o inAny order exactly 2 the entries( | ||
| null | ||
| ) | ||
|
|
||
| expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 the entries( | ||
| { it toEqual "B" }, | ||
| { it toEqual "A" } | ||
| ) | ||
|
|
||
| expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 the entries( | ||
| { it toEqual "B" }, | ||
| { it toEqual "A" } | ||
| ) | ||
|
|
||
| fails { // because the count of "A" is not 2 | ||
| expect(listOf("A", "B", "B")) toContain o inAny order exactly 2 the entries( | ||
| { it toEqual "A" }, | ||
| { it toEqual "B" } | ||
| ) | ||
| } | ||
|
|
||
| fails { // because all elements are not null | ||
| expect(listOf("A", "B", "C")) toContain o inAny order exactly 1 the entries( | ||
| { it toEqual "A" }, | ||
| null | ||
| ) | ||
| } | ||
|
|
||
| fails { // because otherAssertionCreatorsOrNulls contains a lambda which is non-null and has no expectation | ||
| expect(listOf("A", "B")) toContain o inAny order exactly 1 the entries( | ||
| { it toEqual "A" }, | ||
| { /* do nothing */ } | ||
| ) | ||
| } | ||
|
|
||
| fails { // because the count of "A" is less than 2 | ||
| expect(listOf("A", "B", "B")) toContain o inAny order atLeast 2 the entries( | ||
| { it toEqual "B" }, | ||
| { it toEqual "A" } | ||
| ) | ||
| } | ||
|
|
||
| fails { // because the count of "B" is more than 2 | ||
| expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 the entries( | ||
| { it toEqual "B" }, | ||
| { it toEqual "A" } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun elementsOf() { | ||
| expect(listOf("A", "B")) toContain o inAny order exactly 1 elementsOf listOf("A", "B") | ||
| expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 elementsOf listOf("A", "B") | ||
| expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 elementsOf listOf("A", "B") | ||
|
|
||
| fails { | ||
| expect(listOf("A", "B")) toContain o inAny order exactly 2 elementsOf listOf("A", "B") | ||
| expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 elementsOf listOf("A", "B") | ||
| expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 elementsOf listOf("A", "B") | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.