Skip to content

Commit

Permalink
Curry pair and triple fuzzers.
Browse files Browse the repository at this point in the history
  • Loading branch information
drathier committed Oct 22, 2020
1 parent 06401ce commit 387aa2d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/Fuzz.elm
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,17 @@ array fuzzer =
map Array.fromList (list fuzzer)


{-| Turn a pair of fuzzers into a fuzzer of pairs.
{-| Create a fuzzer of pairs from two fuzzers.
-}
pair : ( Fuzzer a, Fuzzer b ) -> Fuzzer ( a, b )
pair ( fuzzerA, fuzzerB ) =
pair : Fuzzer a -> Fuzzer b -> Fuzzer ( a, b )
pair fuzzerA fuzzerB =
map2 (\a b -> ( a, b )) fuzzerA fuzzerB


{-| Turn a triple of fuzzers into a fuzzer of triples.
{-| Create a fuzzer of triples from three fuzzers.
-}
triple : ( Fuzzer a, Fuzzer b, Fuzzer c ) -> Fuzzer ( a, b, c )
triple ( fuzzerA, fuzzerB, fuzzerC ) =
triple : Fuzzer a -> Fuzzer b -> Fuzzer c -> Fuzzer ( a, b, c )
triple fuzzerA fuzzerB fuzzerC =
map3 (\a b c -> ( a, b, c )) fuzzerA fuzzerB fuzzerC


Expand Down
6 changes: 3 additions & 3 deletions src/Test.elm
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ for example like this:
fuzzWith { runs = 4200 }
(pair ( list int, int ))
(pair (list int) int)
"List.reverse never influences List.member" <|
\(nums, target) ->
List.member target (List.reverse nums)
Expand Down Expand Up @@ -399,7 +399,7 @@ fuzz2 :
fuzz2 fuzzA fuzzB desc =
let
fuzzer =
Fuzz.pair ( fuzzA, fuzzB )
Fuzz.pair fuzzA fuzzB
in
(\f ( a, b ) -> f a b) >> fuzz fuzzer desc

Expand All @@ -419,7 +419,7 @@ fuzz3 :
fuzz3 fuzzA fuzzB fuzzC desc =
let
fuzzer =
Fuzz.triple ( fuzzA, fuzzB, fuzzC )
Fuzz.triple fuzzA fuzzB fuzzC
in
uncurry3 >> fuzz fuzzer desc

Expand Down
2 changes: 1 addition & 1 deletion tests/src/FloatWithinTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ floatWithinTests =
a |> Expect.notWithin (Absolute (abs epsilon)) b
in
different withinTest notWithinTest
, fuzz2 (pair ( float, float )) (pair ( float, float )) "within and notWithin should never agree on absolute or relative tolerance" <|
, fuzz2 (pair float float) (pair float float) "within and notWithin should never agree on absolute or relative tolerance" <|
\( absoluteEpsilon, relativeEpsilon ) ( a, b ) ->
let
withinTest =
Expand Down
20 changes: 8 additions & 12 deletions tests/src/FuzzerTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,15 @@ fuzzerTests =

aFuzzer =
triple
( pair ( list int, array float )
, pair
( maybe bool
, result unit char
)
, pair
( triple
( percentage
, map2 (+) int int
, frequency [ ( 1, constant True ), ( 3, constant False ) ]
)
, triple ( intRange 0 100, floatRange -51 pi, map abs int )
(pair (list int) (array float))
(pair (maybe bool) (result unit char))
(pair
(triple
percentage
(map2 (+) int int)
(frequency [ ( 1, constant True ), ( 3, constant False ) ])
)
(triple (intRange 0 100) (floatRange -51 pi) (map abs int))
)
|> Test.Runner.fuzz

Expand Down

0 comments on commit 387aa2d

Please sign in to comment.