fixed-vector-binary (empty) → 0.6.0.0
raw patch · 6 files changed
+190/−0 lines, 6 filesdep +basedep +binarydep +fixed-vectorsetup-changed
Dependencies added: base, binary, fixed-vector, fixed-vector-binary, tasty, tasty-quickcheck
Files
- ChangeLog +3/−0
- Data/Vector/Fixed/Instances/Binary.hs +41/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- fixed-vector-binary.cabal +44/−0
- test/QC.hs +70/−0
+ ChangeLog view
@@ -0,0 +1,3 @@+Changes in 0.6.0.0++ * Initial release
+ Data/Vector/Fixed/Instances/Binary.hs view
@@ -0,0 +1,41 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+-- | Module with binary instances for data types defined in fixed+-- vector+module Data.Vector.Fixed.Instances.Binary 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.Binary (Binary(..))+++instance (Arity n, Binary a) => Binary (B.Vec n a) where+ put = F.mapM_ put+ get = F.replicateM get++instance (Arity n, P.Prim a, Binary a) => Binary (P.Vec n a) where+ put = F.mapM_ put+ get = F.replicateM get++instance (Arity n, S.Storable a, Binary a) => Binary (S.Vec n a) where+ put = F.mapM_ put+ get = F.replicateM get++instance (U.Unbox n a, Binary a) => Binary (U.Vec n a) where+ put = F.mapM_ put+ get = F.replicateM get++instance (Arity n, Binary a) => Binary (F.VecList n a) where+ put = F.mapM_ put+ get = F.replicateM get++instance (Binary a) => Binary (F.Only a) where+ put (F.Only a) = put a+ get = F.Only `fmap` get++instance Binary (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-binary.cabal view
@@ -0,0 +1,44 @@+Name: fixed-vector-binary+Version: 0.6.0.0+Synopsis: Binary instances for fixed-vector+Description:+ Binary 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,+ binary+ Exposed-modules:+ Data.Vector.Fixed.Instances.Binary++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-binary,+ binary,+ 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.Binary+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.Binary ()++++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 :: (Binary a, Arbitrary a, Eq a) => T a -> a -> Bool+p_serialize _ a = 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+++