Skip to content

Commit

Permalink
Merge pull request #86 from harrysarson/tuples
Browse files Browse the repository at this point in the history
* Fix docs: Runner.String.run does not return a tuple.
This has been wrong since 54f790a (3 years!).

* Rename tuple to pair
* Rename tuple3 to triple.

Closes #48
  • Loading branch information
mgold committed Apr 16, 2019
2 parents 7a03aa3 + ac52bb2 commit e90de74
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 38 deletions.
16 changes: 8 additions & 8 deletions src/Fuzz.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Fuzz exposing
( int, intRange, float, floatRange, percentage, string, bool, maybe, result, list, array
, Fuzzer, oneOf, constant, map, map2, map3, map4, map5, andMap, frequency
, tuple, tuple3
, pair, triple
, custom, char, unit, order, invalid
)

Expand Down Expand Up @@ -31,7 +31,7 @@ reproduces a bug.
Instead of using a tuple, consider using `fuzzN`.
@docs tuple, tuple3
@docs pair, triple
## Uncommon Fuzzers
Expand Down Expand Up @@ -466,17 +466,17 @@ array fuzzer =
map Array.fromList (list fuzzer)


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


{-| Turn a 3-tuple of fuzzers into a fuzzer of 3-tuples.
{-| Turn a triple of fuzzers into a fuzzer of triples.
-}
tuple3 : ( Fuzzer a, Fuzzer b, Fuzzer c ) -> Fuzzer ( a, b, c )
tuple3 ( 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
20 changes: 10 additions & 10 deletions src/Simplify.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Simplify exposing
( Simplifier, simplify
, simplest, bool, int, float, string, order, atLeastInt, atLeastFloat, char, atLeastChar, character
, maybe, result, list, array, tuple, tuple3
, maybe, result, list, array, pair, triple
, keepIf, dropIf, merge
, fromFunction, convert
)
Expand Down Expand Up @@ -37,7 +37,7 @@ fail and find a simpler input that also fails, to better illustrate the bug.
## Simplifiers of data structures
@docs maybe, result, list, array, tuple, tuple3
@docs maybe, result, list, array, pair, triple
## Functions on Simplifiers
Expand Down Expand Up @@ -441,11 +441,11 @@ array simplifier =
convert Lazy.List.toArray Lazy.List.fromArray (lazylist simplifier)


{-| 2-Tuple simplifier constructor.
Takes a tuple of simplifiers and returns a simplifier of tuples.
{-| Pair simplifier constructor.
Takes a pair of simplifiers and returns a simplifier of pairs.
-}
tuple : ( Simplifier a, Simplifier b ) -> Simplifier ( a, b )
tuple ( Simp simplifyA, Simp simplifyB ) =
pair : ( Simplifier a, Simplifier b ) -> Simplifier ( a, b )
pair ( Simp simplifyA, Simp simplifyB ) =
Simp <|
\( a, b ) ->
append (Lazy.List.map (Tuple.pair a) (simplifyB b))
Expand All @@ -454,11 +454,11 @@ tuple ( Simp simplifyA, Simp simplifyB ) =
)


{-| 3-Tuple simplifier constructor.
Takes a tuple of simplifiers and returns a simplifier of tuples.
{-| Triple simplifier constructor.
Takes a triple of simplifiers and returns a simplifier of triples.
-}
tuple3 : ( Simplifier a, Simplifier b, Simplifier c ) -> Simplifier ( a, b, c )
tuple3 ( Simp simplifyA, Simp simplifyB, Simp simplifyC ) =
triple : ( Simplifier a, Simplifier b, Simplifier c ) -> Simplifier ( a, b, c )
triple ( Simp simplifyA, Simp simplifyB, Simp simplifyC ) =
Simp <|
\( a, b, c ) ->
append (Lazy.List.map (\c1 -> ( a, b, c1 )) (simplifyC c))
Expand Down
16 changes: 8 additions & 8 deletions src/Test.elm
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,16 @@ type alias FuzzOptions =
{-| Run a [`fuzz`](#fuzz) test with the given [`FuzzOptions`](#FuzzOptions).
Note that there is no `fuzzWith2`, but you can always pass more fuzz values in
using [`Fuzz.tuple`](Fuzz#tuple), [`Fuzz.tuple3`](Fuzz#tuple3),
using [`Fuzz.pair`](Fuzz#pair), [`Fuzz.triple`](Fuzz#triple),
for example like this:
import Test exposing (fuzzWith)
import Fuzz exposing (tuple, list, int)
import Fuzz exposing (pair, list, int)
import Expect
fuzzWith { runs = 4200 }
(tuple ( 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 @@ -376,9 +376,9 @@ fuzz =

{-| Run a [fuzz test](#fuzz) using two random inputs.
This is a convenience function that lets you skip calling [`Fuzz.tuple`](Fuzz#tuple).
This is a convenience function that lets you skip calling [`Fuzz.pair`](Fuzz#pair).
See [`fuzzWith`](#fuzzWith) for an example of writing this in tuple style.
See [`fuzzWith`](#fuzzWith) for an example of writing this using tuples.
import Test exposing (fuzz2)
import Fuzz exposing (list, int)
Expand All @@ -399,14 +399,14 @@ fuzz2 :
fuzz2 fuzzA fuzzB desc =
let
fuzzer =
Fuzz.tuple ( fuzzA, fuzzB )
Fuzz.pair ( fuzzA, fuzzB )
in
(\f ( a, b ) -> f a b) >> fuzz fuzzer desc


{-| Run a [fuzz test](#fuzz) using three random inputs.
This is a convenience function that lets you skip calling [`Fuzz.tuple3`](Fuzz#tuple3).
This is a convenience function that lets you skip calling [`Fuzz.triple`](Fuzz#triple).
-}
fuzz3 :
Expand All @@ -419,7 +419,7 @@ fuzz3 :
fuzz3 fuzzA fuzzB fuzzC desc =
let
fuzzer =
Fuzz.tuple3 ( 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 (tuple ( float, float )) (tuple ( 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
14 changes: 7 additions & 7 deletions tests/src/FuzzerTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ die =
fuzzerTests : Test
fuzzerTests =
describe "Fuzzer methods that use Debug.crash don't call it"
[ describe "FuzzN (uses tupleN) testing string length properties"
[ describe "FuzzN (uses use pair or triple) testing string length properties"
[ fuzz2 string string "fuzz2" <|
\a b ->
testStringLengthIsPreserved [ a, b ]
Expand All @@ -42,19 +42,19 @@ fuzzerTests =
Random.step gen seed

aFuzzer =
tuple3
( tuple ( list int, array float )
, tuple
triple
( pair ( list int, array float )
, pair
( maybe bool
, result unit char
)
, tuple
( tuple3
, pair
( triple
( percentage
, map2 (+) int int
, frequency [ ( 1, constant True ), ( 3, constant False ) ]
)
, tuple3 ( intRange 0 100, floatRange -51 pi, map abs int )
, triple ( intRange 0 100, floatRange -51 pi, map abs int )
)
)
|> Test.Runner.fuzz
Expand Down
6 changes: 2 additions & 4 deletions tests/src/Runner/String.elm
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ indentLines str =
|> String.join "\n"


{-| Run a test and return a tuple of the output message and the number of
tests that failed.
{-| Run a test and return a Summary.
Fuzz tests use a default run count of 100, and a fixed initial seed.
Expand All @@ -116,8 +115,7 @@ run =
runWithOptions defaultRuns defaultSeed


{-| Run a test and return a tuple of the output message and the number of
tests that failed.
{-| Run a test and return a Summary.
-}
runWithOptions : Int -> Random.Seed -> Test -> Summary
runWithOptions runs seed test =
Expand Down

0 comments on commit e90de74

Please sign in to comment.