summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Main.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/Main.hs b/tests/Main.hs
index 4045f793..5a9a50ee 100644
--- a/tests/Main.hs
+++ b/tests/Main.hs
@@ -1,6 +1,7 @@
1{-# LANGUAGE OverloadedStrings #-} 1{-# LANGUAGE OverloadedStrings #-}
2module Main (main) where 2module Main (main) where
3 3
4import Data.Bits
4import Data.Word 5import Data.Word
5import Test.Framework (defaultMain) 6import Test.Framework (defaultMain)
6import Test.Framework.Providers.QuickCheck2 (testProperty) 7import Test.Framework.Providers.QuickCheck2 (testProperty)
@@ -84,6 +85,17 @@ prop_bitfieldIntersectionIndempotent a b = f b == f (f b)
84 where 85 where
85 f = intersection a 86 f = intersection a
86 87
88prop_bitfieldHaveCount :: Bitfield -> Bool
89prop_bitfieldHaveCount b = listHaveCount (toList b) == haveCount b
90 where
91 listHaveCount = foldr f 0
92
93 f :: Bool -> Int -> Int
94 f byte count = fromEnum byte + count
95
96prop_bitfieldCompeteness :: Bitfield -> Bool
97prop_bitfieldCompeteness b = let (have, total) = completeness b in have <= total
98
87main :: IO () 99main :: IO ()
88main = defaultMain $ 100main = defaultMain $
89 [ testProperty "Message encode <-> decode" $ prop_encoding (T :: T Message) 101 [ testProperty "Message encode <-> decode" $ prop_encoding (T :: T Message)
@@ -111,4 +123,7 @@ main = defaultMain $
111 , testProperty "prop_bitfieldIntersectionCommutative" prop_bitfieldIntersectionCommutative 123 , testProperty "prop_bitfieldIntersectionCommutative" prop_bitfieldIntersectionCommutative
112 , testProperty "prop_bitfieldIntersectionAssociative" prop_bitfieldIntersectionAssociative 124 , testProperty "prop_bitfieldIntersectionAssociative" prop_bitfieldIntersectionAssociative
113 , testProperty "prop_bitfieldIntersectionIndempotent" prop_bitfieldIntersectionIndempotent 125 , testProperty "prop_bitfieldIntersectionIndempotent" prop_bitfieldIntersectionIndempotent
126
127 , testProperty "prop_bitfieldHaveCount" prop_bitfieldHaveCount
128 , testProperty "prop_bitfieldCompeteness" prop_bitfieldCompeteness
114 ] \ No newline at end of file 129 ] \ No newline at end of file