summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-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