-
Notifications
You must be signed in to change notification settings - Fork 0
/
spring.hs
69 lines (59 loc) · 1.84 KB
/
spring.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 Test.FitSpec
import Data.List
type Add a = a -> a -> a
type Prod a = a -> a -> a
type Ty a = ( Add a
, Prod a )
properties :: (Listable a, Show a, Eq a, Num a)
=> Add a
-> Prod a
-> [Property]
properties (+) (*) =
[ property $ \x y -> x + y == y + x
, property $ \x y z -> x + (y + z) == (x + y) + z
, property $ \x -> x + 0 == x
, property $ \x -> 0 + x == x
, property $ \x y -> x * y == y * x
, property $ \x y z -> x * (y * z) == (x * y) * z
, property $ \x -> x * 1 == x
, property $ \x -> 1 * x == x
, property $ \x y z -> x * (y + z) == (x * y) + (x * z)
, property $ \x y z -> (y + z) * x == (y * x) + (z * x)
]
fns :: Integral a => Ty a
fns = ((+),(*))
sargs :: Args
sargs =
args { timeout = 0
, nMutants = 1000
, nTests = 1000
, names = [ "x + y", "x * y" ]
}
-- , extraMutants =
-- let ems = [ \x y -> x+y+1
-- , \x y -> x*y+x*y
-- , \x y -> x+y+x+y
-- , (+++)
-- , min
-- , max
-- -- another good example would be
-- -- || and && defined over integers
-- ]
-- in drop 1 [ (s,p)
-- | False -- was useExtra
-- , s <- (+):(*):ems
-- , p <- (*):(+):ems
-- ]
main :: IO ()
main = do
as <- getArgsWith sargs
let run f = reportWith as f (uncurry properties)
case concat (extra as) of
"int" -> run (fns :: Ty Int)
"int2" -> run (fns :: Ty UInt2)
"int3" -> run (fns :: Ty UInt3)
"" -> run (fns :: Ty UInt2)
(+++) :: (Show a, Read a, Integral a) => a -> a -> a
x +++ 0 = x
0 +++ y = y
x +++ y = read (show x ++ show (abs y))