From 9bd27cd068591446ff9026420654de14d58e0841 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sun, 2 Mar 2014 17:41:36 +0400 Subject: Allow zero sized buckets --- tests/Network/BitTorrent/Exchange/BlockSpec.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'tests/Network/BitTorrent/Exchange') 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 @@ module Network.BitTorrent.Exchange.BlockSpec (spec) where import Control.Applicative +import Control.Exception import Data.Maybe import Test.Hspec import Test.QuickCheck @@ -15,10 +16,20 @@ instance Arbitrary BlockIx where arbitrary = BlockIx <$> arbitrary <*> arbitrary <*> arbitrary instance Arbitrary Bucket where - arbitrary = Block.fromList <$> arbitrary <*> arbitrary + arbitrary = do + s <- arbitrary `suchThat` (> 0) + chunks <- arbitrary + return $ Block.fromList s chunks + +isSomeException :: SomeException -> Bool +isSomeException = const True spec :: Spec spec = do - describe "bucket" $ do + describe "empty" $ do + it "should fail on bad size" $ do + evaluate (Block.empty (-1)) `shouldThrow` isSomeException + + describe "toPiece" $ do it "render to piece when it is full" $ property $ \ bkt -> full bkt == isJust (toPiece bkt) \ No newline at end of file -- cgit v1.2.3