|
| 1 | +package ch.tutteli.atrium.api.fluent.en_GB |
| 2 | + |
| 3 | +import ch.tutteli.atrium.api.verbs.expect |
| 4 | +import ch.tutteli.atrium.creating.Expect |
| 5 | +import ch.tutteli.atrium.logic.creating.iterablelike.contains.reporting.InAnyOrderOnlyReportingOptions |
| 6 | +import ch.tutteli.atrium.specs.integration.AbstractIterableToContainInAnyOrderOnlyValuesExpectationsTest |
| 7 | +import ch.tutteli.atrium.specs.integration.IterableToContainSpecBase.Companion.emptyInOrderOnlyReportOptions |
| 8 | +import ch.tutteli.atrium.specs.withNullableSuffix |
| 9 | +import kotlin.test.Test |
| 10 | + |
| 11 | +class IterableToContainInAnyOrderOnlyValuesExpectationsTest : |
| 12 | + AbstractIterableToContainInAnyOrderOnlyValuesExpectationsTest( |
| 13 | + functionDescription to Companion::toContainInAnyOrderOnlyValues, |
| 14 | + (functionDescription to Companion::toContainInAnyOrderOnlyNullableValues).withNullableSuffix() |
| 15 | + ) { |
| 16 | + companion object : IterableToContainSpecBase() { |
| 17 | + val functionDescription = "$toContain.$inAnyOrder.$only.$value/$values" |
| 18 | + |
| 19 | + private fun toContainInAnyOrderOnlyValues( |
| 20 | + expect: Expect<Iterable<Double>>, |
| 21 | + a: Double, |
| 22 | + aX: Array<out Double>, |
| 23 | + report: InAnyOrderOnlyReportingOptions.() -> Unit |
| 24 | + ): Expect<Iterable<Double>> = |
| 25 | + if (report === emptyInOrderOnlyReportOptions) { |
| 26 | + if (aX.isEmpty()) expect.toContain.inAnyOrder.only.value(a) |
| 27 | + else expect.toContain.inAnyOrder.only.values(a, *aX) |
| 28 | + } else expect.toContain.inAnyOrder.only.values(a, *aX, report = report) |
| 29 | + |
| 30 | + private fun toContainInAnyOrderOnlyNullableValues( |
| 31 | + expect: Expect<Iterable<Double?>>, |
| 32 | + a: Double?, |
| 33 | + aX: Array<out Double?>, |
| 34 | + report: InAnyOrderOnlyReportingOptions.() -> Unit |
| 35 | + ): Expect<Iterable<Double?>> = |
| 36 | + if (report === emptyInOrderOnlyReportOptions) { |
| 37 | + if (aX.isEmpty()) expect.toContain.inAnyOrder.only.value(a) |
| 38 | + else expect.toContain.inAnyOrder.only.values(a, *aX) |
| 39 | + } else expect.toContain.inAnyOrder.only.values(a, *aX, report = report) |
| 40 | + } |
| 41 | + |
| 42 | + @Suppress("AssignedValueIsNeverRead", "UNUSED_VARIABLE", "UNUSED_VALUE") |
| 43 | + @Test |
| 44 | + fun ambiguityTest() { |
| 45 | + var list: Expect<List<Number>> = expect(listOf(1)) |
| 46 | + var nSet: Expect<Set<Number?>> = expect(setOf(1)) |
| 47 | + var nCollection: Expect<Collection<Number?>> = expect(setOf(null)) |
| 48 | + var subList: Expect<ArrayList<Number>> = expect(arrayListOf(1)) |
| 49 | + var starSet: Expect<Set<*>> = expect(setOf(1)) |
| 50 | + var starCollection: Expect<Collection<*>> = expect(listOf(null)) |
| 51 | + |
| 52 | + var listValues: Expect<List<Number>> = expect(listOf(1, 1.2)) |
| 53 | + var nSetValues: Expect<Set<Number?>> = expect(setOf(1, 1.2)) |
| 54 | + var nCollectionValues: Expect<Set<Number?>> = expect(setOf(null, 1.2)) |
| 55 | + var subListValues: Expect<ArrayList<Number>> = expect(arrayListOf(1, 1.2)) |
| 56 | + var starSetValues: Expect<Set<*>> = expect(setOf(1, 1.2, "asdf")) |
| 57 | + var starCollectionValues: Expect<Collection<*>> = expect(listOf(1, null, "asdf")) |
| 58 | + |
| 59 | + list = list.toContain.inAnyOrder.only.value(1) |
| 60 | + nSet = nSet.toContain.inAnyOrder.only.value(1) |
| 61 | + nCollection = nCollection.toContain.inAnyOrder.only.value(null) |
| 62 | + subList = subList.toContain.inAnyOrder.only.value(1) |
| 63 | + starSet = starSet.toContain.inAnyOrder.only.value(1) |
| 64 | + starCollection = starCollection.toContain.inAnyOrder.only.value(null) |
| 65 | + |
| 66 | + listValues = listValues.toContain.inAnyOrder.only.values(1, 1.2) |
| 67 | + nSetValues = nSetValues.toContain.inAnyOrder.only.values(1, 1.2) |
| 68 | + nCollectionValues = nCollectionValues.toContain.inAnyOrder.only.values(null, 1.2) |
| 69 | + subListValues = subListValues.toContain.inAnyOrder.only.values(1, 1.2) |
| 70 | + starSetValues = starSetValues.toContain.inAnyOrder.only.values(1, 1.2, "asdf") |
| 71 | + starCollectionValues = starCollectionValues.toContain.inAnyOrder.only.values(1, null, "asdf") |
| 72 | + |
| 73 | + listValues = listValues.toContain.inAnyOrder.only.values(1, 1.2, report = {}) |
| 74 | + nSetValues = nSetValues.toContain.inAnyOrder.only.values(1, 1.2, report = {}) |
| 75 | + subListValues = subListValues.toContain.inAnyOrder.only.values(1, 1.2, report = {}) |
| 76 | + nCollectionValues = nCollectionValues.toContain.inAnyOrder.only.values(null, 1.2, report = {}) |
| 77 | + starSetValues = starSetValues.toContain.inAnyOrder.only.values(1, 1.2, "asdf", report = {}) |
| 78 | + starCollectionValues = starCollectionValues.toContain.inAnyOrder.only.values(1, null, "asdf", report = {}) |
| 79 | + } |
| 80 | +} |
0 commit comments