Skip to content

Instantly share code, notes, and snippets.

@gampleman
Created August 4, 2017 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gampleman/a003ef24ba4d1a131cf86e13112bf581 to your computer and use it in GitHub Desktop.
Save gampleman/a003ef24ba4d1a131cf86e13112bf581 to your computer and use it in GitHub Desktop.
Function Fuzzers
module FunctionFuzzers exposing (..)
import Fuzz exposing (Fuzzer)
import Test.Runner exposing (fuzz)
import Shrink
import Random.Pcg as Random
import Murmur3
function : Fuzzer a -> Fuzzer (b -> a)
function retType =
let
gen =
fuzz retType
fn initialSeed a =
a
|> toString
|> Murmur3.hashString initialSeed
|> Random.initialSeed
|> Random.step gen
|> Tuple.first
|> Tuple.first
generator =
Random.int Random.minInt Random.maxInt
|> Random.map fn
shrinker =
Shrink.noShrink
in
Fuzz.custom generator shrinker
function2 : Fuzzer c -> Fuzzer (a -> b -> c)
function2 =
Fuzz.map curry << function
function3 : Fuzzer d -> Fuzzer (a -> b -> c -> d)
function3 =
Fuzz.map (curry >> curry) << function
function4 : Fuzzer e -> Fuzzer (a -> b -> c -> d -> e)
function4 =
Fuzz.map (curry >> curry >> curry) << function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment