Set 9a Ex 9: clarify text, add test

for #31
This commit is contained in:
Joel Kaasinen
2021-06-02 17:23:42 +03:00
parent 5a09751913
commit fc6670267c
2 changed files with 10 additions and 1 deletions
+4
View File
@@ -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)]
+6 -1
View File
@@ -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]