Skip to content

Commit

Permalink
Merge pull request #718 from robstoll/IterableLike.contains-element
Browse files Browse the repository at this point in the history
reword entry to element in IterableLike.contains
  • Loading branch information
robstoll authored Dec 16, 2020
2 parents 9878e69 + 3058ac3 commit 0834761
Show file tree
Hide file tree
Showing 33 changed files with 306 additions and 291 deletions.
72 changes: 36 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ expect(listOf(1, 2, 2, 4)).contains(2, 3)
```text
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
◆ contains, in any order:
⚬ an entry which is: 3 (kotlin.Int <1234789>)
⚬ an element which equals: 3 (kotlin.Int <1234789>)
⚬ ▶ number of such entries: 0
◾ is at least: 1
```
Expand Down Expand Up @@ -966,11 +966,11 @@ expect(listOf(1, 2, 2, 4)).contains(
```text
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
◆ contains, in any order:
⚬ an entry which:
⚬ an element which:
» is less than: 0 (kotlin.Int <1234789>)
⚬ ▶ number of such entries: 0
◾ is at least: 1
⚬ an entry which:
⚬ an element which:
» is greater than: 2 (kotlin.Int <1234789>)
» is less than: 4 (kotlin.Int <1234789>)
⚬ ▶ number of such entries: 0
Expand Down Expand Up @@ -1005,7 +1005,7 @@ expect(listOf(1, 2, 3, 4)).any { isLessThan(0) }
```text
expected that subject: [1, 2, 3, 4] (java.util.Arrays.ArrayList <1234789>)
◆ contains, in any order:
⚬ an entry which:
⚬ an element which:
» is less than: 0 (kotlin.Int <1234789>)
⚬ ▶ number of such entries: 0
◾ is at least: 1
Expand All @@ -1021,7 +1021,7 @@ expect(listOf(1, 2, 3, 4)).none { isGreaterThan(2) }
```text
expected that subject: [1, 2, 3, 4] (java.util.Arrays.ArrayList <1234789>)
◆ does not contain:
⚬ an entry which:
⚬ an element which:
» is greater than: 2 (kotlin.Int <1234789>)
✘ ▶ number of such entries: 2
◾ is: 0 (kotlin.Int <1234789>)
Expand Down Expand Up @@ -1068,17 +1068,17 @@ expect(listOf(1, 2, 2, 4)).contains.inOrder.only.entries({ isLessThan(3) }, { is
```text
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
◆ contains only, in order:
✔ ▶ entry 0: 1 (kotlin.Int <1234789>)
◾ an entry which:
✔ ▶ element 0: 1 (kotlin.Int <1234789>)
◾ an element which:
» is less than: 3 (kotlin.Int <1234789>)
✘ ▶ entry 1: 2 (kotlin.Int <1234789>)
◾ an entry which:
✘ ▶ element 1: 2 (kotlin.Int <1234789>)
◾ an element which:
» is less than: 2 (kotlin.Int <1234789>)
✘ ▶ size: 4 (kotlin.Int <1234789>)
◾ equals: 2 (kotlin.Int <1234789>)
❗❗ additional entries detected:
entry 2: 2 (kotlin.Int <1234789>)
entry 3: 4 (kotlin.Int <1234789>)
❗❗ additional elements detected:
element 2: 2 (kotlin.Int <1234789>)
element 3: 4 (kotlin.Int <1234789>)
```
</ex-collection-builder-1>

Expand Down Expand Up @@ -1118,15 +1118,15 @@ expect(listOf(1, 2, 2, 4)).contains.inOrder.only.values(1, 2, 2, 3, 4)
```text
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
◆ contains only, in order:
✔ ▶ entry 0: 1 (kotlin.Int <1234789>)
✔ ▶ element 0: 1 (kotlin.Int <1234789>)
◾ equals: 1 (kotlin.Int <1234789>)
✔ ▶ entry 1: 2 (kotlin.Int <1234789>)
✔ ▶ element 1: 2 (kotlin.Int <1234789>)
◾ equals: 2 (kotlin.Int <1234789>)
✔ ▶ entry 2: 2 (kotlin.Int <1234789>)
✔ ▶ element 2: 2 (kotlin.Int <1234789>)
◾ equals: 2 (kotlin.Int <1234789>)
✘ ▶ entry 3: 4 (kotlin.Int <1234789>)
✘ ▶ element 3: 4 (kotlin.Int <1234789>)
◾ equals: 3 (kotlin.Int <1234789>)
✘ ▶ entry 4: ❗❗ hasNext() returned false
✘ ▶ element 4: ❗❗ hasNext() returned false
◾ equals: 4 (kotlin.Int <1234789>)
✘ ▶ size: 4 (kotlin.Int <1234789>)
◾ equals: 5 (kotlin.Int <1234789>)
Expand All @@ -1142,7 +1142,7 @@ expect(listOf(1, 2, 2, 4)).contains.inAnyOrder.atLeast(1).butAtMost(2).entries({
```text
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
◆ contains, in any order:
⚬ an entry which:
⚬ an element which:
» is less than: 3 (kotlin.Int <1234789>)
⚬ ▶ number of such entries: 3
◾ is at most: 2
Expand All @@ -1158,10 +1158,10 @@ expect(listOf(1, 2, 2, 4)).contains.inAnyOrder.only.values(1, 2, 3, 4)
```text
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
◆ contains only, in any order:
✔ an entry which is: 1 (kotlin.Int <1234789>)
✔ an entry which is: 2 (kotlin.Int <1234789>)
✘ an entry which is: 3 (kotlin.Int <1234789>)
✔ an entry which is: 4 (kotlin.Int <1234789>)
✔ an element which equals: 1 (kotlin.Int <1234789>)
✔ an element which equals: 2 (kotlin.Int <1234789>)
✘ an element which equals: 3 (kotlin.Int <1234789>)
✔ an element which equals: 4 (kotlin.Int <1234789>)
✔ ▶ size: 4
◾ equals: 4
❗❗ following entries were mismatched:
Expand All @@ -1178,11 +1178,11 @@ expect(listOf(1, 2, 2, 4)).contains.inAnyOrder.only.values(4, 3, 2, 2, 1)
```text
expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>)
◆ contains only, in any order:
✔ an entry which is: 4 (kotlin.Int <1234789>)
✘ an entry which is: 3 (kotlin.Int <1234789>)
✔ an entry which is: 2 (kotlin.Int <1234789>)
✔ an entry which is: 2 (kotlin.Int <1234789>)
✔ an entry which is: 1 (kotlin.Int <1234789>)
✔ an element which equals: 4 (kotlin.Int <1234789>)
✘ an element which equals: 3 (kotlin.Int <1234789>)
✔ an element which equals: 2 (kotlin.Int <1234789>)
✔ an element which equals: 2 (kotlin.Int <1234789>)
✔ an element which equals: 1 (kotlin.Int <1234789>)
✘ ▶ size: 4
◾ equals: 5
```
Expand Down Expand Up @@ -1282,7 +1282,7 @@ expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>)
⚬ index 1: "b" <1234789>
◆ ▶ values: [1, 2] (java.util.LinkedHashMap.LinkedValues <1234789>)
◾ does not contain:
⚬ an entry which:
⚬ an element which:
» is greater than: 1 (kotlin.Int <1234789>)
✘ ▶ number of such entries: 1
◾ is: 0 (kotlin.Int <1234789>)
Expand Down Expand Up @@ -1312,14 +1312,14 @@ expect(linkedMapOf("a" to 1, "b" to 2)).asEntries().contains.inOrder.only.entrie
```text
expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>)
◆ contains only, in order:
✔ ▶ entry 0: a=1 (java.util.LinkedHashMap.Entry <1234789>)
◾ an entry which:
✔ ▶ element 0: a=1 (java.util.LinkedHashMap.Entry <1234789>)
◾ an element which:
» ▶ key: "a" <1234789>
◾ equals: "a" <1234789>
» ▶ value: 1 (kotlin.Int <1234789>)
◾ equals: 1 (kotlin.Int <1234789>)
✘ ▶ entry 1: b=2 (java.util.LinkedHashMap.Entry <1234789>)
◾ an entry which:
✘ ▶ element 1: b=2 (java.util.LinkedHashMap.Entry <1234789>)
◾ an element which:
» ▶ key: "a" <1234789>
◾ starts with: "a" <1234789>
» ▶ value: 1 (kotlin.Int <1234789>)
Expand Down Expand Up @@ -1593,14 +1593,14 @@ also states which entries were additionally contained in the list:
```text
expected that subject: [1, 2, 3] (java.util.Arrays.ArrayList <1234789>)
◆ contains only, in order:
✔ ▶ entry 0: 1 (kotlin.Int <1234789>)
✔ ▶ element 0: 1 (kotlin.Int <1234789>)
◾ equals: 1 (kotlin.Int <1234789>)
✘ ▶ entry 1: 2 (kotlin.Int <1234789>)
✘ ▶ element 1: 2 (kotlin.Int <1234789>)
◾ equals: 3 (kotlin.Int <1234789>)
✘ ▶ size: 3 (kotlin.Int <1234789>)
◾ equals: 2 (kotlin.Int <1234789>)
❗❗ additional entries detected:
entry 2: 3 (kotlin.Int <1234789>)
❗❗ additional elements detected:
element 2: 3 (kotlin.Int <1234789>)
```
</exs-add-info-1-output>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ch.tutteli.atrium.logic.impl.createExplanatoryAssertionGroup
import ch.tutteli.atrium.logic.impl.createHasElementAssertion
import ch.tutteli.atrium.reporting.translating.Translatable
import ch.tutteli.atrium.translations.DescriptionIterableAssertion
import ch.tutteli.atrium.translations.DescriptionIterableAssertion.AN_ENTRY_WHICH
import ch.tutteli.atrium.translations.DescriptionIterableAssertion.AN_ELEMENT_WHICH

/**
* Represents a creator of a sophisticated `contains` assertions for [Iterable] where an expected entry can appear
Expand All @@ -43,7 +43,10 @@ class InAnyOrderEntriesAssertionCreator<E : Any, T : IterableLike>(
private val converter: (T) -> Iterable<E?>,
searchBehaviour: InAnyOrderSearchBehaviour,
checkers: List<IterableLikeContains.Checker>
) : ContainsAssertionCreator<T, List<E?>, (Expect<E>.() -> Unit)?, IterableLikeContains.Checker>(searchBehaviour, checkers),
) : ContainsAssertionCreator<T, List<E?>, (Expect<E>.() -> Unit)?, IterableLikeContains.Checker>(
searchBehaviour,
checkers
),
IterableLikeContains.Creator<T, (Expect<E>.() -> Unit)?> {

override val descriptionContains: Translatable = DescriptionIterableAssertion.CONTAINS
Expand Down Expand Up @@ -73,7 +76,7 @@ class InAnyOrderEntriesAssertionCreator<E : Any, T : IterableLike>(
}

return assertionBuilder.customType(groupType)
.withDescriptionAndEmptyRepresentation(AN_ENTRY_WHICH)
.withDescriptionAndEmptyRepresentation(AN_ELEMENT_WHICH)
.withAssertions(assertions)
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class InAnyOrderOnlyAssertionCreator<E, T : IterableLike, in SC>(
val featureAssertions = createSizeFeatureAssertion(searchCriteria, actualSize)
if (mismatches == 0 && list.isNotEmpty()) {
featureAssertions.add(LazyThreadUnsafeAssertionGroup {
createExplanatoryGroupForMismatchesEtc(list, WARNING_ADDITIONAL_ENTRIES)
createExplanatoryGroupForMismatchesEtc(list, WARNING_ADDITIONAL_ELEMENTS)
})
}
assertions.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ch.tutteli.atrium.assertions.builders.assertionBuilder
import ch.tutteli.atrium.logic.creating.iterable.contains.searchbehaviours.InAnyOrderOnlySearchBehaviour
import ch.tutteli.atrium.logic.creating.typeutils.IterableLike
import ch.tutteli.atrium.reporting.translating.Translatable
import ch.tutteli.atrium.translations.DescriptionIterableAssertion.AN_ENTRY_WHICH_IS
import ch.tutteli.atrium.translations.DescriptionIterableAssertion.AN_ELEMENT_WHICH_EQUALS

/**
* Represents a creator of a sophisticated `contains` assertions for [Iterable] where exactly the expected entries have
Expand All @@ -30,6 +30,6 @@ class InAnyOrderOnlyValuesAssertionCreator<E, T : IterableLike>(
list: MutableList<E?>
): Pair<Boolean, Assertion> {
val found: Boolean = list.remove(searchCriterion)
return found to assertionBuilder.createDescriptive(AN_ENTRY_WHICH_IS, searchCriterion) { found }
return found to assertionBuilder.createDescriptive(AN_ELEMENT_WHICH_EQUALS, searchCriterion) { found }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InAnyOrderValuesAssertionCreator<SC, T : IterableLike>(

override val descriptionContains: Translatable = DescriptionIterableAssertion.CONTAINS
override val descriptionNumberOfOccurrences: Translatable = DescriptionIterableAssertion.NUMBER_OF_OCCURRENCES
override val groupDescription: Translatable = DescriptionIterableAssertion.AN_ENTRY_WHICH_IS
override val groupDescription: Translatable = DescriptionIterableAssertion.AN_ELEMENT_WHICH_EQUALS

override fun getAssertionGroupType(): AssertionGroupType {
return if (searchBehaviour is NotSearchBehaviour) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ch.tutteli.atrium.logic.creating.iterable.contains.searchbehaviours.InOrd
import ch.tutteli.atrium.logic.creating.typeutils.IterableLike
import ch.tutteli.atrium.reporting.translating.Translatable
import ch.tutteli.atrium.translations.DescriptionIterableAssertion
import ch.tutteli.atrium.translations.DescriptionIterableAssertion.ELEMENT_WITH_INDEX

/**
* Represents the base class for `in order only` assertion creators and provides a corresponding template to fulfill
Expand All @@ -32,7 +33,7 @@ abstract class InOrderOnlyAssertionCreator<E, T : IterableLike, SC>(
override fun Expect<List<E>>.createAssertionsAndReturnIndex(searchCriteria: List<SC>): Int {
var index = 0
searchCriteria.forEachIndexed { currentIndex, searchCriterion ->
createSingleEntryAssertion(currentIndex, searchCriterion, DescriptionIterableAssertion.ENTRY_WITH_INDEX)
createSingleEntryAssertion(currentIndex, searchCriterion, ELEMENT_WITH_INDEX)
index = currentIndex
}
++index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ abstract class InOrderOnlyBaseAssertionCreator<E, T : IterableLike, SC>(
addAssertion(LazyThreadUnsafeAssertionGroup {
val additionalEntries = itr.mapRemainingWithCounter { counter, it ->
val description = TranslatableWithArgs(
DescriptionIterableAssertion.ENTRY_WITH_INDEX,
DescriptionIterableAssertion.ELEMENT_WITH_INDEX,
expectedSize + counter
)
assertionBuilder.descriptive
Expand All @@ -74,7 +74,7 @@ abstract class InOrderOnlyBaseAssertionCreator<E, T : IterableLike, SC>(
.withWarningType
.withAssertion(
assertionBuilder.list
.withDescriptionAndEmptyRepresentation(DescriptionIterableAssertion.WARNING_ADDITIONAL_ENTRIES)
.withDescriptionAndEmptyRepresentation(DescriptionIterableAssertion.WARNING_ADDITIONAL_ELEMENTS)
.withAssertions(additionalEntries)
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal fun createEntryAssertion(explanatoryGroup: AssertionGroup, found: Boole
return assertionBuilder.fixedClaimGroup
.withListType
.withClaim(found)
.withDescriptionAndEmptyRepresentation(DescriptionIterableAssertion.AN_ENTRY_WHICH)
.withDescriptionAndEmptyRepresentation(DescriptionIterableAssertion.AN_ELEMENT_WHICH)
.withAssertion(explanatoryGroup)
.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal fun createEntryAssertion(explanatoryGroup: AssertionGroup, found: Boole
return assertionBuilder.fixedClaimGroup
.withListType
.withClaim(found)
.withDescriptionAndEmptyRepresentation(AN_ENTRY_WHICH)
.withDescriptionAndEmptyRepresentation(AN_ELEMENT_WHICH)
.withAssertion(explanatoryGroup)
.build()
}
Expand Down Expand Up @@ -100,7 +100,7 @@ internal fun <E> createSizeFeatureAssertionForInOrderOnly(
if (iterableAsList.size > expectedSize) {
addAssertion(LazyThreadUnsafeAssertionGroup {
val additionalEntries = itr.mapRemainingWithCounter { counter, it ->
val description = TranslatableWithArgs(ENTRY_WITH_INDEX, expectedSize + counter)
val description = TranslatableWithArgs(ELEMENT_WITH_INDEX, expectedSize + counter)
assertionBuilder.descriptive
.holding
.withDescriptionAndRepresentation(description, it)
Expand All @@ -111,7 +111,7 @@ internal fun <E> createSizeFeatureAssertionForInOrderOnly(
.withWarningType
.withAssertion(
assertionBuilder.list
.withDescriptionAndEmptyRepresentation(WARNING_ADDITIONAL_ENTRIES)
.withDescriptionAndEmptyRepresentation(WARNING_ADDITIONAL_ELEMENTS)
.withAssertions(additionalEntries)
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ch.tutteli.atrium.domain.robstoll.lib.creating.iterable.contains.createEx
import ch.tutteli.atrium.domain.robstoll.lib.creating.iterable.contains.createHasElementAssertion
import ch.tutteli.atrium.reporting.translating.Translatable
import ch.tutteli.atrium.translations.DescriptionIterableAssertion
import ch.tutteli.atrium.translations.DescriptionIterableAssertion.AN_ENTRY_WHICH
import ch.tutteli.atrium.translations.DescriptionIterableAssertion.AN_ELEMENT_WHICH

/**
* Represents a creator of a sophisticated `contains` assertions for [Iterable] where an expected entry can appear
Expand Down Expand Up @@ -72,7 +72,7 @@ class InAnyOrderEntriesAssertionCreator<E : Any, in T : Iterable<E?>>(
}

return assertionBuilder.customType(groupType)
.withDescriptionAndEmptyRepresentation(AN_ENTRY_WHICH)
.withDescriptionAndEmptyRepresentation(AN_ELEMENT_WHICH)
.withAssertions(assertions)
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ch.tutteli.atrium.domain.robstoll.lib.creating.iterable.contains.collectI
import ch.tutteli.atrium.domain.robstoll.lib.creating.iterable.contains.createHasElementAssertion
import ch.tutteli.atrium.reporting.translating.Translatable
import ch.tutteli.atrium.translations.DescriptionIterableAssertion
import ch.tutteli.atrium.translations.DescriptionIterableAssertion.AN_ENTRY_WHICH
import ch.tutteli.atrium.translations.DescriptionIterableAssertion.AN_ELEMENT_WHICH

/**
* Represents a creator of a sophisticated `contains` assertions for [Iterable] where an expected entry can appear
Expand Down Expand Up @@ -80,7 +80,7 @@ class InAnyOrderEntriesDeprecatedAssertionCreator<E : Any, in T : Iterable<E?>>(
}

return AssertImpl.builder.customType(groupType)
.withDescriptionAndEmptyRepresentation(AN_ENTRY_WHICH)
.withDescriptionAndEmptyRepresentation(AN_ELEMENT_WHICH)
.withAssertions(assertions)
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class InAnyOrderOnlyAssertionCreator<E, in T : Iterable<E?>, in SC>(
val featureAssertions = createSizeFeatureAssertion(searchCriteria, actualSize)
if (mismatches == 0 && list.isNotEmpty()) {
featureAssertions.add(LazyThreadUnsafeAssertionGroup {
createExplanatoryGroupForMismatchesEtc(list, WARNING_ADDITIONAL_ENTRIES)
createExplanatoryGroupForMismatchesEtc(list, WARNING_ADDITIONAL_ELEMENTS)
})
}
assertions.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ch.tutteli.atrium.assertions.AssertionGroup
import ch.tutteli.atrium.assertions.builders.assertionBuilder
import ch.tutteli.atrium.domain.creating.iterable.contains.searchbehaviours.InAnyOrderOnlySearchBehaviour
import ch.tutteli.atrium.reporting.translating.Translatable
import ch.tutteli.atrium.translations.DescriptionIterableAssertion.AN_ENTRY_WHICH_IS
import ch.tutteli.atrium.translations.DescriptionIterableAssertion.AN_ELEMENT_WHICH_EQUALS

/**
* Represents a creator of a sophisticated `contains` assertions for [Iterable] where exactly the expected entries have
Expand All @@ -28,6 +28,6 @@ class InAnyOrderOnlyValuesAssertionCreator<E, in T : Iterable<E?>>(
list: MutableList<E?>
): Pair<Boolean, Assertion> {
val found: Boolean = list.remove(searchCriterion)
return found to assertionBuilder.createDescriptive(AN_ENTRY_WHICH_IS, searchCriterion) { found }
return found to assertionBuilder.createDescriptive(AN_ELEMENT_WHICH_EQUALS, searchCriterion) { found }
}
}
Loading

0 comments on commit 0834761

Please sign in to comment.