summaryrefslogtreecommitdiff
path: root/tests/Data/Torrent
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Data/Torrent')
-rw-r--r--tests/Data/Torrent/LayoutSpec.hs30
-rw-r--r--tests/Data/Torrent/MetainfoSpec.hs14
2 files changed, 31 insertions, 13 deletions
diff --git a/tests/Data/Torrent/LayoutSpec.hs b/tests/Data/Torrent/LayoutSpec.hs
new file mode 100644
index 00000000..d3966b3f
--- /dev/null
+++ b/tests/Data/Torrent/LayoutSpec.hs
@@ -0,0 +1,30 @@
1{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2{-# LANGUAGE StandaloneDeriving #-}
3module Data.Torrent.LayoutSpec (spec) where
4
5import Control.Applicative
6import Test.Hspec
7import Test.QuickCheck
8import System.Posix.Types
9
10import Data.Torrent.Layout
11
12
13instance Arbitrary COff where
14 arbitrary = fromIntegral <$> (arbitrary :: Gen Int)
15
16instance Arbitrary a => Arbitrary (FileInfo a) where
17 arbitrary = FileInfo <$> arbitrary <*> arbitrary <*> arbitrary
18
19instance Arbitrary LayoutInfo where
20 arbitrary = oneof
21 [ SingleFile <$> arbitrary
22 , MultiFile <$> arbitrary <*> arbitrary
23 ]
24
25spec :: Spec
26spec = do
27 describe "accumPosition" $ do
28 it "" $ property $ \ p1 p2 p3 s1 s2 s3 ->
29 accumPositions [(p1, s1), (p2, s2), (p3, s3)]
30 `shouldBe` [(p1, (0, s1)), (p2, (s1, s2)), (p3, (s1 + s2, s3))] \ No newline at end of file
diff --git a/tests/Data/Torrent/MetainfoSpec.hs b/tests/Data/Torrent/MetainfoSpec.hs
index 636bb6b1..b5716e07 100644
--- a/tests/Data/Torrent/MetainfoSpec.hs
+++ b/tests/Data/Torrent/MetainfoSpec.hs
@@ -16,7 +16,7 @@ import Test.QuickCheck.Instances ()
16import Data.Torrent.Piece 16import Data.Torrent.Piece
17import Data.Torrent.Layout 17import Data.Torrent.Layout
18import Data.Torrent 18import Data.Torrent
19 19import Data.Torrent.LayoutSpec ()
20 20
21{----------------------------------------------------------------------- 21{-----------------------------------------------------------------------
22-- Common 22-- Common
@@ -38,18 +38,6 @@ instance Arbitrary URI where
38-- Instances 38-- Instances
39-----------------------------------------------------------------------} 39-----------------------------------------------------------------------}
40 40
41instance Arbitrary FileSize where
42 arbitrary = fromIntegral <$> (arbitrary :: Gen Int)
43
44instance Arbitrary a => Arbitrary (FileInfo a) where
45 arbitrary = FileInfo <$> arbitrary <*> arbitrary <*> arbitrary
46
47instance Arbitrary LayoutInfo where
48 arbitrary = oneof
49 [ SingleFile <$> arbitrary
50 , MultiFile <$> arbitrary <*> arbitrary
51 ]
52
53instance Arbitrary HashArray where 41instance Arbitrary HashArray where
54 arbitrary = HashArray <$> arbitrary 42 arbitrary = HashArray <$> arbitrary
55 43