diff options
Diffstat (limited to 'tests/Main.hs')
-rw-r--r-- | tests/Main.hs | 39 |
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 | ||
17 | import Encoding | 17 | import Encoding |
18 | 18 | ||
19 | 19 | {----------------------------------------------------------------------- | |
20 | 20 | Bitfield | |
21 | instance Arbitrary IntSet where | 21 | -----------------------------------------------------------------------} |
22 | arbitrary = fromList <$> arbitrary | 22 | -- other properties are tested in IntervalSet |
23 | 23 | ||
24 | prop_completenessRange :: Bitfield -> Bool | 24 | prop_completenessRange :: Bitfield -> Bool |
25 | prop_completenessRange bf = 0 <= c && c <= 1 | 25 | prop_completenessRange bf = 0 <= c && c <= 1 |
26 | where | 26 | where |
27 | c = completeness bf | 27 | c = completeness bf |
28 | 28 | ||
29 | prop_minMax :: Bitfield -> Bool | ||
30 | prop_minMax bf | ||
31 | | BF.null bf = True | ||
32 | | otherwise = BF.findMin bf <= BF.findMax bf | ||
33 | |||
29 | prop_rarestInRange :: [Bitfield] -> Bool | 34 | prop_rarestInRange :: [Bitfield] -> Bool |
30 | prop_rarestInRange xs = case rarest xs of | 35 | prop_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 -} | ||
41 | prop_differenceDeMorgan :: Bitfield -> Bitfield -> Bitfield -> Bool | ||
42 | prop_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 | |||
34 | main :: IO () | 57 | main :: IO () |
35 | main = defaultMain | 58 | main = 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 | ] |