5 (*) gebruik Environment 'Gast'
6 (*) zet Project Options op 'Basic Values Only' en '8M' Maximum Heap Size.
14 (\n` n2` m -> let n = cast [A,B,C] n`
18 conversion_invariant n /\
20 subset_property n n2 /\
21 strictsubset_property n n2 /\
22 empty_properties m n /\
23 disjoint_properties n n2 /\
24 product_properties n n2 /\
25 intersect_properties n n2 /\
26 setminus_properties n n2 /\
27 union_properties n n2 /\
28 powset_properties n /\
39 instance == Enum where (==) x y = gEq{|*|} x y
40 instance < Enum where (<) x y = gEq{|*|} (gLexOrd{|*|} x y) LT
42 // clean should have something like this!
46 membership :: Enum [Enum] -> Property
49 ( memberOfSet x s <==> isMember x xs )
52 conversion_invariant :: [Enum] -> Property
53 conversion_invariant xs
54 = name "conversion_invariant"
55 ( toSet (fromSet xs`) == xs` )
58 length_property :: [Enum] -> Property
60 = name "length_property"
61 ( nrOfElements s == length (removeDup xs) )
64 subset_property :: [Enum] [Enum] -> Property
66 = name "subset_property"
67 ( (isSubset u v) <==> all (flip isMember ys) xs)
68 where (u,v) = (toSet xs, toSet ys)
70 strictsubset_property :: [Enum] [Enum] -> Property
71 strictsubset_property xs ys
72 = name "strictsubset_property"
73 ( (isStrictSubset u v) <==> (all (flip isMember ys) xs && not (all (flip isMember xs) ys)) )
74 where (u,v) = (toSet xs, toSet ys)
76 // everything you alwys wanted to know about the empty set...
77 // ... but were afraid to ask
78 empty_properties :: Enum [Enum] -> Property
80 = name "empty_properties"
81 ( isEmptySet (cast dummy zero) /\ isEmptySet (toSet (cast [A] [])) /\
82 ((nrOfElements s == 0) <==> isEmptySet s) /\
83 ((zero == s) <==> isEmptySet s) )
88 product_properties :: [Enum] [Enum] -> Property
89 product_properties xs ys
90 = name "product_properties"
91 ( product u v == toSet [(x,y) \\ x<-xs, y<-ys ] )
92 where (u,v) = (toSet xs, toSet ys)
94 powset_properties :: [Enum] -> Property
96 = name "powset_properties"
97 ( powerSet s == toSet (map toSet (subs xs)) )
100 subs [x:xs] = subs xs ++ [ [x:xs`] \\ xs` <- subs xs ]
102 union_properties :: [Enum] [Enum] -> Property
103 union_properties xs ys
104 = name "union_properties"
105 ( union u v == toSet (xs++ys) )
106 where (u,v) = (toSet xs, toSet ys)
108 intersect_properties :: [Enum] [Enum] -> Property
109 intersect_properties xs ys
110 = name "intersect_properties"
111 ( intersection u v == toSet [ x \\ x<-xs | isMember x ys ] )
112 where (u,v) = (toSet xs, toSet ys)
114 setminus_properties :: [Enum] [Enum] -> Property
115 setminus_properties xs ys
116 = name "setminus_properties"
117 ( without u v == toSet [ x \\ x<-xs | not (isMember x ys) ])
118 where (u,v) = (toSet xs, toSet ys)
120 disjoint_properties :: [Enum] [Enum] -> Property
121 disjoint_properties xs ys
122 = name "disjoint_properties"
123 ( isDisjoint u v <==> (nrOfElements u + nrOfElements v == nrOfElements (union u v)) )
124 where (u,v) = (toSet xs, toSet ys)