ianmackenzie/elm-random-test/1.0.0

Test.Random

The Test.checkN functions work much like the Test.fuzzN functions from elm-test, except you pass Generator values instead of Fuzzer values and the description is passed first (I personally think it reads better that way).

Internally, the given generators will be:

check : String -> Generator a -> (a -> Expectation) -> Test
check2 : String -> Generator a -> Generator b -> (a -> b -> Expectation) -> Test
String
-> Generator a
-> Generator b
-> Generator c
-> (a -> b -> c -> Expectation)
-> Test
String
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> (a -> b -> c -> d -> Expectation)
-> Test
String
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
-> (a -> b -> c -> d -> e -> Expectation)
-> Test
String
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
-> Generator f
-> (a -> b -> c -> d -> e -> f -> Expectation)
-> Test
String
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
-> Generator f
-> Generator g
-> (a -> b -> c -> d -> e -> f -> g -> Expectation)
-> Test
String
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
-> Generator f
-> Generator g
-> Generator h
-> (a -> b -> c -> d -> e -> f -> g -> h -> Expectation)
-> Test

Advanced

checkExpectation : String -> Generator Expectation -> Test

If you need to write tests with more than 8 inputs or otherwise need more flexibility, you can use this function. Instead of passing value generators and an expectation function separately, you use whatever functionality you want to build up a Generator Expectation and then test that.

For example,

Test.Random.check2 "My test"
    firstGenerator
    secondGenerator
    Expect.equal

could be written as

Test.Random.checkExpectation "My test" <|
    Random.map2 Expect.equal
        firstGenerator
        secondGenerator

where existing Random functionality (in this case Random.map2) is used to convert a couple of value generators into an Expectation generator.