]> git.rkrishnan.org Git - functorrent.git/blob - src/TestInstances.hs
Move Arbitrary instances into another module
[functorrent.git] / src / TestInstances.hs
1 module FuncTorrent.TestInstances where
2
3 import qualified Data.ByteString as B
4 import Test.QuickCheck
5
6 import Bencode
7
8 instance Arbitrary B.ByteString where
9   arbitrary = B.pack <$> arbitrary
10
11 instance Arbitrary BVal where
12   arbitrary = sized bval
13               where
14                 bval :: Int -> Gen BVal
15                 bval 0 = oneof [ Bint <$> arbitrary
16                                , Bstr <$> arbitrary]
17                 bval n = oneof [ Bint <$> arbitrary
18                                , Bstr <$> arbitrary
19                                , Blist <$> vectorOf n (bval (n `div` 4))
20                                , do keys <- vectorOf n arbitrary
21                                     vals <- vectorOf n (bval (n `div` 4))
22                                     return $ Bdict $ fromList $ zip keys vals ]