diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-05-03 11:33:48 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-05-03 11:33:48 +0400 |
commit | 2c79ab203d8be419cff936e306722cf47625472b (patch) | |
tree | 13059022f5b5eb833fa4cd53ce8703a497484cef /tests | |
parent | 26867c91679ecf0c93ecde1cf4eb142041580f92 (diff) |
+ Add initial tests for bitfields.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Encoding.hs (renamed from tests/encoding.hs) | 19 | ||||
-rw-r--r-- | tests/Main.hs | 34 |
2 files changed, 36 insertions, 17 deletions
diff --git a/tests/encoding.hs b/tests/Encoding.hs index 405d2eb1..bd452975 100644 --- a/tests/encoding.hs +++ b/tests/Encoding.hs | |||
@@ -1,15 +1,14 @@ | |||
1 | {-# LANGUAGE StandaloneDeriving #-} | 1 | {-# LANGUAGE StandaloneDeriving #-} |
2 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} | 2 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} |
3 | {-# OPTIONS -fno-warn-orphans #-} | 3 | {-# OPTIONS -fno-warn-orphans #-} |
4 | module Main (main) where | 4 | module Encoding where |
5 | 5 | ||
6 | import Control.Applicative | 6 | import Control.Applicative |
7 | import Data.Word | 7 | import Data.Word |
8 | import Data.ByteString (ByteString) | 8 | import Data.ByteString (ByteString) |
9 | import qualified Data.ByteString as B | 9 | import qualified Data.ByteString as B |
10 | import Data.Serialize | 10 | import Data.Serialize |
11 | 11 | import Test.Framework (Test) | |
12 | import Test.Framework (defaultMain, Test) | ||
13 | import Test.Framework.Providers.QuickCheck2 (testProperty) | 12 | import Test.Framework.Providers.QuickCheck2 (testProperty) |
14 | import Test.QuickCheck | 13 | import Test.QuickCheck |
15 | 14 | ||
@@ -85,17 +84,3 @@ test_scrape_url = zipWith mkTest [1 :: Int ..] (check `map` tests) | |||
85 | ] | 84 | ] |
86 | 85 | ||
87 | mkTest i = testProperty ("scrape test #" ++ show i) | 86 | mkTest i = testProperty ("scrape test #" ++ show i) |
88 | |||
89 | main :: IO () | ||
90 | main = defaultMain $ | ||
91 | [ testProperty "Message encode <-> decode" $ | ||
92 | prop_encoding (T :: T Message) | ||
93 | |||
94 | , testProperty "PeerID encode <-> decode" $ | ||
95 | prop_encoding (T :: T PeerID) | ||
96 | |||
97 | , testProperty "Handshake encode <-> decode" $ | ||
98 | prop_encoding (T :: T Handshake) | ||
99 | ] ++ test_scrape_url ++ | ||
100 | [ | ||
101 | ] \ No newline at end of file | ||
diff --git a/tests/Main.hs b/tests/Main.hs new file mode 100644 index 00000000..0b158cb9 --- /dev/null +++ b/tests/Main.hs | |||
@@ -0,0 +1,34 @@ | |||
1 | module Main (main) where | ||
2 | |||
3 | import Test.Framework (defaultMain) | ||
4 | import Test.Framework.Providers.QuickCheck2 (testProperty) | ||
5 | |||
6 | import Encoding | ||
7 | |||
8 | import Network.BitTorrent | ||
9 | |||
10 | prop_bitfieldDiff0 :: Bitfield -> Bool | ||
11 | prop_bitfieldDiff0 b = (b `difference` empty (8 * bitfieldByteCount b)) == b | ||
12 | |||
13 | prop_bitfieldDiff1 :: Bitfield -> Bool | ||
14 | prop_bitfieldDiff1 b = em `difference` b == em | ||
15 | where | ||
16 | em = empty (8 * bitfieldByteCount b) | ||
17 | |||
18 | |||
19 | main :: IO () | ||
20 | main = defaultMain $ | ||
21 | [ testProperty "Message encode <-> decode" $ | ||
22 | prop_encoding (T :: T Message) | ||
23 | |||
24 | , testProperty "PeerID encode <-> decode" $ | ||
25 | prop_encoding (T :: T PeerID) | ||
26 | |||
27 | , testProperty "Handshake encode <-> decode" $ | ||
28 | prop_encoding (T :: T Handshake) | ||
29 | ] | ||
30 | ++ test_scrape_url ++ | ||
31 | [ | ||
32 | testProperty "bitfield `difference` empty bitfield" prop_bitfieldDiff0 | ||
33 | , testProperty "empty bitfield `difference` bitfield" prop_bitfieldDiff1 | ||
34 | ] \ No newline at end of file | ||