Commits

Aleksey Khudyakov committed c23cef0

Add tests for cereal instances

  • Participants
  • Parent commits e07d164

Comments (0)

Files changed (4)

File histogram-fill-tests/Test.hs

 import Test.Tasty            (testGroup,defaultMain)
+import qualified Test.Cereal
 import qualified Test.Histogram
 
 main :: IO ()
 main =
   defaultMain $ testGroup "tests"
     [ Test.Histogram.tests
+    , Test.Cereal.tests
     ]

File histogram-fill-tests/Test/Cereal.hs

+{-# LANGUAGE ScopedTypeVariables #-}
+module Test.Cereal ( tests
+  ) where
+
+import Data.Typeable
+import Data.Serialize
+
+import Test.QuickCheck
+import Test.Tasty            (TestTree,testGroup)
+import Test.Tasty.QuickCheck (testProperty)
+
+import Data.Histogram
+import Data.Histogram.Bin.MaybeBin
+import Data.Histogram.QuickCheck   ()
+import Data.Histogram.Cereal       ()
+
+
+tests :: TestTree
+tests = testGroup "cereal"
+  [ testTagged p_serialize (T :: T BinI)
+  , testTagged p_serialize (T :: T BinInt)
+  , testTagged p_serialize (T :: T (BinF Float))
+  , testTagged p_serialize (T :: T BinD)
+  , testTagged p_serialize (T :: T (BinEnum Char))
+  , testTagged p_serialize (T :: T LogBinD)
+  , testTagged p_serialize (T :: T (MaybeBin BinI))
+  , testTagged p_serialize (T :: T (Bin2D BinI BinI))
+    --
+  , testTagged p_serialize (T :: T (Histogram BinI Int))
+  ]
+
+
+
+p_serialize :: (Serialize a, Arbitrary a, Eq a) => T a -> a -> Bool
+p_serialize _ a = Right a == (decode . encode) a
+
+data T a = T
+
+testTagged :: forall a b. (Testable b, Typeable a) => (T a -> b) -> T a -> TestTree
+testTagged prop t
+  = testProperty (show $ typeOf (undefined :: a)) (prop t)

File histogram-fill-tests/Test/Histogram.hs

 import Data.Typeable
 
 import Test.QuickCheck
-import Test.Tasty            (TestTree,testGroup,defaultMain)
+import Test.Tasty            (TestTree,testGroup)
 import Test.Tasty.QuickCheck (testProperty)
 
 import Data.Histogram
 --
 ----------------------------------------------------------------
 
-tests :: [TestTree]
+tests :: TestTree
 tests = testGroup "Histogram"
   [ testGroup "Bins"
     [ testsBin (T :: T BinI)

File histogram-fill-tests/histogram-fill-tests.cabal

   Main-is:        Test.hs
   Other-modules:
     Test.Histogram
+    Test.Cereal
   Build-depends:
     base >=3 && < 5,
     histogram-fill,
+    histogram-fill-cereal,
     histogram-fill-quickcheck,
     vector,
+    cereal,
     QuickCheck >= 2,
     tasty,
     tasty-quickcheck