diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-06-06 21:48:30 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-06-06 21:48:30 +0400 |
commit | 99e771564a1433029ce8a8ce4db8282fc217a1c4 (patch) | |
tree | 2b6c80c6bec1f46841b7b881e929cfd0119f95d6 /tests/Main.hs | |
parent | 638ffee180b444c6c8d769fa8c95d151a44b7962 (diff) |
+ Add some tests.
Diffstat (limited to 'tests/Main.hs')
-rw-r--r-- | tests/Main.hs | 30 |
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 #-} |
2 | module Main (main) where | 2 | module Main (main) where |
3 | 3 | ||
4 | import Control.Applicative | ||
5 | import Data.IntervalSet | ||
6 | import Data.List as L | ||
7 | import Data.Ord | ||
4 | import Data.Word | 8 | import Data.Word |
9 | |||
5 | import Test.Framework (defaultMain) | 10 | import Test.Framework (defaultMain) |
6 | import Test.Framework.Providers.QuickCheck2 (testProperty) | 11 | import Test.Framework.Providers.QuickCheck2 (testProperty) |
12 | import Test.QuickCheck | ||
13 | |||
14 | import Data.Bitfield as BF | ||
15 | import Network.BitTorrent as BT | ||
7 | 16 | ||
8 | import Encoding | 17 | import Encoding |
9 | 18 | ||
10 | import Data.Bitfield as BT | 19 | |
11 | import Network.BitTorrent as BT | 20 | |
21 | instance Arbitrary IntSet where | ||
22 | arbitrary = fromList <$> arbitrary | ||
23 | |||
24 | prop_completenessRange :: Bitfield -> Bool | ||
25 | prop_completenessRange bf = 0 <= c && c <= 1 | ||
26 | where | ||
27 | c = completeness bf | ||
28 | |||
29 | prop_rarestInRange :: [Bitfield] -> Bool | ||
30 | prop_rarestInRange xs = case rarest xs of | ||
31 | Just r -> 0 <= r && r < totalCount (maximumBy (comparing totalCount) xs) | ||
32 | Nothing -> True | ||
12 | 33 | ||
13 | main :: IO () | 34 | main :: IO () |
14 | main = defaultMain [] | 35 | main = defaultMain |
36 | [ testProperty "completeness range" prop_completenessRange | ||
37 | , testProperty "rarest in range" prop_rarestInRange | ||
38 | ] | ||