summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSam T <sta.cs.vsu@gmail.com>2013-03-31 15:45:10 +0400
committerSam T <sta.cs.vsu@gmail.com>2013-03-31 15:45:10 +0400
commit71560ebe0f02e10e2f70aadae15176fc4571c381 (patch)
tree79a8f89d718f3ea141ea4b1f004de1142853d86b /tests
parent3c82f6740cfab315892d6cf0186ec0b8188d8d57 (diff)
+ tests
Diffstat (limited to 'tests')
-rw-r--r--tests/properties.hs30
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 @@
1module Main (main) where
2
3import Control.Applicative
4import qualified Data.ByteString as B
5import qualified Data.ByteString.Lazy as L
6import Test.Framework (defaultMain)
7import Test.Framework.Providers.QuickCheck2 (testProperty)
8import Test.QuickCheck
9
10import Data.BEncode
11
12instance Arbitrary B.ByteString where
13 arbitrary = fmap B.pack arbitrary
14
15instance Arbitrary BEncode where
16 arbitrary = frequency
17 [ (50, BInteger <$> arbitrary)
18 , (40, BString <$> arbitrary)
19 , (5, BList <$> (arbitrary `suchThat` ((10 >) . length)))
20 ]
21
22prop_EncDec :: BEncode -> Bool
23prop_EncDec x = case decode (L.toStrict (encode x)) of
24 Left _ -> False
25 Right x' -> x == x'
26
27main :: IO ()
28main = defaultMain
29 [ testProperty "encode <-> decode" prop_EncDec
30 ] \ No newline at end of file