From 11987749fc6e6d3e53ea737d46d5ab13a16faeb8 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Sat, 28 Sep 2019 13:43:29 -0400 Subject: Factor out some new libraries word64-map: Data.Word64Map network-addr: Network.Address tox-crypto: Crypto.Tox lifted-concurrent: Control.Concurrent.Lifted.Instrument Control.Concurrent.Async.Lifted.Instrument psq-wrap: Data.Wrapper.PSQInt Data.Wrapper.PSQ minmax-psq: Data.MinMaxPSQ tasks: Control.Concurrent.Tasks kad: Network.Kademlia Network.Kademlia.Bootstrap Network.Kademlia.Routing Network.Kademlia.CommonAPI Network.Kademlia.Persistence Network.Kademlia.Search --- .../tests/Network/BitTorrent/Exchange/BlockSpec.hs | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 dht/bittorrent/tests/Network/BitTorrent/Exchange/BlockSpec.hs (limited to 'dht/bittorrent/tests/Network/BitTorrent/Exchange/BlockSpec.hs') diff --git a/dht/bittorrent/tests/Network/BitTorrent/Exchange/BlockSpec.hs b/dht/bittorrent/tests/Network/BitTorrent/Exchange/BlockSpec.hs new file mode 100644 index 00000000..2dc8e0b8 --- /dev/null +++ b/dht/bittorrent/tests/Network/BitTorrent/Exchange/BlockSpec.hs @@ -0,0 +1,35 @@ +module Network.BitTorrent.Exchange.BlockSpec (spec) where +import Control.Applicative +import Control.Exception +import Data.Maybe +import Test.Hspec +import Test.QuickCheck +import Test.QuickCheck.Instances () + +import Network.BitTorrent.Exchange.Block as Block + + +instance Arbitrary a => Arbitrary (Block a) where + arbitrary = Block <$> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary BlockIx where + arbitrary = BlockIx <$> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary Bucket where + arbitrary = do + s <- arbitrary `suchThat` (> 0) + chunks <- arbitrary + return $ Block.fromList s chunks + +isSomeException :: SomeException -> Bool +isSomeException = const True + +spec :: Spec +spec = 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