Skip to content
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

elementsOf(List) for contains.inOrder.only #128

Closed
robstoll opened this issue Aug 27, 2019 · 13 comments
Closed

elementsOf(List) for contains.inOrder.only #128

robstoll opened this issue Aug 27, 2019 · 13 comments
Assignees
Milestone

Comments

@robstoll
Copy link
Owner

robstoll commented Aug 27, 2019

Platform (jvm, jdk8, js, android): all

Code related feature

val otherList : List<Int>
expect(listOf(1, 2)).contains.inOrder.only.elementsOf(otherList)

//instead of

expect(listOf(1, 2)).contains.inOrder.only.elementsOf(otherList.first(), *otherList.drop(1).toTypedArray())

Following the things you need to do (see also a0b539c for a guideline):

api

  • add fun elementsOf in apis/fluent-en_GB/atrium-fluent_en_GB-common/.../iterableContainsInOrderOnlyCreators.kt (see other functions there)
    • it is enough if you delegate to values
    • require that List.isNotEmpty
    • add @since 0.9.0 to the KDOC
  • extend IterableContainsInOrderOnlyValuesAssertionsSpec (add another include, similar to BuilderSpec)

Your first contribution?

  • Write a comment I'll work on this if you would like to take this issue over.
    This way we get the chance to revise the description in case things have changed in the meantime,
    we might give you additional hints and we can assign the task to you, so that others do not start as well.
  • See Your first code contribution for guidelines.
  • Do not hesitate to ask questions here or to contact us via Atrium's slack channel if you need help
    (Invite yourself in case you do not have an account yet).
@robstoll robstoll added this to the 0.9.0 milestone Aug 29, 2019
@mehdikazemi8
Copy link

Hi Robert,
I'll work on this.

@robstoll
Copy link
Owner Author

@mehdikazemi8 as you have not yet forked the repo I was wondering if you need help. Let me know if this is the case and have a look at Your first code contribution

@robstoll
Copy link
Owner Author

robstoll commented Oct 11, 2019

@mehdikazemi8 do you need any help? (unassigning you in the meantime so that others could pick up with they want)

@npswedberg
Copy link
Contributor

Hi new to atrium but would love to give this a shot

@robstoll
Copy link
Owner Author

robstoll commented Oct 14, 2019

@npswedberg go for it 👍 (and write here or on slack if you need help)

@npswedberg
Copy link
Contributor

Hi I think I am a bit confused on the last point "extend IterableContainsInOrderOnlyValuesAssertionsSpec (add another include, similar to BuilderSpec)". I am assuming I am going to make a new spec file called IterableContainsInOrderAtLeast1ElementsOfAssertionSpec. By extend do you mean that my new spec should inherit from the ValuesAssertionSpec? Sorry I am very new to Kotlin and any hints would be greatly appreciated.

@npswedberg
Copy link
Contributor

npswedberg commented Oct 22, 2019

package ch.tutteli.atrium.api.fluent.en_GB

import ch.tutteli.atrium.creating.Expect
import org.spekframework.spek2.Spek
import kotlin.reflect.KFunction3

class IterableContainsInOrderAtLeast1ElementsOfAssertionSpec : Spek({
    include(BuilderSpec)
    include(ShortcutSpec)
    //include(IterableContainsInOrderOnlyValuesAssertionsSpec)

}) {
    object BuilderSpec : ch.tutteli.atrium.specs.integration.IterableContainsInAnyOrderAtLeast1ValuesAssertionsSpec (
        getContainsPair(),
        getContainsNullablePair(),
        "◆ ",
        "[Atrium][Builder] "
    )

    object ShortcutSpec : ch.tutteli.atrium.specs.integration.IterableContainsInAnyOrderAtLeast1ValuesAssertionsSpec(
        getContainsShortcutPair(),
        getContainsNullableShortcutPair(),
        "◆ ",
        "[Atrium][Shortcut] "
    )

    companion object : IterableContainsSpecBase() {
        fun getContainsPair() = "$contains.$inOrder.$atLeast(1).$inOrderElementsOf" to Companion::containsInOrderOnlyValues

        private fun containsInOrderOnlyValues(
            plant: Expect<Iterable<Double>>,
            a: Double,
            aX: Array<out Double>
        ): Expect<Iterable<Double>> =
            if (aX.isEmpty()) plant.contains.inOrder.atLeast(1).$inOrderElementsOf(a)
            else plant.contains.inOrder.atLeast(1).inOrderElementsOf.values(a, *aX)

        fun getContainsNullablePair() =
            "$contains.$inOrder.$atLeast(1).$inOrderElementsOf" to Companion::containsInOrderOnlyNullableValues

        private fun containsInOrderOnlyNullableValues(
            plant: Expect<Iterable<Double?>>,
            a: Double?,
            aX: Array<out Double?>
        ): Expect<Iterable<Double?>> =
            if (aX.isEmpty()) plant.contains.inOrder.only.value(a)
            else plant.contains.inOrder.only.values(a, *aX)

        private val containsShortcutFun: KFunction3<Expect<Iterable<Double>>, Double, Array<out Double>, Expect<Iterable<Double>>> =
            Expect<Iterable<Double>>::containsExactly

        fun getContainsShortcutPair() = containsShortcutFun.name to Companion::containsInOrderOnlyValuesShortcut

        private fun containsInOrderOnlyValuesShortcut(
            plant: Expect<Iterable<Double>>,
            a: Double,
            aX: Array<out Double>
        ): Expect<Iterable<Double>> =
            if (aX.isEmpty()) plant.containsExactly(a)
            else plant.containsExactly(a, *aX)

        private val containsNullableShortcutFun: KFunction3<Expect<Iterable<Double?>>, Double?, Array<out Double?>, Expect<Iterable<Double?>>> =
            Expect<Iterable<Double?>>::containsExactly

        fun getContainsNullableShortcutPair() =
            containsNullableShortcutFun.name to Companion::containsInOrderOnlyNullableValuesShortcut

        private fun containsInOrderOnlyNullableValuesShortcut(
            plant: Expect<Iterable<Double?>>,
            a: Double?,
            aX: Array<out Double?>
        ): Expect<Iterable<Double?>> =
            if (aX.isEmpty()) plant.containsExactly(a)
            else plant.containsExactly(a, *aX)
    }
}

@robstoll
Copy link
Owner Author

robstoll commented Oct 22, 2019

Your approach is fine as well and maybe even better thinking in longer terms.
Yet, please delete ShortcutSpec as you don't implement a shortcut (only the builder) => basically you can do it like this: a0b539c#diff-9470ba377a3696d1eae2652a91019f8f

A few notes about the code above:

plant.contains.inOrder.atLeast(1).inOrderElementsOf.values(a, *aX)

Please name your function just elementsOf (no need for the inOrder suffix).
I suggest you create a pull request, this way I can review your code you wrote so far and give you additional hints.

@npswedberg
Copy link
Contributor

Hi Rob, Thank you so much for the help! Here is the PR #247

@npswedberg
Copy link
Contributor

My current build is broken because the pattern I was following expected integration tests. Should I write integration tests for this feature?

@robstoll
Copy link
Owner Author

@npswedberg yes tests are required. See review for details why your build fails.

@npswedberg
Copy link
Contributor

Thanks for the feedback the PR has been updated

@robstoll
Copy link
Owner Author

Implemented by 71f7be4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants