summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Encoding.hs2
-rw-r--r--tests/Main.hs30
2 files changed, 28 insertions, 4 deletions
diff --git a/tests/Encoding.hs b/tests/Encoding.hs
index 0b678a25..8afd3625 100644
--- a/tests/Encoding.hs
+++ b/tests/Encoding.hs
@@ -35,7 +35,7 @@ instance Arbitrary Block where
35 arbitrary = Block <$> positive <*> positive <*> arbitrary 35 arbitrary = Block <$> positive <*> positive <*> arbitrary
36 36
37instance Arbitrary Bitfield where 37instance Arbitrary Bitfield where
38 arbitrary = mkBitfield <$> positive <*> arbitrary 38 arbitrary = mkBitfield <$> (succ <$> positive) <*> arbitrary
39 39
40instance Arbitrary PortNumber where 40instance Arbitrary PortNumber where
41 arbitrary = fromIntegral <$> (arbitrary :: Gen Word16) 41 arbitrary = fromIntegral <$> (arbitrary :: Gen Word16)
diff --git a/tests/Main.hs b/tests/Main.hs
index bc3f7809..ef4ab8a7 100644
--- a/tests/Main.hs
+++ b/tests/Main.hs
@@ -1,14 +1,38 @@
1{-# LANGUAGE OverloadedStrings #-} 1{-# LANGUAGE OverloadedStrings #-}
2module Main (main) where 2module Main (main) where
3 3
4import Control.Applicative
5import Data.IntervalSet
6import Data.List as L
7import Data.Ord
4import Data.Word 8import Data.Word
9
5import Test.Framework (defaultMain) 10import Test.Framework (defaultMain)
6import Test.Framework.Providers.QuickCheck2 (testProperty) 11import Test.Framework.Providers.QuickCheck2 (testProperty)
12import Test.QuickCheck
13
14import Data.Bitfield as BF
15import Network.BitTorrent as BT
7 16
8import Encoding 17import Encoding
9 18
10import Data.Bitfield as BT 19
11import Network.BitTorrent as BT 20
21instance Arbitrary IntSet where
22 arbitrary = fromList <$> arbitrary
23
24prop_completenessRange :: Bitfield -> Bool
25prop_completenessRange bf = 0 <= c && c <= 1
26 where
27 c = completeness bf
28
29prop_rarestInRange :: [Bitfield] -> Bool
30prop_rarestInRange xs = case rarest xs of
31 Just r -> 0 <= r && r < totalCount (maximumBy (comparing totalCount) xs)
32 Nothing -> True
12 33
13main :: IO () 34main :: IO ()
14main = defaultMain [] 35main = defaultMain
36 [ testProperty "completeness range" prop_completenessRange
37 , testProperty "rarest in range" prop_rarestInRange
38 ]