From 71560ebe0f02e10e2f70aadae15176fc4571c381 Mon Sep 17 00:00:00 2001 From: Sam T Date: Sun, 31 Mar 2013 15:45:10 +0400 Subject: + tests --- tests/properties.hs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/properties.hs (limited to 'tests') 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 @@ +module Main (main) where + +import Control.Applicative +import qualified Data.ByteString as B +import qualified Data.ByteString.Lazy as L +import Test.Framework (defaultMain) +import Test.Framework.Providers.QuickCheck2 (testProperty) +import Test.QuickCheck + +import Data.BEncode + +instance Arbitrary B.ByteString where + arbitrary = fmap B.pack arbitrary + +instance Arbitrary BEncode where + arbitrary = frequency + [ (50, BInteger <$> arbitrary) + , (40, BString <$> arbitrary) + , (5, BList <$> (arbitrary `suchThat` ((10 >) . length))) + ] + +prop_EncDec :: BEncode -> Bool +prop_EncDec x = case decode (L.toStrict (encode x)) of + Left _ -> False + Right x' -> x == x' + +main :: IO () +main = defaultMain + [ testProperty "encode <-> decode" prop_EncDec + ] \ No newline at end of file -- cgit v1.2.3