diff options
author | Sam T <sta.cs.vsu@gmail.com> | 2013-03-31 15:45:10 +0400 |
---|---|---|
committer | Sam T <sta.cs.vsu@gmail.com> | 2013-03-31 15:45:10 +0400 |
commit | 71560ebe0f02e10e2f70aadae15176fc4571c381 (patch) | |
tree | 79a8f89d718f3ea141ea4b1f004de1142853d86b /tests | |
parent | 3c82f6740cfab315892d6cf0186ec0b8188d8d57 (diff) |
+ tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/properties.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/properties.hs b/tests/properties.hs new file mode 100644 index 0000000..41950e7 --- /dev/null +++ b/tests/properties.hs | |||
@@ -0,0 +1,30 @@ | |||
1 | module Main (main) where | ||
2 | |||
3 | import Control.Applicative | ||
4 | import qualified Data.ByteString as B | ||
5 | import qualified Data.ByteString.Lazy as L | ||
6 | import Test.Framework (defaultMain) | ||
7 | import Test.Framework.Providers.QuickCheck2 (testProperty) | ||
8 | import Test.QuickCheck | ||
9 | |||
10 | import Data.BEncode | ||
11 | |||
12 | instance Arbitrary B.ByteString where | ||
13 | arbitrary = fmap B.pack arbitrary | ||
14 | |||
15 | instance Arbitrary BEncode where | ||
16 | arbitrary = frequency | ||
17 | [ (50, BInteger <$> arbitrary) | ||
18 | , (40, BString <$> arbitrary) | ||
19 | , (5, BList <$> (arbitrary `suchThat` ((10 >) . length))) | ||
20 | ] | ||
21 | |||
22 | prop_EncDec :: BEncode -> Bool | ||
23 | prop_EncDec x = case decode (L.toStrict (encode x)) of | ||
24 | Left _ -> False | ||
25 | Right x' -> x == x' | ||
26 | |||
27 | main :: IO () | ||
28 | main = defaultMain | ||
29 | [ testProperty "encode <-> decode" prop_EncDec | ||
30 | ] \ No newline at end of file | ||