Created
September 13, 2022 12:25
-
-
Save gampleman/5fa1d5c084a14de24a0d9475a09641eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FunctionFuzzers exposing (func1, func2, func3) | |
import Bitwise | |
import Expect | |
import Fuzz exposing (Fuzzer) | |
import Random | |
import Shrink | |
import Test exposing (..) | |
import Test.Runner | |
curry : (( a, b ) -> c) -> (a -> b -> c) | |
curry fn a b = | |
fn ( a, b ) | |
combineHashes : (arg1 -> Int) -> (arg2 -> Int) -> ( arg1, arg2 ) -> Int | |
combineHashes hash1 hash2 ( arg1, arg2 ) = | |
Bitwise.xor (hash1 arg1) (hash2 arg2) | |
func1 : (arg -> Int) -> Fuzzer return -> Fuzzer (arg -> return) | |
func1 hash return = | |
case Test.Runner.fuzz return of | |
Ok gen -> | |
let | |
funcGen = | |
Random.int Random.minInt Random.maxInt | |
|> Random.map | |
(\salt input -> | |
Bitwise.xor salt (hash input) | |
|> Random.initialSeed | |
|> Random.step gen | |
|> Tuple.first | |
|> Tuple.first | |
) | |
in | |
Fuzz.custom funcGen Shrink.noShrink | |
Err str -> | |
Fuzz.invalid str | |
func2 : (arg1 -> Int) -> (arg2 -> Int) -> Fuzzer return -> Fuzzer (arg1 -> arg2 -> return) | |
func2 hash1 hash2 return = | |
func1 (combineHashes hash1 hash2) return |> Fuzz.map curry | |
func3 : (arg1 -> Int) -> (arg2 -> Int) -> (arg3 -> Int) -> Fuzzer return -> Fuzzer (arg1 -> arg2 -> arg3 -> return) | |
func3 hash1 hash2 hash3 return = | |
func2 (combineHashes hash1 hash2) hash3 return |> Fuzz.map curry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment