Skip to content

Commit

Permalink
format samples and adjust in order only samples
Browse files Browse the repository at this point in the history
  • Loading branch information
robstoll committed Aug 14, 2024
1 parent 1910d70 commit 5b65f91
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class IterableFeatureExtractorSamples {
.toBeLessThan(4) // subject is still 3

fails {
expect(iterable).last.toBeGreaterThan(3).toBeLessThan (4) // subject is 3, fails on first expectation, second is skipped
expect(iterable).last.toBeGreaterThan(3)
.toBeLessThan(4) // subject is 3, fails on first expectation, second is skipped
}

fails {
Expand All @@ -125,8 +126,8 @@ class IterableFeatureExtractorSamples {

expect(iterable).last { // subject within this expectation-group is of type Int (actually 3)
toBeGreaterThan(3) // fails
toBeLessThan (4) // still evaluated, even though `toBeGreaterThan` already fails,
// use `.last.` if you want a fail fast behaviour
toBeLessThan(4) // still evaluated, even though `toBeGreaterThan` already fails,
// use `.last.` if you want a fail fast behaviour
} // subject here is back to type Iterable<Int>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class IterableLikeToContainCheckerSamples {
}
}

fails { // because there are 3 elements which are greater than 2
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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,41 @@ import kotlin.test.Test

class IterableLikeToContainInAnyOrderCreatorSamples {
@Test
fun value(){
expect(listOf("A","B")).toContain.inAnyOrder.exactly(1).value("A")
expect(listOf("A","B","A","B")).toContain.inAnyOrder.atLeast(2).value("A")
expect(listOf("A","B","B")).toContain.inAnyOrder.atMost(2).value("B")
fun value() {
expect(listOf("A", "B")).toContain.inAnyOrder.exactly(1).value("A")
expect(listOf("A", "B", "A", "B")).toContain.inAnyOrder.atLeast(2).value("A")
expect(listOf("A", "B", "B")).toContain.inAnyOrder.atMost(2).value("B")

fails {
expect(listOf("A","B")).toContain.inAnyOrder.exactly(2).value("A")
expect(listOf("A","B","A","B")).toContain.inAnyOrder.atLeast(3).value("A")
expect(listOf("A","B","B","B")).toContain.inAnyOrder.atMost(2).value("B")
expect(listOf("A", "B")).toContain.inAnyOrder.exactly(2).value("A")
expect(listOf("A", "B", "A", "B")).toContain.inAnyOrder.atLeast(3).value("A")
expect(listOf("A", "B", "B", "B")).toContain.inAnyOrder.atMost(2).value("B")
}
}

@Test
fun values(){
expect(listOf("A","B")).toContain.inAnyOrder.exactly(1).values("B", "A")
expect(listOf("A","B","A","B")).toContain.inAnyOrder.atLeast(2).values("B", "A")
expect(listOf("A","B","B")).toContain.inAnyOrder.atMost(2).values("B", "A")
fun values() {
expect(listOf("A", "B")).toContain.inAnyOrder.exactly(1).values("B", "A")
expect(listOf("A", "B", "A", "B")).toContain.inAnyOrder.atLeast(2).values("B", "A")
expect(listOf("A", "B", "B")).toContain.inAnyOrder.atMost(2).values("B", "A")

fails {
expect(listOf("A","B")).toContain.inAnyOrder.exactly(2).values("B", "A")
expect(listOf("A","B","A","B")).toContain.inAnyOrder.atLeast(3).values("B", "A")
expect(listOf("A","B","B","B")).toContain.inAnyOrder.atMost(2).values("B", "A")
expect(listOf("A", "B")).toContain.inAnyOrder.exactly(2).values("B", "A")
expect(listOf("A", "B", "A", "B")).toContain.inAnyOrder.atLeast(3).values("B", "A")
expect(listOf("A", "B", "B", "B")).toContain.inAnyOrder.atMost(2).values("B", "A")
}
}

@Test
fun elementsOf(){
expect(listOf("A","B")).toContain.inAnyOrder.exactly(1).elementsOf(listOf("A","B"))
expect(listOf("A","B","A","B")).toContain.inAnyOrder.atLeast(2).elementsOf(listOf("A","B"))
expect(listOf("A","B","B")).toContain.inAnyOrder.atMost(2).elementsOf(listOf("A","B"))
fun elementsOf() {
expect(listOf("A", "B")).toContain.inAnyOrder.exactly(1).elementsOf(listOf("A", "B"))
expect(listOf("A", "B", "A", "B")).toContain.inAnyOrder.atLeast(2).elementsOf(listOf("A", "B"))
expect(listOf("A", "B", "B")).toContain.inAnyOrder.atMost(2).elementsOf(listOf("A", "B"))

fails {
expect(listOf("A","B")).toContain.inAnyOrder.exactly(2).elementsOf(listOf("A","B"))
expect(listOf("A","B","A","B")).toContain.inAnyOrder.atLeast(3).elementsOf(listOf("A","B"))
expect(listOf("A","B","B","B")).toContain.inAnyOrder.atMost(2).elementsOf(listOf("A","B"))
expect(listOf("A", "B")).toContain.inAnyOrder.exactly(2).elementsOf(listOf("A", "B"))
expect(listOf("A", "B", "A", "B")).toContain.inAnyOrder.atLeast(3).elementsOf(listOf("A", "B"))
expect(listOf("A", "B", "B", "B")).toContain.inAnyOrder.atMost(2).elementsOf(listOf("A", "B"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,51 @@ import kotlin.test.Test

class IterableLikeToContainInAnyOrderOnlyCreatorSamples {
@Test
fun value(){
fun value() {
expect(listOf("A")).toContain.inAnyOrder.only.value("A")

fails { // because subject list does not contain expected value
expect(listOf("B")).toContain.inAnyOrder.only.value("A")
}

fails { // because subject list contains multiple elements
expect(listOf("A","A")).toContain.inAnyOrder.only.value("A")
expect(listOf("A", "A")).toContain.inAnyOrder.only.value("A")
}
}

@Test
fun values(){
expect(listOf("A","B","C")).toContain.inAnyOrder.only.values(
fun values() {
expect(listOf("A", "B", "C")).toContain.inAnyOrder.only.values(
"C", "B", "A"
)

fails { // because not all elements found
expect(listOf("A","B","C")).toContain.inAnyOrder.only.values(
"B","A"
expect(listOf("A", "B", "C")).toContain.inAnyOrder.only.values(
"B", "A"
)
}

fails { // because more elements expected than found
expect(listOf("A","B","C")).toContain.inAnyOrder.only.values(
"D","C","B","A"
expect(listOf("A", "B", "C")).toContain.inAnyOrder.only.values(
"D", "C", "B", "A"
)
}
}

@Test
fun elementsOf(){
expect(listOf("A","B","C")).toContain.inAnyOrder.only.elementsOf(
listOf("A","B","C")
fun elementsOf() {
expect(listOf("A", "B", "C")).toContain.inAnyOrder.only.elementsOf(
listOf("A", "B", "C")
)

fails { // because not all elements found
expect(listOf("A","B","C")).toContain.inAnyOrder.only.elementsOf(
expect(listOf("A", "B", "C")).toContain.inAnyOrder.only.elementsOf(
listOf("B", "A")
)
}

fails { // because more elements expected than found
expect(listOf("A","B","C")).toContain.inAnyOrder.only.elementsOf(
expect(listOf("A", "B", "C")).toContain.inAnyOrder.only.elementsOf(
listOf("B", "A", "C", "D")
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,70 @@ import kotlin.test.Test

class IterableLikeToContainInOrderOnlyCreatorSamples {
@Test
fun value(){
fun value() {
expect(listOf("A")).toContain.inOrder.only.value("A")

fails { // because subject list does not contain expected value
expect(listOf("B")).toContain.inOrder.only.value("A")
}

fails { // because subject list contains multiple elements
expect(listOf("A","A")).toContain.inOrder.only.value("A")
}

fails { // because the order is wrong
expect(listOf("B","A")).toContain.inOrder.only.value("A")
expect(listOf("A", "A")).toContain.inOrder.only.value("A")
}
}

@Test
fun values(){
expect(listOf("A","B","C")).toContain.inOrder.only.values(
"A","B","C"
fun values() {
expect(listOf("A", "B", "C")).toContain.inOrder.only.values(
"A", "B", "C"
)

fails { // although same elements but not in same order
expect(listOf("A","B","C")).toContain.inOrder.only.values(
"A","C","B"
expect(listOf("A", "B", "C")).toContain.inOrder.only.values(
"A", "C", "B"
)
}

fails { // because not all elements found
expect(listOf("A","B","C")).toContain.inOrder.only.values(
"A","B"
expect(listOf("A", "B", "C")).toContain.inOrder.only.values(
"A", "B"
)
}

fails { // because more elements expected than found
expect(listOf("A","B","C")).toContain.inOrder.only.values(
"A","B","C","D"
expect(listOf("A", "B", "C")).toContain.inOrder.only.values(
"A", "B", "C", "D"
)
}

fails { // because order is wrong
expect(listOf("A", "B")).toContain.inOrder.only.values(
"B", "A"
)
}
}

@Test
fun elementsOf(){
expect(listOf("A","B","C")).toContain.inOrder.only.elementsOf(
listOf("A","B","C")
fun elementsOf() {
expect(listOf("A", "B", "C")).toContain.inOrder.only.elementsOf(
listOf("A", "B", "C")
)

fails { // although same elements but not in same order
expect(listOf("A","B","C")).toContain.inOrder.only.elementsOf(
listOf("A","C","B")
expect(listOf("A", "B", "C")).toContain.inOrder.only.elementsOf(
listOf("A", "C", "B")
)
}

fails { // because not all elements found
expect(listOf("A","B","C")).toContain.inOrder.only.elementsOf(
listOf("A","B")
fails { // because not all elements found
expect(listOf("A", "B", "C")).toContain.inOrder.only.elementsOf(
listOf("A", "B")
)
}

fails { // because more elements expected than found
expect(listOf("A","B","C")).toContain.inOrder.only.elementsOf(
listOf("A","B","C","D")
expect(listOf("A", "B", "C")).toContain.inOrder.only.elementsOf(
listOf("A", "B", "C", "D")
)
}
}
Expand Down

0 comments on commit 5b65f91

Please sign in to comment.