6 | import Data.SortedSet
10 | import PriorityQueue.BinomialQueue
11 | import PriorityQueue.SkewBinomialQueue
12 | import PriorityQueue.Bootstrap
16 | fromList' : {q : Type -> Type} -> PriorityQueue q => List Integer -> q Integer
17 | fromList' is = fromFoldable is
20 | listGen : Gen (List Integer)
21 | listGen = list (linear 0 32) (integer (constant 0 40))
23 | sameUniqueElements : (q : Type -> Type) -> PriorityQueue q => Property
24 | sameUniqueElements q = property $
do
25 | input <- forAll listGen
26 | let input : SortedSet _ = foldl (\acc, e => insert e acc) empty input
27 | let queue : q Integer =
28 | foldl (\acc, e => insert e acc) empty input
29 | let output : SortedSet _ =
30 | foldl (\acc, e => insert e acc) empty $
toList queue
33 | sortsElements : (q : Type -> Type) -> PriorityQueue q => Property
34 | sortsElements q = property $
do
35 | input <- forAll listGen
36 | let queue : q Integer =
37 | foldl (\acc, e => insert e acc) empty input
38 | let output : List _ =
39 | foldr (::) [] $
toList queue
40 | (sort input) === output
42 | emptyTree : (q : Type -> Type) -> PriorityQueue q => Property
43 | emptyTree q = property $
do
44 | let e : q Integer = empty
48 | emptyNull : (q : Type -> Type) -> PriorityQueue q => Property
49 | emptyNull q = property $
do
50 | let e : q Integer = empty
54 | meldSortConcat : (q : Type -> Type) -> PriorityQueue q => Property
55 | meldSortConcat q = property $
do
56 | xs <- forAll listGen
57 | ys <- forAll listGen
58 | let x : q _ = meld (fromList' xs) (fromList' ys)
59 | let y : q _ = fromList' (xs ++ ys)
60 | toList x === toList y
62 | meldSingletons : (q : Type -> Type) -> PriorityQueue q => Property
63 | meldSingletons q = property $
do
64 | xs <- forAll listGen
65 | let x : q _ = foldl meld empty . map singleton $
xs
66 | let y : q _ = fromList' xs
67 | toList x === toList y
69 | minIsMin : (q : Type -> Type) -> PriorityQueue q => Property
70 | minIsMin q = property $
do
71 | xs <- forAll listGen
72 | let x : q _ = fromList' xs
73 | findMin x === head' (sort xs)
75 | deleteRemovesMin : (q : Type -> Type) -> PriorityQueue q => Property
76 | deleteRemovesMin q = property $
do
77 | xs <- forAll listGen
78 | let x : q _ = fromList' xs
79 | let ys = fromMaybe [] (tail' $
sort xs)
80 | let xs = toList (deleteMin x)
83 | lengthCheck : (q : Type -> Type) -> PriorityQueue q => Property
84 | lengthCheck q = property $
do
85 | xs <- forAll listGen
86 | let x : q _ = fromList' xs
87 | length xs === length x
89 | all : (q : Type -> Type) -> (name : String) -> PriorityQueue q => Group
93 | [ ("empty: empty -> []", emptyTree q)
94 | , ("empty: empty -> null", emptyNull q)
95 | , ("length: xs : List x -> pq -> length xs == length pq", lengthCheck q)
96 | , ("min: min [a, ...] -> a", minIsMin q)
97 | , ("min: deleteMin [a, b, ...] -> [b, ...]", deleteRemovesMin q)
98 | , ("insert: SortedSet -> Queue -> SortedSet", sameUniqueElements q)
99 | , ("insert: List -> Queue -> Sorted List", sortsElements q)
100 | , ("meld: [a] meld [b] -> [a] ++ [b]", meldSortConcat q)
101 | , ("meld: foldl meld [a, b, ...] -> fromList' [a, b, ...]", meldSortConcat q)
107 | test [ all BinomialQueue "BinomialQueue"
108 | , all SkewBinomialQueue "SkewBinomialQueue"
109 | , all (Bootstrap SkewBinomialQueue) "Bootstrap SkewBinomialQueue"