Bug: tests do not terminate because of the recursive nature of
the BVal data type.
directory,
doctest,
tasty,
directory,
doctest,
tasty,
+ tasty-hunit,
+ QuickCheck,
+ tasty-quickcheck,
+ test-framework-quickcheck2
test-suite functorrent-hlint
type: exitcode-stdio-1.0
test-suite functorrent-hlint
type: exitcode-stdio-1.0
import Data.ByteString (ByteString, readFile)
import Data.Map.Strict (fromList)
import Data.ByteString (ByteString, readFile)
import Data.Map.Strict (fromList)
-import Test.Tasty
-import Test.Tasty.HUnit
+import Test.Tasty (TestTree, testGroup, defaultMain)
+import Test.Tasty.HUnit (testCase, (@?=))
+import Test.Tasty.QuickCheck (testProperty)
-import FuncTorrent.Bencode (decode, BVal(..))
+import FuncTorrent.Bencode (encode, decode, BVal(..))
import FuncTorrent.Metainfo (Info(..), Metainfo(..), mkMetaInfo)
import FuncTorrent.Peer (Peer(..))
import FuncTorrent.Tracker
import FuncTorrent.Metainfo (Info(..), Metainfo(..), mkMetaInfo)
import FuncTorrent.Peer (Peer(..))
import FuncTorrent.Tracker
unitTests = testGroup "Unit tests" [testFile, testMkMetaInfo, testResponse1,
testResponse2]
unitTests = testGroup "Unit tests" [testFile, testMkMetaInfo, testResponse1,
testResponse2]
+propEncodeDecode :: BVal -> Bool
+propEncodeDecode bval = let encoded = encode bval
+ decoded = decode encoded
+ in Right bval == decoded
+
+qcTests :: TestTree
+qcTests = testGroup "QuickCheck tests" [ testProperty "encode/decode" propEncodeDecode ]
+
-tests = testGroup "Tests" [unitTests]
+tests = testGroup "Tests" [unitTests, qcTests]
main :: IO ()
main = defaultMain tests
main :: IO ()
main = defaultMain tests