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

setR reverses its argument #16

Closed
LightAndLight opened this issue Apr 28, 2020 · 1 comment · Fixed by #17
Closed

setR reverses its argument #16

LightAndLight opened this issue Apr 28, 2020 · 1 comment · Fixed by #17
Labels

Comments

@LightAndLight
Copy link
Contributor

setR reverses its argument. For example, setR [4, 5, 6] [ 1 * 2 * 3 ] == [ 1 * 2 * 6 5 4 ].

Would you like me to submit a fix?

Attached: a property test suite that helped me diagnose the issue

module Tests.Pivot exposing (pivotTests)

import Expect
import Fuzz exposing (Fuzzer)
import Pivot exposing (Pivot)
import Test exposing (Test, describe)


genPivotInt : Fuzzer (Pivot Int)
genPivotInt =
    Fuzz.map3
        (\a b c -> Pivot.singleton b |> Pivot.setL a |> Pivot.setR c)
        (Fuzz.list Fuzz.int)
        Fuzz.int
        (Fuzz.list Fuzz.int)


genListInt : Fuzzer (List Int)
genListInt =
    Fuzz.list Fuzz.int


pivotTests : Test
pivotTests =
    describe "pivot"
        [ Test.fuzz genPivotInt "setL (getL a) == a" <|
            \pivot ->
                Pivot.setL (Pivot.getL pivot) pivot
                    |> Expect.equal pivot
        , Test.fuzz2 genListInt genPivotInt "getL (setL l a) == l" <|
            \list pivot ->
                Pivot.getL (Pivot.setL list pivot)
                    |> Expect.equal list
        , Test.fuzz genPivotInt "setR (getR a) == a" <|
            \pivot ->
                Pivot.setR (Pivot.getR pivot) pivot
                    |> Expect.equal pivot
        , Test.fuzz2 genListInt genPivotInt "getR (setR l a) == l" <|
            \list pivot ->
                Pivot.getR (Pivot.setR list pivot)
                    |> Expect.equal list
        , Test.fuzz3 Fuzz.int genListInt genPivotInt "goR (setR (x :: xs) a) == Just (setR xs (appendGoR x a))" <|
            \x xs pivot ->
                Pivot.goR (Pivot.setR (x :: xs) pivot)
                    |> Expect.equal (Just (Pivot.setR xs (Pivot.appendGoR x pivot)))

        ]
@yotamDvir yotamDvir added the bug label Apr 28, 2020
@yotamDvir
Copy link
Owner

Yes please!

Certainly getX (setX l a) == l are desired identities, so this is a bug.
Other identities that should hold but are violated relate to appendListR:

  • appendListR l (setR [] a) == setR l a
  • setR (getR a ++ l) a == appendListR l a

In your submission you are also encouraged to:

  1. Add the tests you wrote in a new file tests/Modify.elm in a format similar to the other test files - separate Test for each method, and using tests/Common/Utils.elm.
  2. Describe this behavior in the documentation like this.

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

Successfully merging a pull request may close this issue.

2 participants