-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQC-basics.hs
More file actions
30 lines (22 loc) · 900 Bytes
/
Copy pathQC-basics.hs
File metadata and controls
30 lines (22 loc) · 900 Bytes
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
import Test.QuickCheck
import Data.List
-- testing a sort routine
qsort :: Ord a => [a] -> [a]
qsort [] = []
qsort (x:xs) = qsort lhs ++ [x] ++ qsort rhs
where lhs = filter (< x) xs
rhs = filter (>= x) xs
prop_idempotent xs = qsort (qsort xs) == qsort xs
prop_minimum xs = head (qsort xs) == minimum xs
-- fails on empty lists
prop_minimum' xs = not (null xs) ==> head (qsort xs) == minimum xs
prop_ordered xs = ordered (qsort xs)
where ordered [] = True
ordered [x] = True
ordered (x:y:ys) = x <= y && ordered (y:xs)
prop_permutation xs = permutation xs (qsort xs)
where permutation xs ys = null (xs \\ ys) && null (ys \\ xs)
prop_maximum xs = not (null xs) ==> last (qsort xs) == maximum xs
prop_append xs ys = not (null xs) ==>
head (qsort (xs ++ ys)) == min (minimum xs) (minimum ys)
prop_sort_model xs = sort xs == qsort xs