summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-05-03 11:33:48 +0400
committerSam T <pxqr.sta@gmail.com>2013-05-03 11:33:48 +0400
commit2c79ab203d8be419cff936e306722cf47625472b (patch)
tree13059022f5b5eb833fa4cd53ce8703a497484cef /tests
parent26867c91679ecf0c93ecde1cf4eb142041580f92 (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.hs34
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 #-}
4module Main (main) where 4module Encoding where
5 5
6import Control.Applicative 6import Control.Applicative
7import Data.Word 7import Data.Word
8import Data.ByteString (ByteString) 8import Data.ByteString (ByteString)
9import qualified Data.ByteString as B 9import qualified Data.ByteString as B
10import Data.Serialize 10import Data.Serialize
11 11import Test.Framework (Test)
12import Test.Framework (defaultMain, Test)
13import Test.Framework.Providers.QuickCheck2 (testProperty) 12import Test.Framework.Providers.QuickCheck2 (testProperty)
14import Test.QuickCheck 13import 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
89main :: IO ()
90main = 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 @@
1module Main (main) where
2
3import Test.Framework (defaultMain)
4import Test.Framework.Providers.QuickCheck2 (testProperty)
5
6import Encoding
7
8import Network.BitTorrent
9
10prop_bitfieldDiff0 :: Bitfield -> Bool
11prop_bitfieldDiff0 b = (b `difference` empty (8 * bitfieldByteCount b)) == b
12
13prop_bitfieldDiff1 :: Bitfield -> Bool
14prop_bitfieldDiff1 b = em `difference` b == em
15 where
16 em = empty (8 * bitfieldByteCount b)
17
18
19main :: IO ()
20main = 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