diff --git a/exercises/Set9a.hs b/exercises/Set9a.hs index cdce3ad..3bfecae 100644 --- a/exercises/Set9a.hs +++ b/exercises/Set9a.hs @@ -163,6 +163,10 @@ data Text = Text String -- -- Hint: remember the function `lookup` from Prelude? -- +-- Note! The order of arguments to `compose` is the other way around +-- compared to e.g. (.): `compose f g` should apply `f` first, then +-- `g`, but `f.g` applies `g` first, then `f`. +-- -- Examples: -- composing two mappings of size 1: -- compose [("a",1)] [(1,True)] diff --git a/exercises/Set9aTest.hs b/exercises/Set9aTest.hs index 07561da..8635ce0 100644 --- a/exercises/Set9aTest.hs +++ b/exercises/Set9aTest.hs @@ -21,7 +21,7 @@ tests = [(1,"workload",[ex1_small, ex1_medium, ex1_big]) ,(6,"Lock",[ex6_examples, ex6_gen]) ,(7,"Eq Text",[ex7]) ,(8,"compose",[ex8_one_one, ex8_many_one, ex8_bijection, ex8_surjective]) - ,(9,"permute",[ex9_id, ex9_compose]) + ,(9,"permute",[ex9_id, ex9_simple, ex9_compose]) ] -- -- -- -- -- @@ -191,6 +191,11 @@ ex9_id = property $ do xs <- shuffle (take n "abcdefghij") return $ $(testing [|permute id xs|]) (?== xs) +ex9_simple = forAllShrink_ (sublistOf "pqrstuv") $ \sorted -> + forAllBlind (shuffle sorted) $ \cs -> + let res = [(i,j) | (i,c) <- zip [0..] cs, let Just j = elemIndex c sorted] + in $(testing [|permute res cs|]) (?==sorted) + ex9_compose = property $ do n <- choose (2,5) p <- return . zip [0..n-1] =<< shuffle [0..n-1]