summaryrefslogtreecommitdiff
path: root/tests/Main.hs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-06-06 21:48:30 +0400
committerSam T <pxqr.sta@gmail.com>2013-06-06 21:48:30 +0400
commit99e771564a1433029ce8a8ce4db8282fc217a1c4 (patch)
tree2b6c80c6bec1f46841b7b881e929cfd0119f95d6 /tests/Main.hs
parent638ffee180b444c6c8d769fa8c95d151a44b7962 (diff)
+ Add some tests.
Diffstat (limited to 'tests/Main.hs')
-rw-r--r--tests/Main.hs30
1 files changed, 27 insertions, 3 deletions
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 ]