summaryrefslogtreecommitdiff
path: root/Tests.hs
blob: c52cc8b2d208f888be46ba9106e52a2ddafc9c23 (plain)
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
import Char
import List 
import Test.QuickCheck
import Text.Printf
import qualified Data.Heap.Binary as B
import qualified Data.Heap.Binomial as N
import qualified Data.Heap.Skew as S
import qualified Data.Tree.AVL as A
import qualified Data.Tree.Splay as P

binary_fromListToList s = (B.toList . B.fromList) s == sort s
  where _ = s :: [Int]

binomial_fromListToList s = (N.toList . N.fromList) s == sort s
  where _ = s :: [Int]

skew_fromListToList s = (S.toList . S.fromList) s == sort s
  where _ = s :: [Int]

avl_fromListToList s = (map fst . A.toList . A.fromList) s == (map fst . sort) s
  where _ = s :: [(Int,Int)]

splay_fromListToList s = (map fst . P.toList . P.fromList) s == (map fst . sort) s
  where _ = s :: [(Int,Int)]



tests = [
    ("Heap.Binary:   toList.fromList/sort", test binary_fromListToList),
    ("Heap.Binomial: toList.fromList/sort", test binomial_fromListToList),
    ("Heap.Skew:     toList.fromList/sort", test skew_fromListToList),
    ("Tree.AVL:      toList.fromList/sort", test avl_fromListToList),
    ("Tree.Splay:    toList.fromList/sort", test splay_fromListToList)]

main  = mapM_ (\(s,a) -> printf "%-25s: " s >> a) tests
 
instance Arbitrary Char where
    arbitrary     = choose ('\0', '\128')
    coarbitrary c = variant (ord c `rem` 4)