summaryrefslogtreecommitdiff
path: root/tests/Network
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-03-02 17:41:36 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-03-02 17:41:36 +0400
commit9bd27cd068591446ff9026420654de14d58e0841 (patch)
treefea02372ebfd22b0f5874f3e55c088b7b0c48073 /tests/Network
parent39af7d8024fdc358a41fe164e10c2e3eb9e5f13e (diff)
Allow zero sized buckets
Diffstat (limited to 'tests/Network')
-rw-r--r--tests/Network/BitTorrent/Exchange/BlockSpec.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/tests/Network/BitTorrent/Exchange/BlockSpec.hs b/tests/Network/BitTorrent/Exchange/BlockSpec.hs
index d0d71906..2dc8e0b8 100644
--- a/tests/Network/BitTorrent/Exchange/BlockSpec.hs
+++ b/tests/Network/BitTorrent/Exchange/BlockSpec.hs
@@ -1,5 +1,6 @@
1module Network.BitTorrent.Exchange.BlockSpec (spec) where 1module Network.BitTorrent.Exchange.BlockSpec (spec) where
2import Control.Applicative 2import Control.Applicative
3import Control.Exception
3import Data.Maybe 4import Data.Maybe
4import Test.Hspec 5import Test.Hspec
5import Test.QuickCheck 6import Test.QuickCheck
@@ -15,10 +16,20 @@ instance Arbitrary BlockIx where
15 arbitrary = BlockIx <$> arbitrary <*> arbitrary <*> arbitrary 16 arbitrary = BlockIx <$> arbitrary <*> arbitrary <*> arbitrary
16 17
17instance Arbitrary Bucket where 18instance Arbitrary Bucket where
18 arbitrary = Block.fromList <$> arbitrary <*> arbitrary 19 arbitrary = do
20 s <- arbitrary `suchThat` (> 0)
21 chunks <- arbitrary
22 return $ Block.fromList s chunks
23
24isSomeException :: SomeException -> Bool
25isSomeException = const True
19 26
20spec :: Spec 27spec :: Spec
21spec = do 28spec = do
22 describe "bucket" $ do 29 describe "empty" $ do
30 it "should fail on bad size" $ do
31 evaluate (Block.empty (-1)) `shouldThrow` isSomeException
32
33 describe "toPiece" $ do
23 it "render to piece when it is full" $ property $ \ bkt -> 34 it "render to piece when it is full" $ property $ \ bkt ->
24 full bkt == isJust (toPiece bkt) \ No newline at end of file 35 full bkt == isJust (toPiece bkt) \ No newline at end of file