Skip to content

Commit

Permalink
Fix setR (#17)
Browse files Browse the repository at this point in the history
* Added some Modify tests

* Remove only to allow all tests to run

* Stop setR from reversing its arguments

* Added documentation to setL and setR

* Moved docs out from Pivot.Modify to Pivot
  • Loading branch information
LightAndLight authored May 5, 2020
1 parent 45979cb commit 9c65618
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/Pivot.elm
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,23 @@ setC =


{-| Replace the left.
setL [ 1, 2, 3 ] [ 99 * 4 * 5 ] == [ 1 2 3 * 4 * 5 ]
getL >> setL == identity
-}
setL : List a -> Pivot a -> Pivot a
setL =
Modify.setL


{-| Replace the right.
setR [ 3, 4, 5 ] [ 1 * 2 * 99 ] == [ 1 * 2 * 3 4 5 ]
getR >> setR == identity
-}
setR : List a -> Pivot a -> Pivot a
setR =
Expand Down
4 changes: 2 additions & 2 deletions src/Pivot/Modify.elm
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ setL l_ (Pivot c ( l, r )) =


setR : List a -> Pivot a -> Pivot a
setR r_ =
setL r_ |> mirror
setR r_ (Pivot c ( l, r )) =
Pivot c ( l, r_ )


switchL : Pivot a -> Maybe (Pivot a)
Expand Down
39 changes: 39 additions & 0 deletions tests/Modify.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Modify exposing (..)

import Common.Units as Fuzz exposing (pivot)
import Expect
import Fuzz
import Pivot
import Test exposing (Test, describe)


setL : Test
setL =
describe "setL"
[ Test.fuzz (Fuzz.pivot Fuzz.int) "setL (getL a) a == a" <|
\pivot ->
Pivot.setL (Pivot.getL pivot) pivot
|> Expect.equal pivot
, Test.fuzz2 (Fuzz.list Fuzz.int) (Fuzz.pivot Fuzz.int) "getL (setL l a) == l" <|
\list pivot ->
Pivot.getL (Pivot.setL list pivot)
|> Expect.equal list
]


setR : Test
setR =
describe "setR"
[ Test.fuzz (Fuzz.pivot Fuzz.int) "setR (getR a) == a" <|
\pivot ->
Pivot.setR (Pivot.getR pivot) pivot
|> Expect.equal pivot
, Test.fuzz2 (Fuzz.list Fuzz.int) (Fuzz.pivot Fuzz.int) "getR (setR l a) == l" <|
\list pivot ->
Pivot.getR (Pivot.setR list pivot)
|> Expect.equal list
, Test.fuzz3 Fuzz.int (Fuzz.list Fuzz.int) (Fuzz.pivot Fuzz.int) "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)))
]
13 changes: 6 additions & 7 deletions tests/Position.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import Test exposing (Test, describe, fuzz, fuzz2, fuzz3, only, skip, test)

goR : Test
goR =
only <|
describe "goR" <|
[ test "goR [1 2 3 *4*] == Nothing" <|
\_ -> E.equal (P.goR p_1_2_3__4__) Nothing
, test "goR [1 *2* 3 4] == Just [1 2 *3* 4]" <|
\_ -> E.equal (P.goR p_1__2__3_4_) (Just p_1_2__3__4_)
]
describe "goR" <|
[ test "goR [1 2 3 *4*] == Nothing" <|
\_ -> E.equal (P.goR p_1_2_3__4__) Nothing
, test "goR [1 *2* 3 4] == Just [1 2 *3* 4]" <|
\_ -> E.equal (P.goR p_1__2__3_4_) (Just p_1_2__3__4_)
]

0 comments on commit 9c65618

Please sign in to comment.