-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorting.hs
43 lines (40 loc) · 1.25 KB
/
sorting.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
-- Minimal example: mutation testing a sort specification
--
-- (this program might take a minute to run depending on your system)
--
-- Usage:
--
-- $ ghc -O2 sorting.hs
-- $ ./sorting
-- Apparent incomplete and non-minimal specification based on
-- 4000 test cases for each of properties 1, 2, 3, 4 and 5
-- for each of 4000 mutant variations.
--
-- 3 survivors (99% killed), smallest:
-- \xs -> case xs of
-- [0,0,1] -> [0,1,1]
-- _ -> sort xs
--
-- apparent minimal property subsets: {1,2,3} {1,2,4}
-- conjectures: {3} = {4} 96% killed (weak)
-- {1,3} ==> {5} 98% killed (weak)
import Test.FitSpec
import Data.List (sort)
properties sort =
[ property $ \xs -> ordered (sort xs)
, property $ \xs -> length (sort xs) == length xs
, property $ \x xs -> elem x (sort xs) == elem x xs
, property $ \x xs -> notElem x (sort xs) == notElem x xs
, property $ \x xs -> minimum (x:xs) == head (sort (x:xs))
]
where
ordered (x:y:xs) = x <= y && ordered (y:xs)
ordered _ = True
main =
mainWith args { names = ["sort xs"]
, nMutants = 4000
, nTests = 4000
, timeout = 0
}
(sort::[Word2]->[Word2])
properties