diff options
Diffstat (limited to 'tests/Main.hs')
-rw-r--r-- | tests/Main.hs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/Main.hs b/tests/Main.hs index fb69565d..6180069f 100644 --- a/tests/Main.hs +++ b/tests/Main.hs | |||
@@ -59,6 +59,86 @@ instance Arbitrary URI where | |||
59 | instance Arbitrary Text where | 59 | instance Arbitrary Text where |
60 | arbitrary = T.pack <$> arbitrary | 60 | arbitrary = T.pack <$> arbitrary |
61 | 61 | ||
62 | {- | ||
63 | {----------------------------------------------------------------------- | ||
64 | MemMap | ||
65 | -----------------------------------------------------------------------} | ||
66 | |||
67 | tmpdir :: FilePath | ||
68 | tmpdir = "tmp" | ||
69 | |||
70 | boundaryTest :: Assertion | ||
71 | boundaryTest = do | ||
72 | f <- mallocTo (Fixed.interval 0 1) Fixed.empty | ||
73 | f <- mallocTo (Fixed.interval 1 2) f | ||
74 | writeElem f 0 (1 :: Word8) | ||
75 | writeElem f 1 (2 :: Word8) | ||
76 | bs <- readBytes (Fixed.interval 0 2) f | ||
77 | "\x1\x2" @=? bs | ||
78 | |||
79 | mmapSingle :: Assertion | ||
80 | mmapSingle = do | ||
81 | f <- mmapTo (tmpdir </> "single.test") (10, 5) 5 Fixed.empty | ||
82 | writeBytes (Fixed.interval 5 5) "abcde" f | ||
83 | bs <- readBytes (Fixed.interval 5 5) f | ||
84 | "abcde" @=? bs | ||
85 | |||
86 | coalesceTest :: Assertion | ||
87 | coalesceTest = do | ||
88 | f <- mmapTo (tmpdir </> "a.test") (0, 1) 10 Fixed.empty | ||
89 | f <- mmapTo (tmpdir </> "bc.test") (0, 2) 12 f | ||
90 | f <- mmapTo (tmpdir </> "c.test") (0, 1) 13 f | ||
91 | writeBytes (Fixed.interval 10 4) "abcd" f | ||
92 | bs <- readBytes (Fixed.interval 10 4) f | ||
93 | "abcd" @=? bs | ||
94 | -} | ||
95 | |||
96 | {----------------------------------------------------------------------- | ||
97 | Bitfield | ||
98 | -----------------------------------------------------------------------} | ||
99 | -- other properties are tested in IntervalSet | ||
100 | |||
101 | prop_completenessRange :: Bitfield -> Bool | ||
102 | prop_completenessRange bf = 0 <= c && c <= 1 | ||
103 | where | ||
104 | c = completeness bf | ||
105 | |||
106 | prop_minMax :: Bitfield -> Bool | ||
107 | prop_minMax bf | ||
108 | | BF.null bf = True | ||
109 | | otherwise = BF.findMin bf <= BF.findMax bf | ||
110 | |||
111 | prop_rarestInRange :: [Bitfield] -> Bool | ||
112 | prop_rarestInRange xs = case rarest xs of | ||
113 | Just r -> 0 <= r | ||
114 | && r < totalCount (maximumBy (comparing totalCount) xs) | ||
115 | Nothing -> True | ||
116 | |||
117 | {- this one should give pretty good coverage -} | ||
118 | prop_differenceDeMorgan :: Bitfield -> Bitfield -> Bitfield -> Bool | ||
119 | prop_differenceDeMorgan a b c = | ||
120 | (a `BF.difference` (b `BF.intersection` c)) | ||
121 | == ((a `BF.difference` b) `BF.union` (a `BF.difference` c)) | ||
122 | && | ||
123 | (a `BF.difference` (b `BF.union` c)) | ||
124 | == ((a `BF.difference` b) `BF.intersection` (a `BF.difference` c)) | ||
125 | |||
126 | {- | ||
127 | [ -- mem map | ||
128 | testCase "boudary" boundaryTest | ||
129 | , testCase "single" mmapSingle | ||
130 | , testCase "coalesce" coalesceTest | ||
131 | ] | ||
132 | |||
133 | instance Arbitrary Bitfield where | ||
134 | arbitrary = mkBitfield <$> (succ . min 1000 <$> positive) | ||
135 | <*> arbitrary | ||
136 | |||
137 | testProperty "completeness range" prop_completenessRange | ||
138 | , testProperty "rarest in range" prop_rarestInRange | ||
139 | , testProperty "min less that max" prop_minMax | ||
140 | , testProperty "difference de morgan" prop_differenceDeMorgan | ||
141 | -} | ||
62 | {----------------------------------------------------------------------- | 142 | {----------------------------------------------------------------------- |
63 | Handshake | 143 | Handshake |
64 | -----------------------------------------------------------------------} | 144 | -----------------------------------------------------------------------} |