@@ -4,6 +4,7 @@ import BitParser
44import BitWriter
55import Bytes exposing (Bytes)
66import Bytes.Extra as Bytes
7+import Expect exposing (Expectation)
78import Fuzz exposing (Fuzzer)
89import List.Extra as List
910import Test exposing (..)
@@ -19,9 +20,37 @@ tests =
1920 (\a ->
2021 maybeBytesEq (Just a) (BitWriter.run (mat a BitWriter.empty) |> BitParser.run rub)
2122 )
23+ , fuzz (noun ())
24+ "jam <-> cue"
25+ (\n ->
26+ maybeNounEq (Just n) (BitWriter.run (jam n BitWriter.empty) |> BitParser.run cue)
27+ )
2228 ]
2329
2430
31+maybeNounEq : Maybe Noun -> Maybe Noun -> Expectation
32+maybeNounEq a b =
33+ case ( a, b ) of
34+ ( Just x, Just y ) ->
35+ nounEq x y
36+
37+ _ ->
38+ Expect.equal a b
39+
40+
41+nounEq : Noun -> Noun -> Expectation
42+nounEq a b =
43+ case ( a, b ) of
44+ ( Atom x, Atom y ) ->
45+ bytesEq x y
46+
47+ ( Cell ( x1, y1 ), Cell ( x2, y2 ) ) ->
48+ Expect.all [ nounEq x1 x2 |> always, nounEq y1 y2 |> always ] ()
49+
50+ _ ->
51+ Expect.fail (Debug.toString a ++ " /= " ++ Debug.toString b)
52+
53+
2554atom : Fuzzer Bytes
2655atom =
2756 bytes
@@ -29,12 +58,9 @@ atom =
2958 (\a -> a |> Bytes.toByteValues |> List.dropWhileRight (\x -> x == 0) |> Bytes.fromByteValues)
3059
3160
32−noun : Fuzzer Noun
33−noun =
34− (\() ->
35− Fuzz.oneOf
36− [ bytes |> Fuzz.map Atom
37− , Fuzz.map2 (\a b -> Cell ( a, b )) noun noun
38− ]
39− )
40− ()
61+noun : () -> Fuzzer Noun
62+noun () =
63+ Fuzz.frequency
64+ [ ( 0.6, atom |> Fuzz.map Atom )
65+ , ( 0.4, Fuzz.map2 (\a b -> Cell ( a, b )) (Fuzz.lazy noun) (Fuzz.lazy noun) )
66+ ]