summaryrefslogtreecommitdiff
path: root/tests/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Main.hs')
-rw-r--r--tests/Main.hs39
1 files changed, 32 insertions, 7 deletions
diff --git a/tests/Main.hs b/tests/Main.hs
index ef4ab8a7..0aa6423f 100644
--- a/tests/Main.hs
+++ b/tests/Main.hs
@@ -16,23 +16,48 @@ import Network.BitTorrent as BT
16 16
17import Encoding 17import Encoding
18 18
19 19{-----------------------------------------------------------------------
20 20 Bitfield
21instance Arbitrary IntSet where 21-----------------------------------------------------------------------}
22 arbitrary = fromList <$> arbitrary 22-- other properties are tested in IntervalSet
23 23
24prop_completenessRange :: Bitfield -> Bool 24prop_completenessRange :: Bitfield -> Bool
25prop_completenessRange bf = 0 <= c && c <= 1 25prop_completenessRange bf = 0 <= c && c <= 1
26 where 26 where
27 c = completeness bf 27 c = completeness bf
28 28
29prop_minMax :: Bitfield -> Bool
30prop_minMax bf
31 | BF.null bf = True
32 | otherwise = BF.findMin bf <= BF.findMax bf
33
29prop_rarestInRange :: [Bitfield] -> Bool 34prop_rarestInRange :: [Bitfield] -> Bool
30prop_rarestInRange xs = case rarest xs of 35prop_rarestInRange xs = case rarest xs of
31 Just r -> 0 <= r && r < totalCount (maximumBy (comparing totalCount) xs) 36 Just r -> 0 <= r
37 && r < totalCount (maximumBy (comparing totalCount) xs)
32 Nothing -> True 38 Nothing -> True
33 39
40{- this one should give pretty good coverage -}
41prop_differenceDeMorgan :: Bitfield -> Bitfield -> Bitfield -> Bool
42prop_differenceDeMorgan a b c =
43 (a `BF.difference` (b `BF.intersection` c))
44 == ((a `BF.difference` b) `BF.union` (a `BF.difference` c))
45 &&
46 (a `BF.difference` (b `BF.union` c))
47 == ((a `BF.difference` b) `BF.intersection` (a `BF.difference` c))
48
49
50{-----------------------------------------------------------------------
51 Torrent
52-----------------------------------------------------------------------}
53
54-- TODO tests for torrent: encoding <-> decoding
55
56
34main :: IO () 57main :: IO ()
35main = defaultMain 58main = defaultMain
36 [ testProperty "completeness range" prop_completenessRange 59 [ testProperty "completeness range" prop_completenessRange
37 , testProperty "rarest in range" prop_rarestInRange 60 , testProperty "rarest in range" prop_rarestInRange
61 , testProperty "min less that max" prop_minMax
62 , testProperty "difference de morgan" prop_differenceDeMorgan
38 ] 63 ]