on master help sign in
Plug in common array test code cleanly in Data.Array.Prim.Pinned
420ee10adithyaov
test/Streamly/Test/Common/Array.hs−15
@@ -31,24 +31,14 @@ import Streamly.Test.Common (listEquals)
31
31
32import qualified Streamly.Prelude as S
32import qualified Streamly.Prelude as S
33
33
34−#if defined(DATA_ARRAY_PRIM_PINNED)
35−import qualified Streamly.Internal.Data.Fold as Fold
36−#endif
37−
38#ifdef TEST_SMALL_ARRAY
34#ifdef TEST_SMALL_ARRAY
39import qualified Streamly.Internal.Data.SmallArray as A
35import qualified Streamly.Internal.Data.SmallArray as A
40type Array = A.SmallArray
36type Array = A.SmallArray
41−#elif defined(DATA_ARRAY_PRIM_PINNED)
42−import qualified Streamly.Internal.Data.Array.Prim.Pinned as A
43−import qualified Streamly.Internal.Data.Array.Prim.Pinned.Type as A
44−type Array = A.Array
45#endif
37#endif
46
38
47moduleName :: String
39moduleName :: String
48#ifdef TEST_SMALL_ARRAY
40#ifdef TEST_SMALL_ARRAY
49moduleName = "Data.SmallArray"
41moduleName = "Data.SmallArray"
50−#elif defined(DATA_ARRAY_PRIM_PINNED)
51−moduleName = "Data.Array.Prim.Pinned"
52#endif
42#endif
53
43
54-- Coverage build takes too long with default number of tests
44-- Coverage build takes too long with default number of tests
@@ -189,10 +179,5 @@ main =
189 prop "read . write === id" testFoldUnfold
179 prop "read . write === id" testFoldUnfold
190 prop "fromList" testFromList
180 prop "fromList" testFromList
191#endif
181#endif
192−
193−#if defined(DATA_ARRAY_PRIM_PINNED)
194− prop "foldMany with writeNUnsafe concats to original"
195− (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))
196−#endif
197 prop "foldMany with writeN concats to original"
182 prop "foldMany with writeN concats to original"
198 (foldManyWith A.writeN)
183 (foldManyWith A.writeN)
test/Streamly/Test/Data/Array/Prim/Pinned.hs+45−2
@@ -8,5 +8,48 @@
8
8
9module Streamly.Test.Data.Array.Prim.Pinned where
9module Streamly.Test.Data.Array.Prim.Pinned where
10
10
11−#define DATA_ARRAY_PRIM_PINNED
11+#include "Streamly/Test/Data/Array/CommonImports.hs"
12+
13+import qualified Streamly.Internal.Data.Fold as Fold
14+import qualified Streamly.Internal.Data.Array.Prim as A
15+import qualified Streamly.Internal.Data.Array.Prim.Type as A
16+type Array = A.Array
17+
18+moduleName :: String
19+moduleName = "Data.Array.Prim.Pinned"
20+
12−#include "Streamly/Test/Common/Array.hs"
21+#include "Streamly/Test/Data/Array/Common.hs"
22+
23+testFromStreamToStream :: Property
24+testFromStreamToStream = genericTestFromTo (const A.fromStream) A.toStream (==)
25+
26+testFoldUnfold :: Property
27+testFoldUnfold = genericTestFromTo (const (S.fold A.write)) (S.unfold A.read) (==)
28+
29+testFromList :: Property
30+testFromList =
31+ forAll (choose (0, maxArrLen)) $ \len ->
32+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
33+ monadicIO $ do
34+ let arr = A.fromList list
35+ xs <- run $ S.toList $ (S.unfold A.read) arr
36+ assert (xs == list)
37+
38+testLengthFromStream :: Property
39+testLengthFromStream = genericTestFrom (const A.fromStream)
40+
41+
42+main :: IO ()
43+main =
44+ hspec $
45+ H.parallel $
46+ modifyMaxSuccess (const maxTestCount) $ do
47+ describe moduleName $ do
48+ commonMain
49+ describe "Construction" $ do
50+ prop "length . fromStream === n" testLengthFromStream
51+ prop "toStream . fromStream === id" testFromStreamToStream
52+ prop "read . write === id" testFoldUnfold
53+ prop "fromList" testFromList
54+ prop "foldMany with writeNUnsafe concats to original"
55+ (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))