fixed-vector-cereal (empty) → 0.6.0.0
raw patch · 6 files changed
+191/−0 lines, 6 filesdep +basedep +cerealdep +fixed-vectorsetup-changed
Dependencies added: base, cereal, fixed-vector, fixed-vector-cereal, tasty, tasty-quickcheck
Files
- ChangeLog +3/−0
- Data/Vector/Fixed/Instances/Cereal.hs +41/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- fixed-vector-cereal.cabal +45/−0
- test/QC.hs +70/−0
+ ChangeLog view
@@ -0,0 +1,3 @@+Changes in 0.6.0.0++ * Initial release
+ Data/Vector/Fixed/Instances/Cereal.hs view
@@ -0,0 +1,41 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+-- | Module with cereal instances for data types defined in fixed+-- vector+module Data.Vector.Fixed.Instances.Cereal where++import Data.Vector.Fixed (Arity)+import qualified Data.Vector.Fixed as F+import qualified Data.Vector.Fixed.Boxed as B+import qualified Data.Vector.Fixed.Unboxed as U+import qualified Data.Vector.Fixed.Primitive as P+import qualified Data.Vector.Fixed.Storable as S+import Data.Serialize (Serialize(..))+++instance (Arity n, Serialize a) => Serialize (B.Vec n a) where+ put = F.mapM_ put+ get = F.replicateM get++instance (Arity n, P.Prim a, Serialize a) => Serialize (P.Vec n a) where+ put = F.mapM_ put+ get = F.replicateM get++instance (Arity n, S.Storable a, Serialize a) => Serialize (S.Vec n a) where+ put = F.mapM_ put+ get = F.replicateM get++instance (U.Unbox n a, Serialize a) => Serialize (U.Vec n a) where+ put = F.mapM_ put+ get = F.replicateM get++instance (Arity n, Serialize a) => Serialize (F.VecList n a) where+ put = F.mapM_ put+ get = F.replicateM get++instance (Serialize a) => Serialize (F.Only a) where+ put (F.Only a) = put a+ get = F.Only `fmap` get++instance Serialize (F.Empty a) where+ put _ = return ()+ get = return F.Empty
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) Aleksey Khudyakov++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:++1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.++3. Neither the name of the author nor the names of his contributors+ may be used to endorse or promote products derived from this software+ without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS+OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ fixed-vector-cereal.cabal view
@@ -0,0 +1,45 @@+Name: fixed-vector-cereal+Version: 0.6.0.0+Synopsis: Cereal instances for fixed-vector+Description:+ Cereal instances for fixed-vector+ +Cabal-Version: >= 1.8+License: BSD3+License-File: LICENSE+Author: Aleksey Khudyakov <alexey.skladnoy@gmail.com>+Maintainer: Aleksey Khudyakov <alexey.skladnoy@gmail.com>+Bug-reports: https://github.com/Shimuuar/fixed-vector/issues+Category: Data+Build-Type: Simple+extra-source-files:+ ChangeLog++source-repository head+ type: hg+ location: http://bitbucket.org/Shimuuar/fixed-vector+source-repository head+ type: git+ location: http://github.com/Shimuuar/fixed-vector++Library+ Ghc-options: -Wall+ Build-Depends:+ base >=3 && <5,+ fixed-vector >= 0.6,+ cereal+ Exposed-modules:+ Data.Vector.Fixed.Instances.Cereal++Test-Suite test+ Type: exitcode-stdio-1.0+ Hs-source-dirs: test+ Main-is: QC.hs+ Build-Depends:+ base >=3 && <5,+ fixed-vector,+ fixed-vector-cereal,+ cereal,+ tasty,+ tasty-quickcheck+
+ test/QC.hs view
@@ -0,0 +1,70 @@+{-# LANGUAGE ScopedTypeVariables #-}+import Test.Tasty+import Test.Tasty.QuickCheck as QC++import Data.Typeable+import Data.Serialize+import Data.Vector.Fixed (N2,N3,N4)+import qualified Data.Vector.Fixed as F+import qualified Data.Vector.Fixed.Unboxed as U+import qualified Data.Vector.Fixed.Boxed as B+import qualified Data.Vector.Fixed.Storable as S+import qualified Data.Vector.Fixed.Primitive as P+import Data.Vector.Fixed.Instances.Cereal ()++++tests = testGroup "cereal"+ [ testTagged p_serialize (T :: T (F.Only Int))+ , testTagged p_serialize (T :: T (F.VecList N2 Int))+ , testTagged p_serialize (T :: T (F.VecList N3 Int))+ , testTagged p_serialize (T :: T (F.VecList N4 Int))+ --+ , testTagged p_serialize (T :: T (U.Vec N2 Int))+ , testTagged p_serialize (T :: T (U.Vec N3 Int))+ , testTagged p_serialize (T :: T (U.Vec N4 Int))+ --+ , testTagged p_serialize (T :: T (B.Vec N2 Int))+ , testTagged p_serialize (T :: T (B.Vec N3 Int))+ , testTagged p_serialize (T :: T (B.Vec N4 Int))+ --+ , testTagged p_serialize (T :: T (S.Vec N2 Int))+ , testTagged p_serialize (T :: T (S.Vec N3 Int))+ , testTagged p_serialize (T :: T (S.Vec N4 Int))+ --+ , testTagged p_serialize (T :: T (P.Vec N2 Int))+ , testTagged p_serialize (T :: T (P.Vec N3 Int))+ , testTagged p_serialize (T :: T (P.Vec N4 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)++main :: IO ()+main = defaultMain tests++----------------------------------------------------------------+instance Arbitrary a => Arbitrary (F.Only a) where+ arbitrary = F.replicateM arbitrary+instance Arbitrary a => Arbitrary (F.Empty a) where+ arbitrary = F.replicateM arbitrary++instance (F.Arity n, Arbitrary a) => Arbitrary (F.VecList n a) where+ arbitrary = F.replicateM arbitrary+instance (U.Unbox n a, Arbitrary a) => Arbitrary (U.Vec n a) where+ arbitrary = F.replicateM arbitrary+instance (F.Arity n, Arbitrary a) => Arbitrary (B.Vec n a) where+ arbitrary = F.replicateM arbitrary+instance (F.Arity n, S.Storable a, Arbitrary a) => Arbitrary (S.Vec n a) where+ arbitrary = F.replicateM arbitrary+instance (F.Arity n, P.Prim a, Arbitrary a) => Arbitrary (P.Vec n a) where+ arbitrary = F.replicateM arbitrary+++