1 implementation module stdProperty
4 GAST: A Generic Automatic Software Test-system
6 stdProperty: opertors on logical properties
8 Pieter Koopman, 2004..2008
9 Radboud Universty, Nijmegen
14 import testable, StdEnv
15 from MersenneTwister import genRandInt
17 class (==>) infixr 1 b :: b p -> Property | Testable p
22 | c = Prop (evaluate p)
23 = Prop (\rs r = [{r & res = Rej}])
30 # r1 = testAnalysis r (evaluate c rs r)
35 class (\/) infixr 2 a b :: !a b -> Property // Conditional or of arg1 and arg2
36 class (/\) infixr 3 a b :: !a b -> Property // Conditional and of arg1 and arg2
38 instance /\ Bool Bool where (/\) x y = prop (x && y)
39 instance /\ Property Bool where (/\) x y = x /\ prop y
40 instance /\ Bool Property where (/\) x y = prop x /\ y
41 instance /\ Property Property
42 where (/\) x y = Prop (and x y)
46 r1 = testAnalysis r (evaluate x rs r)
47 r2 = testAnalysis r (evaluate y rs2 r)
48 = case (r1.res,r2.res) of // collect labels !!
49 (CE ,_ ) = [r1] // to fix the evaluation order
76 instance \/ Bool Bool where (\/) x y = prop (x || y)
77 instance \/ Property Bool where (\/) x y = x \/ prop y
78 instance \/ Bool Property where (\/) x y = prop x \/ y
79 instance \/ Property Property
80 where (\/) x y = Prop (or x y)
84 = case testAnalysis r (evaluate x rs r) of
86 r=:{res=Pass} = case testAnalysis r (evaluate y rs2 r) of
91 (<==>) infix 4 :: !a !b -> Property | Testable a & Testable b // True if properties are equivalent
94 r = {res=Undef, labels=[], args=[], name=[]}
95 b = testAnalysis r (evaluate p rs r)
96 c = testAnalysis r (evaluate q rs r)
97 = prop (b.res == c.res) // can this be improved?
99 (===>) infix 1 :: Bool Bool -> Bool
100 (===>) p q = (not p) || q
102 ExistsIn :: (x->p) [x] -> Property | Testable p & TestArg x
103 ExistsIn f l = Prop p
104 where p rs r = [exists r [testAnalysis r (evaluate (f a) rs r)\\a <- l] MaxExists]
106 Exists :: (x->p) -> Property | Testable p & TestArg x
109 # (rs,rs2) = split rs
110 = [exists r [testAnalysis r (evaluate (f a) rs2 r)\\a <- generateAll rs] MaxExists]
111 exists r [] n = {r & res = CE}
112 exists r _ 0 = {r & res = Undef}
113 exists _ [r=:{res}:x] n = case res of
118 noCE r [] n = {r & res = OK}
119 noCE r _ 0 = {r & res = Pass}
120 noCE _ [r=:{res=CE}:x] n = r
121 noCE _ [r=:{res=OK}:x] n = noCE {r&res=Pass} x (n-1)
122 noCE r [_:x] n = noCE r x (n-1)
124 testAnalysis :: Admin [Admin] -> Admin // maakt van een lijst resultaten een enkel resultaat
125 testAnalysis r l = analysis l MaxExists Undef OK
127 analysis [] n min max = {r & res = max}
128 analysis _ 0 min max = {r & res = min}
129 analysis [s:x] n min max
132 OK = analysis x (n-1) Pass max
133 Pass = analysis x (n-1) Pass Pass
134 Undef = analysis x (n-1) min max
136 OK = analysis x (n-1) OK max
137 Pass = analysis x (n-1) Pass max
138 = analysis x (n-1) Rej max
139 = abort "Unknow result in testAnalysis"
141 ForAll :: !(x->p) -> Property | Testable p & TestArg x
142 ForAll f = Prop (evaluate f)
144 ForEach :: ![x] !(x->p) -> Property | Testable p & TestArg x
145 ForEach list f = Prop (forAll f list)
147 (For) infixl 0 :: !(x->p) ![x] -> Property | Testable p & TestArg x
148 (For) p list = ForEach list p
150 // XXXXXXXXXXXXXXXXXXXXXXXXXX
152 class (VOOR) infixl 0 t :: (t a b) [a] -> [b]
154 where VOOR f l = map f l
156 :: PL a b = PL [a->b]
158 where VOOR (PL fl) l = diagonal [map f l\\f<-fl] //[f x \\ f<-fl, x<-l]
160 //| Testable p & TestArg x
162 // XXXXXXXXXXXXXXXXXXXXXXXXXX
164 (ForAndGen) infixl 0 :: !(x->p) ![x] -> Property | Testable p & TestArg x
165 (ForAndGen) p list = Prop (evaluate p)
166 where evaluate f rs result
167 # (rs,rs2) = split rs
168 = forAll f (list++generateAll rs) rs2 result
170 classify :: !Bool l !p -> Property | Testable p & genShow{|*|} l
172 | c = Prop (\rs r = evaluate p rs {r & labels = [show1 l:r.labels]})
175 label :: !l !p -> Property | Testable p & genShow{|*|} l
176 label l p = Prop (\rs r = evaluate p rs {r & labels = [show1 l:r.labels]})
178 name :: !n !p -> Property | Testable p & genShow{|*|} n
179 name n p = Prop (\rs r = evaluate p rs {r & name = [show1 n:r.name]})
181 instance ~ Bool where ~ b = not b
192 where ~ (Prop p) = Prop (\rs r = let r` = testAnalysis r (p rs r) in [{r` & res = ~r`.res}])