diff options
Diffstat (limited to 'tests/Network/BitTorrent/Exchange/BlockSpec.hs')
-rw-r--r-- | tests/Network/BitTorrent/Exchange/BlockSpec.hs | 15 |
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 @@ | |||
1 | module Network.BitTorrent.Exchange.BlockSpec (spec) where | 1 | module Network.BitTorrent.Exchange.BlockSpec (spec) where |
2 | import Control.Applicative | 2 | import Control.Applicative |
3 | import Control.Exception | ||
3 | import Data.Maybe | 4 | import Data.Maybe |
4 | import Test.Hspec | 5 | import Test.Hspec |
5 | import Test.QuickCheck | 6 | import Test.QuickCheck |
@@ -15,10 +16,20 @@ instance Arbitrary BlockIx where | |||
15 | arbitrary = BlockIx <$> arbitrary <*> arbitrary <*> arbitrary | 16 | arbitrary = BlockIx <$> arbitrary <*> arbitrary <*> arbitrary |
16 | 17 | ||
17 | instance Arbitrary Bucket where | 18 | instance 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 | |||
24 | isSomeException :: SomeException -> Bool | ||
25 | isSomeException = const True | ||
19 | 26 | ||
20 | spec :: Spec | 27 | spec :: Spec |
21 | spec = do | 28 | spec = 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 |