-
Notifications
You must be signed in to change notification settings - Fork 0
/
setsofsets.hs
69 lines (57 loc) · 2.18 KB
/
setsofsets.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import Set as S
import Test.FitSpec hiding ((\/),Set)
instance (Ord a, Listable a) => Listable (S.Set a) where
tiers = setCons set
instance (Ord a, Listable a) => Mutable (S.Set a) where
mutiers = mutiersEq
instance (Ord a, Show a, Listable a) => ShowMutable (S.Set a) where
mutantS = mutantSEq
-- The Mutable and ShowMutable instances could be alternatively derived by:
-- deriveMutable 'Set
-- Type of functions under test
type PowerS a = S.Set a -> S.Set (S.Set a)
type PartitionsS a = S.Set a -> S.Set (S.Set (S.Set a))
type Ty a = (PowerS a, PartitionsS a)
-- The property map.
-- In a real program applying FitSpec, the 'Int' parameter would not exist.
-- It is here so we can re-run the steps taken in creating the final
-- property list (by @properties 5@).
properties :: (Ord a, Eq a, Show a, Listable a)
=> Int -> Ty a -> [Property]
properties 0 (powerS,partitionsS) =
[
]
properties 1 (powerS,partitionsS) =
[ property $ \s t -> (t <~ powerS s) == subS t s
, property $ \s -> allS (allS (`subS` s)) (partitionsS s)
]
properties 2 (powerS,partitionsS) =
[ property $ \s t -> (t <~ powerS s) == subS t s
, property $ \s -> allS (allS (`subS` s)) (partitionsS s)
, property $ \s -> nonEmptyS (partitionsS s)
]
properties 3 (powerS,partitionsS) =
[ property $ \s t -> (t <~ powerS s) == subS t s
, property $ \s -> allS (allS (`subS` s)) (partitionsS s)
, property $ \s -> nonEmptyS (partitionsS s)
, property $ \s -> allS (allS (\t -> nonEmptyS t && subS t s)) (partitionsS s)
]
-- Ommited on paper -- we changed 4th to:
--, property $ \s -> allS (\p -> unionS p == s && allS nonEmptyS p) (partitionsS s)
properties _ (powerS,partitionsS) =
[ property $ \s t -> (t <~ powerS s) == subS t s
, property $ \s p -> (p <~ partitionsS s) ==
( unionS p == s &&
allS nonEmptyS p &&
sum (map sizeS (elemList p)) == sizeS s )
]
fns :: Ord a => Ty a
fns = (powerS, partitionsS)
main :: IO ()
main = do
as <- getArgs
let psid = read . concat . extra $ as
mainWith as { names = [ "powerS s"
, "partitionsS s" ] }
(fns::Ty Word2)
(properties psid)