mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
@@ -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)]
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user