summaryrefslogtreecommitdiff
path: root/tests/Data/Torrent/LayoutSpec.hs
blob: d3966b3f3acba33e86d2cb782547e8e982d3114a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving         #-}
module Data.Torrent.LayoutSpec (spec) where

import Control.Applicative
import Test.Hspec
import Test.QuickCheck
import System.Posix.Types

import Data.Torrent.Layout


instance Arbitrary COff where
  arbitrary = fromIntegral <$> (arbitrary :: Gen Int)

instance Arbitrary a => Arbitrary (FileInfo a) where
  arbitrary = FileInfo <$> arbitrary <*> arbitrary <*> arbitrary

instance Arbitrary LayoutInfo where
  arbitrary = oneof
    [ SingleFile <$> arbitrary
    , MultiFile  <$> arbitrary <*> arbitrary
    ]

spec :: Spec
spec = do
  describe "accumPosition" $ do
    it "" $ property $ \ p1 p2 p3 s1 s2 s3 ->
      accumPositions [(p1, s1), (p2, s2), (p3, s3)]
        `shouldBe`   [(p1, (0, s1)), (p2, (s1, s2)), (p3, (s1 + s2, s3))]