diff options
Diffstat (limited to 'tests/Main.hs')
-rw-r--r-- | tests/Main.hs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/Main.hs b/tests/Main.hs index 0aa6423f..ff571b6b 100644 --- a/tests/Main.hs +++ b/tests/Main.hs | |||
@@ -2,20 +2,35 @@ | |||
2 | module Main (main) where | 2 | module Main (main) where |
3 | 3 | ||
4 | import Control.Applicative | 4 | import Control.Applicative |
5 | import qualified Data.ByteString.Lazy as Lazy | ||
5 | import Data.IntervalSet | 6 | import Data.IntervalSet |
6 | import Data.List as L | 7 | import Data.List as L |
7 | import Data.Ord | 8 | import Data.Ord |
9 | import Data.Maybe | ||
8 | import Data.Word | 10 | import Data.Word |
11 | import Data.Text as T | ||
12 | import Network.URI | ||
9 | 13 | ||
10 | import Test.Framework (defaultMain) | 14 | import Test.Framework (defaultMain) |
11 | import Test.Framework.Providers.QuickCheck2 (testProperty) | 15 | import Test.Framework.Providers.QuickCheck2 (testProperty) |
12 | import Test.QuickCheck | 16 | import Test.QuickCheck |
13 | 17 | ||
18 | import Data.BEncode | ||
14 | import Data.Bitfield as BF | 19 | import Data.Bitfield as BF |
20 | import Data.Torrent | ||
15 | import Network.BitTorrent as BT | 21 | import Network.BitTorrent as BT |
16 | 22 | ||
23 | import Debug.Trace | ||
17 | import Encoding | 24 | import Encoding |
18 | 25 | ||
26 | |||
27 | instance Arbitrary URI where | ||
28 | arbitrary = pure $ fromJust | ||
29 | $ parseURI "http://exsample.com:80/123365_asd" | ||
30 | |||
31 | instance Arbitrary Text where | ||
32 | arbitrary = T.pack <$> arbitrary | ||
33 | |||
19 | {----------------------------------------------------------------------- | 34 | {----------------------------------------------------------------------- |
20 | Bitfield | 35 | Bitfield |
21 | -----------------------------------------------------------------------} | 36 | -----------------------------------------------------------------------} |
@@ -51,8 +66,29 @@ prop_differenceDeMorgan a b c = | |||
51 | Torrent | 66 | Torrent |
52 | -----------------------------------------------------------------------} | 67 | -----------------------------------------------------------------------} |
53 | 68 | ||
69 | prop_properBEncode :: Show a => BEncodable a => Eq a => T a -> a -> Bool | ||
70 | prop_properBEncode _ expected = actual == Right expected | ||
71 | where | ||
72 | actual = decoded $ Lazy.toStrict $ encoded expected | ||
73 | |||
74 | |||
54 | -- TODO tests for torrent: encoding <-> decoding | 75 | -- TODO tests for torrent: encoding <-> decoding |
76 | instance Arbitrary FileInfo where | ||
77 | arbitrary = FileInfo <$> arbitrary <*> arbitrary <*> arbitrary | ||
55 | 78 | ||
79 | instance Arbitrary ContentInfo where | ||
80 | arbitrary = oneof | ||
81 | [ SingleFile <$> arbitrary <*> arbitrary <*> arbitrary | ||
82 | <*> arbitrary <*> arbitrary <*> arbitrary | ||
83 | , MultiFile <$> arbitrary <*> arbitrary <*> arbitrary | ||
84 | <*> arbitrary <*> arbitrary | ||
85 | ] | ||
86 | |||
87 | instance Arbitrary Torrent where | ||
88 | arbitrary = torrent <$> arbitrary | ||
89 | <*> arbitrary <*> arbitrary <*> arbitrary | ||
90 | <*> arbitrary <*> arbitrary <*> arbitrary | ||
91 | <*> arbitrary <*> pure Nothing <*> arbitrary | ||
56 | 92 | ||
57 | main :: IO () | 93 | main :: IO () |
58 | main = defaultMain | 94 | main = defaultMain |
@@ -60,4 +96,11 @@ main = defaultMain | |||
60 | , testProperty "rarest in range" prop_rarestInRange | 96 | , testProperty "rarest in range" prop_rarestInRange |
61 | , testProperty "min less that max" prop_minMax | 97 | , testProperty "min less that max" prop_minMax |
62 | , testProperty "difference de morgan" prop_differenceDeMorgan | 98 | , testProperty "difference de morgan" prop_differenceDeMorgan |
99 | |||
100 | , testProperty "file info encoding" $ | ||
101 | prop_properBEncode (T :: T FileInfo) | ||
102 | , testProperty "content info encoding" $ | ||
103 | prop_properBEncode (T :: T ContentInfo) | ||
104 | , testProperty "torrent encoding" $ | ||
105 | prop_properBEncode (T :: T Torrent) | ||
63 | ] | 106 | ] |