From 99e771564a1433029ce8a8ce4db8282fc217a1c4 Mon Sep 17 00:00:00 2001 From: Sam T Date: Thu, 6 Jun 2013 21:48:30 +0400 Subject: + Add some tests. --- tests/Main.hs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'tests/Main.hs') 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 @@ {-# LANGUAGE OverloadedStrings #-} module Main (main) where +import Control.Applicative +import Data.IntervalSet +import Data.List as L +import Data.Ord import Data.Word + import Test.Framework (defaultMain) import Test.Framework.Providers.QuickCheck2 (testProperty) +import Test.QuickCheck + +import Data.Bitfield as BF +import Network.BitTorrent as BT import Encoding -import Data.Bitfield as BT -import Network.BitTorrent as BT + + +instance Arbitrary IntSet where + arbitrary = fromList <$> arbitrary + +prop_completenessRange :: Bitfield -> Bool +prop_completenessRange bf = 0 <= c && c <= 1 + where + c = completeness bf + +prop_rarestInRange :: [Bitfield] -> Bool +prop_rarestInRange xs = case rarest xs of + Just r -> 0 <= r && r < totalCount (maximumBy (comparing totalCount) xs) + Nothing -> True main :: IO () -main = defaultMain [] +main = defaultMain + [ testProperty "completeness range" prop_completenessRange + , testProperty "rarest in range" prop_rarestInRange + ] -- cgit v1.2.3