diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-05-03 13:29:43 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-05-03 13:29:43 +0400 |
commit | 506d971c0f37179a680399df3db2faeaa36c0272 (patch) | |
tree | 2e35d3e9bb3675df94268c71a6411dafb65ba4fb /tests | |
parent | 019e33b479ebedf477b80267a2beaa74adfe23a3 (diff) |
+ Add more properties for bitfield operations.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Main.hs | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/tests/Main.hs b/tests/Main.hs index d51afce0..c887fd64 100644 --- a/tests/Main.hs +++ b/tests/Main.hs | |||
@@ -36,24 +36,59 @@ prop_bitfieldMinJust n = | |||
36 | if n == 0 then m == Nothing | 36 | if n == 0 then m == Nothing |
37 | else m == Just 0 | 37 | else m == Just 0 |
38 | 38 | ||
39 | prop_bitfieldUnionIdentity :: Bitfield -> Bool | ||
40 | prop_bitfieldUnionIdentity b = | ||
41 | ((b `union` empty (8 * bitfieldByteCount b)) == b) | ||
42 | && ((empty (8 * bitfieldByteCount b) `union` b) == b) | ||
39 | 43 | ||
40 | main :: IO () | 44 | prop_bitfieldUnionCommutative :: Bitfield -> Bitfield -> Bool |
41 | main = defaultMain $ | 45 | prop_bitfieldUnionCommutative a b = union a b == union b a |
42 | [ testProperty "Message encode <-> decode" $ | 46 | |
43 | prop_encoding (T :: T Message) | 47 | prop_bitfieldUnionAssociative :: Bitfield -> Bitfield -> Bitfield -> Bool |
48 | prop_bitfieldUnionAssociative a b c = union a (union b c) == union (union a b) c | ||
49 | |||
50 | prop_bitfieldUnionIdempotent :: Bitfield -> Bitfield -> Bool | ||
51 | prop_bitfieldUnionIdempotent a b = union a b == union a (union a b) | ||
52 | |||
53 | prop_bitfieldIntersectionIdentity :: Bitfield -> Bool | ||
54 | prop_bitfieldIntersectionIdentity b = | ||
55 | ((b `intersection` full (8 * bitfieldByteCount b)) == b) | ||
56 | && ((full (8 * bitfieldByteCount b) `intersection` b) == b) | ||
57 | |||
58 | prop_bitfieldIntersectionCommutative :: Bitfield -> Bitfield -> Bool | ||
59 | prop_bitfieldIntersectionCommutative a b = intersection a b == intersection b a | ||
44 | 60 | ||
45 | , testProperty "PeerID encode <-> decode" $ | 61 | prop_bitfieldIntersectionAssociative :: Bitfield -> Bitfield -> Bitfield -> Bool |
46 | prop_encoding (T :: T PeerID) | 62 | prop_bitfieldIntersectionAssociative a b c = |
63 | intersection a (intersection b c) == intersection (intersection a b) c | ||
47 | 64 | ||
48 | , testProperty "Handshake encode <-> decode" $ | 65 | prop_bitfieldIntersectionIndempotent :: Bitfield -> Bitfield -> Bool |
49 | prop_encoding (T :: T Handshake) | 66 | prop_bitfieldIntersectionIndempotent a b = f b == f (f b) |
67 | where | ||
68 | f = intersection a | ||
69 | |||
70 | main :: IO () | ||
71 | main = defaultMain $ | ||
72 | [ testProperty "Message encode <-> decode" $ prop_encoding (T :: T Message) | ||
73 | , testProperty "PeerID encode <-> decode" $ prop_encoding (T :: T PeerID) | ||
74 | , testProperty "Handshake encode <-> decode" $ prop_encoding (T :: T Handshake) | ||
50 | ] | 75 | ] |
51 | ++ test_scrape_url ++ | 76 | ++ test_scrape_url ++ |
52 | [ | 77 | [ |
53 | testProperty "bitfield `difference` empty bitfield" prop_bitfieldDiff0 | 78 | testProperty "bitfield `difference` empty bitfield" prop_bitfieldDiff0 |
54 | , testProperty "empty bitfield `difference` bitfield" prop_bitfieldDiff1 | 79 | , testProperty "empty bitfield `difference` bitfield" prop_bitfieldDiff1 |
55 | , testProperty "prop_bitfieldMinNothing" prop_bitfieldMinNothing | 80 | , testProperty "prop_bitfieldMinNothing" prop_bitfieldMinNothing |
56 | , testProperty "prop_bitfieldMaxNothing" prop_bitfieldMaxNothing | 81 | , testProperty "prop_bitfieldMaxNothing" prop_bitfieldMaxNothing |
57 | , testProperty "prop_bitfieldMaxJust" prop_bitfieldMaxJust | 82 | , testProperty "prop_bitfieldMaxJust" prop_bitfieldMaxJust |
58 | , testProperty "prop_bitfieldMinJust" prop_bitfieldMinJust | 83 | , testProperty "prop_bitfieldMinJust" prop_bitfieldMinJust |
84 | |||
85 | , testProperty "prop_bitfieldUnionIdentity" prop_bitfieldUnionIdentity | ||
86 | , testProperty "prop_bitfieldUnionCommutative" prop_bitfieldUnionCommutative | ||
87 | , testProperty "prop_bitfieldUnionAssociative" prop_bitfieldUnionAssociative | ||
88 | , testProperty "prop_bitfieldUnionIdempotent" prop_bitfieldUnionIdempotent | ||
89 | |||
90 | , testProperty "prop_bitfieldIntersectionIdentity" prop_bitfieldIntersectionIdentity | ||
91 | , testProperty "prop_bitfieldIntersectionCommutative" prop_bitfieldIntersectionCommutative | ||
92 | , testProperty "prop_bitfieldIntersectionAssociative" prop_bitfieldIntersectionAssociative | ||
93 | , testProperty "prop_bitfieldIntersectionIndempotent" prop_bitfieldIntersectionIndempotent | ||
59 | ] \ No newline at end of file | 94 | ] \ No newline at end of file |