diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Main.hs | 15 |
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 #-} |
2 | module Main (main) where | 2 | module Main (main) where |
3 | 3 | ||
4 | import Data.Bits | ||
4 | import Data.Word | 5 | import Data.Word |
5 | import Test.Framework (defaultMain) | 6 | import Test.Framework (defaultMain) |
6 | import Test.Framework.Providers.QuickCheck2 (testProperty) | 7 | import 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 | ||
88 | prop_bitfieldHaveCount :: Bitfield -> Bool | ||
89 | prop_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 | |||
96 | prop_bitfieldCompeteness :: Bitfield -> Bool | ||
97 | prop_bitfieldCompeteness b = let (have, total) = completeness b in have <= total | ||
98 | |||
87 | main :: IO () | 99 | main :: IO () |
88 | main = defaultMain $ | 100 | main = 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 |