packages feed

massiv-test 0.1.6 → 0.1.6.1

raw patch · 9 files changed

+132/−80 lines, 9 filesdep ~massivPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: massiv

API changes (from Hackage documentation)

+ Test.Massiv.Utils: beforeAllWith :: (b -> IO a) -> SpecWith a -> SpecWith b
- Test.Massiv.Array.Numeric: prop_MatrixMatrixMultiply :: forall r e. (Numeric r e, Mutable r Ix2 e, Eq e, Show e) => Fun e e -> Matrix r e -> Property
+ Test.Massiv.Array.Numeric: prop_MatrixMatrixMultiply :: forall r e. (Numeric r e, Mutable r Ix2 e, Eq (Matrix r e), Show (Matrix r e)) => Fun e e -> Matrix r e -> Property

Files

LICENSE view
@@ -1,4 +1,4 @@-Copyright Alexey Kuleshevich (c) 2017-2019+Copyright Alexey Kuleshevich (c) 2017-2021  All rights reserved. 
massiv-test.cabal view
@@ -1,5 +1,5 @@ name:                massiv-test-version:             0.1.6+version:             0.1.6.1 synopsis:            Library that contains generators, properties and tests for Massiv Array Library. description:         This library is designed for users of massiv library that need random generators for writing custom property tests and reusing some of the predefined ones. homepage:            https://github.com/lehins/massiv@@ -7,7 +7,7 @@ license-file:        LICENSE author:              Alexey Kuleshevich maintainer:          alexey@kuleshevi.ch-copyright:           2018-2019 Alexey Kuleshevich+copyright:           2018-2021 Alexey Kuleshevich category:            Data, Data Structures, Parallelism build-type:          Simple extra-source-files:  README.md@@ -80,7 +80,7 @@                     , data-default                     , deepseq                     , genvalidity-hspec-                    , massiv >= 0.5.2+                    , massiv >= 0.6                     , massiv-test                     , mwc-random                     , hspec@@ -133,7 +133,7 @@                     , data-default                     , deepseq                     , genvalidity-hspec-                    , massiv >= 0.5.2+                    , massiv >= 0.6                     , massiv-test                     , mwc-random                     , hspec
src/Test/Massiv/Array/Numeric.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE BangPatterns #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MonoLocalBinds #-} {-# LANGUAGE RankNTypes #-}@@ -37,14 +38,15 @@   prop_MatrixMatrixMultiply ::-     forall r e. (Numeric r e, Mutable r Ix2 e, Eq e, Show e)+     forall r e. (Numeric r e, Mutable r Ix2 e, Eq (Matrix r e), Show (Matrix r e))   => Fun e e   -> Matrix r e   -> Property prop_MatrixMatrixMultiply f arr = expectProp $ do   let arr' = A.transpose (A.map (applyFun f) arr)-  arr !><! arr' `shouldBe` naiveMatrixMatrixMultiply (delay arr) arr'-  arr !><! transpose arr `shouldBe` naiveMatrixMatrixMultiply (delay arr) (transpose arr)+  arr !><! compute arr' `shouldBe` compute (naiveMatrixMatrixMultiply (delay arr) arr')+  arr !><! compute (transpose arr) `shouldBe`+    compute (naiveMatrixMatrixMultiply (delay arr) (transpose arr))   let Sz2 m n = size arr   when (m /= n) $     arr .><. arr `shouldThrow` (== SizeMismatchException (size arr) (Sz2 m n))@@ -78,8 +80,6 @@      , Mutable r Ix2 e      , Source (R r) Ix1 e      , Mutable r Ix1 e-     , Eq e-     , Show e      , Show (Vector r e)      , Eq (Vector r e)      )@@ -90,7 +90,8 @@   expectProp $ do     let Sz2 m _ = size arr         v = makeArray Seq (Sz m) (applyFun f)-    v ><! arr `shouldBe` flatten (naiveMatrixMatrixMultiply (resize' (Sz2 1 m) v) (delay arr))+    v ><! arr `shouldBe`+      compute (flatten (naiveMatrixMatrixMultiply (resize' (Sz2 1 m) v) (delay arr)))     multiplyVectorByMatrix v arr `shouldReturn` compute (v ><! arr)     makeArray Seq (Sz (m + 1)) (applyFun f) ><. arr `shouldThrow`       (== SizeMismatchException (Sz2 1 (m + 1)) (size arr))
src/Test/Massiv/Core/Mutable.hs view
@@ -63,7 +63,7 @@   => Property prop_UnsafeInitializeNew =   property $ \comp sz e ->-    (compute (A.replicate comp sz e) :: Array r ix e) ===+    (compute (A.replicate comp sz e :: Array DL ix e) :: Array r ix e) ===     runST (unsafeFreeze comp =<< initializeNew (Just e) sz)  prop_UnsafeInitialize ::@@ -178,7 +178,7 @@   -> e   -> Property prop_UnsafeLinearSet comp (SzIx sz ix) (NonNegative delta) e =-  compute (A.replicate Seq k e) ===+  compute (A.replicate Seq k e :: Array DL Ix1 e) ===   slice' i k (flatten (arrd :: Array r ix e))   where     i = toLinearIndex sz ix
tests/Test/Massiv/Array/Manifest/VectorSpec.hs view
@@ -43,7 +43,9 @@   -> ArrNE r ix Int   -> Property prop_toFromVector _ _ _ (ArrNE arr) =-  arr === fromVector' (getComp arr) (size arr) (toVector arr :: v Int)+  let comp = getComp arr+      arr' = fromVector' comp (size arr) (toVector arr :: v Int)+  in arr' === arr .&&. (getComp arr' === comp)   toFromVectorSpec :: Spec@@ -51,7 +53,7 @@   it_prop "Unboxed" U   it_prop "Primitive" P   it_prop "Storable" S-  it_prop "BoxedStrict" B+  it_prop "BoxedStrict" BL   where     it_prop name r =       describe name $ do
tests/Test/Massiv/Array/MutableSpec.hs view
@@ -188,6 +188,7 @@ spec = do   specMutableR @B @Int   specMutableR @N @Int+  specMutableR @BL @Int   specUnboxedMutableR @S @Int   specUnboxedMutableR @P @Int   specUnboxedMutableR @U @Int
tests/Test/Massiv/Array/Ops/TransformSpec.hs view
@@ -183,7 +183,7 @@   -> Property prop_ZoomWithGridStrideCompute arr stride defVal =   (computeWithStride @r stride' arr' ===-   compute (A.replicate Seq (Sz (liftIndex (+ 1) $ unSz (size arr))) defVal)) .&&.+   compute (A.replicate @DL Seq (Sz (liftIndex (+ 1) $ unSz (size arr))) defVal)) .&&.   (computeWithStride @r stride' (extract' (pureIndex 1) sz' arr') === compute arr)   where     arr' = compute @r (zoomWithGrid defVal stride arr)
tests/Test/Massiv/Array/StencilSpec.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE MonoLocalBinds #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedLists #-}@@ -21,20 +22,29 @@  singletonStencil :: (Index ix) => (Int -> Int) -> Stencil ix Int Int singletonStencil f =-  makeStencil oneSz zeroIndex $ \ get -> fmap f (get zeroIndex)+  makeStencil oneSz zeroIndex $ \ get -> f (get zeroIndex)  -prop_MapSingletonStencil :: (Load DW ix Int, Manifest U ix Int, Show (Array U ix Int)) =>-                            Proxy ix -> Fun Int Int -> Border Int -> ArrNE U ix Int -> Property+prop_MapSingletonStencil ::+     (Load DW ix Int, Manifest U ix Int, Show (Array U ix Int))+  => Proxy ix+  -> Fun Int Int+  -> Border Int+  -> ArrNE U ix Int+  -> Property prop_MapSingletonStencil _ f b (ArrNE arr) =   computeAs U (mapStencil b (singletonStencil (apply f)) arr) === computeAs U (A.map (apply f) arr)  prop_ApplyZeroStencil ::-     (Load DW ix Int, Manifest U ix Int) => Proxy ix -> Int -> Array U ix Int -> Property+     (Load DW ix Int, Show (Array U ix Int), Manifest U ix Int)+  => Proxy ix+  -> Int+  -> Array U ix Int+  -> Property prop_ApplyZeroStencil _ e arr =-  assertSomeException $ computeAs U (applyStencil noPadding zeroStencil arr)+  computeAs U (applyStencil noPadding zeroStencil arr) === makeArray Seq (size arr) (const e)   where-    zeroStencil = makeStencil zeroSz zeroIndex $ \_get -> pure e+    zeroStencil = makeStencil zeroSz zeroIndex $ const e   prop_MapSingletonStencilWithStride ::@@ -50,11 +60,22 @@  -- Tests out of bounds stencil indexing prop_DangerousStencil ::-     Index ix => Proxy ix -> NonZero Int -> DimIx ix -> SzIx ix -> Property-prop_DangerousStencil _ (NonZero s) (DimIx r) (SzIx sz ix) =-  ix' `deepseq` assertSomeException $ makeStencil sz ix $ \get -> get ix' :: Value Int+     forall ix. Load DW ix Int+  => Proxy ix+  -> DimIx ix+  -> SzIx ix+  -> Property+prop_DangerousStencil _ (DimIx r) (SzIx sz center) =+  assertException validateException arr   where-    ix' = liftIndex (* signum s) (setDim' zeroIndex r (getDim' (unSz sz) r))+    stencil = makeStencil sz center $ \get -> get ix' :: Int+    arr = computeAs P (mapStencil Edge stencil (makeArray Seq sz (const 0) :: Array P ix Int))+    ix' = liftIndex2 (-)+          (setDim' zeroIndex r (getDim' (unSz sz) r))+          (setDim' zeroIndex r (getDim' center r))+    validateException = \case+      IndexOutOfBoundsException _ _ -> pure ()+      exc -> expectationFailure $ "Unexpected exception: " <> show exc   instance Index ix => Show (Stencil ix a b) where@@ -70,12 +91,14 @@   -> Array P ix Int   -> Property prop_MapEqApplyStencil stride (SzTiny sz) b arr =-  forAll (elements (P.zip [0 ..] (toList $ A.map (\(n, _, _) -> n) stencils))) $ \(i, _) ->-    let (_, stencil, g) = stencils ! i-     in computeAs P (unsafeMapStencil b sz zeroIndex (const g) arr) ===-        computeAs P (applyStencil (samePadding stencil b) stencil arr) .&&.-        computeWithStrideAs P stride (unsafeMapStencil b sz zeroIndex (const g) arr) ===-        computeWithStrideAs P stride (applyStencil (samePadding stencil b) stencil arr)+  expectProp $+  A.forM_ stencils $ \(_name, stencil, g) -> do+    -- TODO: Instead of removing deprecated unsafeMapStencil move it here for testing when+    -- removed from massiv.+    computeAs P (unsafeMapStencil b sz zeroIndex (const g) arr) `shouldBe`+      computeAs P (applyStencil (samePadding stencil b) stencil arr)+    computeWithStrideAs P stride (unsafeMapStencil b sz zeroIndex (const g) arr) `shouldBe`+      computeWithStrideAs P stride (applyStencil (samePadding stencil b) stencil arr)   where     stencils = mkCommonStencils sz @@ -143,11 +166,11 @@       in getStencilSize stencil === sz .&&. getStencilCenter stencil === ix  stencilDirection :: Ix2 -> Array U Ix2 Int -> Array U Ix2 Int-stencilDirection ix = computeAs U . mapStencil (Fill def) (makeStencil (Sz 3) (1 :. 1) $ \f -> f ix)+stencilDirection ix = computeAs U . mapStencil (Fill 0) (makeStencil (Sz 3) (1 :. 1) $ \f -> f ix)   stencilCorners :: Ix2 -> Ix2 -> Array U Ix2 Int -> Array U Ix2 Int-stencilCorners ixC ix = computeAs U . mapStencil (Fill def) (makeStencil (Sz 3) ixC $ \f -> f ix)+stencilCorners ixC ix = computeAs U . mapStencil (Fill 0) (makeStencil (Sz 3) ixC $ \f -> f ix)   stencilConvolution :: Spec
tests/Test/Massiv/VectorSpec.hs view
@@ -1,12 +1,10 @@ {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE MonoLocalBinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeOperators #-} module Test.Massiv.VectorSpec (spec) where  import Control.Arrow (first)@@ -37,54 +35,80 @@ sizeException exc = exc `deepseq` True  toUnboxV2 ::-     Unbox e1-  => (VU.Vector e2 -> VU.Vector e3 -> VU.Vector e1)-  -> Array U ix1 e2-  -> Array U ix2 e3-  -> Array U Ix1 e1-toUnboxV2 f v1 v2 = fromUnboxedVector (f (toUnboxedVector v1) (toUnboxedVector v2))+     (Unbox e, Unbox e1, Unbox e2, Index ix1, Index ix2)+  => (VU.Vector e1 -> VU.Vector e2 -> VU.Vector e)+  -> Array U ix1 e1+  -> Array U ix2 e2+  -> Array U Ix1 e+toUnboxV2 f v1 v2 =+  fromUnboxedVector (getComp v1 <> getComp v2) (f (toUnboxedVector v1) (toUnboxedVector v2))  toUnboxV3 ::-     Unbox e1-  => (VU.Vector e -> VU.Vector e2 -> VU.Vector e3 -> VU.Vector e1)-  -> Array U ix e-  -> Array U ix1 e2-  -> Array U ix2 e3-  -> Array U Ix1 e1-toUnboxV3 f v1 = toUnboxV2 (f (toUnboxedVector v1))+     (Unbox e, Unbox e1, Unbox e2, Unbox e3, Index ix1, Index ix2, Index ix3)+  => (VU.Vector e1 -> VU.Vector e2 -> VU.Vector e3 -> VU.Vector e)+  -> Array U ix1 e1+  -> Array U ix2 e2+  -> Array U ix3 e3+  -> Array U Ix1 e+toUnboxV3 f v1 v2 v3 = appComp (getComp v1) (toUnboxV2 (f (toUnboxedVector v1)) v2 v3)  toUnboxV4 ::-     Unbox e1-  => (VU.Vector e2 -> VU.Vector e3 -> VU.Vector e4 -> VU.Vector e5 -> VU.Vector e1)-  -> Array U ix1 e2-  -> Array U ix2 e3-  -> Array U ix3 e4-  -> Array U ix4 e5-  -> Array U Ix1 e1-toUnboxV4 f v1 = toUnboxV3 (f (toUnboxedVector v1))+     (Unbox e, Unbox e1, Unbox e2, Unbox e3, Unbox e4, Index ix1, Index ix2, Index ix3, Index ix4)+  => (VU.Vector e1 -> VU.Vector e2 -> VU.Vector e3 -> VU.Vector e4 -> VU.Vector e)+  -> Array U ix1 e1+  -> Array U ix2 e2+  -> Array U ix3 e3+  -> Array U ix4 e4+  -> Array U Ix1 e+toUnboxV4 f v1 v2 v3 v4 = appComp (getComp v1) (toUnboxV3 (f (toUnboxedVector v1)) v2 v3 v4)  toUnboxV5 ::-     Unbox e1-  => (VU.Vector e2 -> VU.Vector e3 -> VU.Vector e4 -> VU.Vector e5 -> VU.Vector e6 -> VU.Vector e1)-  -> Array U ix1 e2-  -> Array U ix2 e3-  -> Array U ix3 e4-  -> Array U ix4 e5-  -> Array U ix5 e6-  -> Array U Ix1 e1-toUnboxV5 f v1 = toUnboxV4 (f (toUnboxedVector v1))+     ( Unbox e+     , Unbox e1+     , Unbox e2+     , Unbox e3+     , Unbox e4+     , Unbox e5+     , Index ix1+     , Index ix2+     , Index ix3+     , Index ix4+     , Index ix5+     )+  => (VU.Vector e1 -> VU.Vector e2 -> VU.Vector e3 -> VU.Vector e4 -> VU.Vector e5 -> VU.Vector e)+  -> Array U ix1 e1+  -> Array U ix2 e2+  -> Array U ix3 e3+  -> Array U ix4 e4+  -> Array U ix5 e5+  -> Array U Ix1 e+toUnboxV5 f v1 v2 v3 v4 v5 = appComp (getComp v1) (toUnboxV4 (f (toUnboxedVector v1)) v2 v3 v4 v5)  toUnboxV6 ::-     Unbox e1-  => (VU.Vector e2 -> VU.Vector e3 -> VU.Vector e4 -> VU.Vector e5 -> VU.Vector e6 -> VU.Vector e7 -> VU.Vector e1)-  -> Array U ix1 e2-  -> Array U ix2 e3-  -> Array U ix3 e4-  -> Array U ix4 e5-  -> Array U ix5 e6-  -> Array U ix6 e7-  -> Array U Ix1 e1-toUnboxV6 f v1 = toUnboxV5 (f (toUnboxedVector v1))+     ( Unbox e+     , Unbox e1+     , Unbox e2+     , Unbox e3+     , Unbox e4+     , Unbox e5+     , Unbox e6+     , Index ix1+     , Index ix2+     , Index ix3+     , Index ix4+     , Index ix5+     , Index ix6+     )+  => (VU.Vector e1 -> VU.Vector e2 -> VU.Vector e3 -> VU.Vector e4 -> VU.Vector e5 -> VU.Vector e6 -> VU.Vector e)+  -> Array U ix1 e1+  -> Array U ix2 e2+  -> Array U ix3 e3+  -> Array U ix4 e4+  -> Array U ix5 e5+  -> Array U ix6 e6+  -> Array U Ix1 e+toUnboxV6 f v1 v2 v3 v4 v5 v6 =+  appComp (getComp v1) (toUnboxV5 (f (toUnboxedVector v1)) v2 v3 v4 v5 v6)  toPrimV2 :: (Index ix) => (VP.Vector e1 -> VP.Vector e2 -> t) -> Array P ix e1 -> Array P ix e2 -> t toPrimV2 f v1 v2 = f (toPrimitiveVector v1) (toPrimitiveVector v2)@@ -269,11 +293,11 @@   withSeed @(V.Vector DS Word) seed (genWithMapM (`V.smapM` a))   !==! withSeed seed (genWithMapM (`VP.mapM` toPrimitiveVector a)) -prop_smapMaybeM :: SeedVector -> Array B Ix2 Word -> Fun Word (Maybe Word16) -> Property+prop_smapMaybeM :: SeedVector -> Array BL Ix2 Word -> Fun Word (Maybe Word16) -> Property prop_smapMaybeM seed a gm =   withSeed @(V.Vector DS Word16) seed (genWithMapM (\ f -> V.smapMaybeM (fmap g . f) a))-  !==! withSeed seed (genWithMapM-                      (\f -> VP.convert . VB.mapMaybe id <$> VB.mapM (fmap g . f) (toBoxedVector a)))+  !==! withSeed seed+      (genWithMapM (\f -> VP.convert . VB.mapMaybe id <$> VB.mapM (fmap g . f) (toBoxedVector a)))   where g = apply gm  prop_sitraverse :: SeedVector -> Vector P Word -> Property@@ -858,7 +882,8 @@             toPrimitiveVector (compute (V.sempty :: V.Vector DS Word)) `shouldBe` VP.empty           prop "singleton" $ \e -> (V.singleton e :: V.Vector P Word) !==! VP.singleton e           prop "ssingleton" $ \(e :: Word) -> V.ssingleton e !==! VP.singleton e-          prop "replicate" $ \comp k (e :: Word) -> V.replicate comp (Sz k) e !==! VP.replicate k e+          prop "replicate" $ \comp k (e :: Word) ->+            V.replicate @DL comp (Sz k) e !==! VP.replicate k e           prop "sreplicate" $ \k (e :: Word) -> V.sreplicate (Sz k) e !==! VP.replicate k e           prop "generate" $ \comp k (f :: Fun Int Word) ->             V.generate comp (Sz k) (apply f) !==! VP.generate k (apply f)