on master help sign in
Plug in common array test code cleanly in Data.Array.Prim
561ec1eadithyaov
test/Streamly/Test/Common/Array.hs+2−10
@@ -31,8 +31,7 @@ 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) ||\
35− defined(DATA_ARRAY_PRIM_PINNED)
34+#if defined(DATA_ARRAY_PRIM_PINNED)
36import qualified Streamly.Internal.Data.Fold as Fold
35import qualified Streamly.Internal.Data.Fold as Fold
37#endif
36#endif
38
37
@@ -43,10 +42,6 @@ type Array = A.SmallArray
43import qualified Streamly.Internal.Data.Array.Prim.Pinned as A
42import qualified Streamly.Internal.Data.Array.Prim.Pinned as A
44import qualified Streamly.Internal.Data.Array.Prim.Pinned.Type as A
43import qualified Streamly.Internal.Data.Array.Prim.Pinned.Type as A
45type Array = A.Array
44type Array = A.Array
46−#elif defined(DATA_ARRAY_PRIM)
47−import qualified Streamly.Internal.Data.Array.Prim as A
48−import qualified Streamly.Internal.Data.Array.Prim.Type as A
49−type Array = A.Array
50#endif
45#endif
51
46
52moduleName :: String
47moduleName :: String
@@ -54,8 +49,6 @@ moduleName :: String
54moduleName = "Data.SmallArray"
49moduleName = "Data.SmallArray"
55#elif defined(DATA_ARRAY_PRIM_PINNED)
50#elif defined(DATA_ARRAY_PRIM_PINNED)
56moduleName = "Data.Array.Prim.Pinned"
51moduleName = "Data.Array.Prim.Pinned"
57−#elif defined(DATA_ARRAY_PRIM)
58−moduleName = "Data.Array.Prim"
59#endif
52#endif
60
53
61-- Coverage build takes too long with default number of tests
54-- Coverage build takes too long with default number of tests
@@ -197,8 +190,7 @@ main =
197 prop "fromList" testFromList
190 prop "fromList" testFromList
198#endif
191#endif
199
192
200−#if defined(DATA_ARRAY_PRIM) ||\
201− defined(DATA_ARRAY_PRIM_PINNED)
193+#if defined(DATA_ARRAY_PRIM_PINNED)
202 prop "foldMany with writeNUnsafe concats to original"
194 prop "foldMany with writeNUnsafe concats to original"
203 (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))
195 (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))
204#endif
196#endif
test/Streamly/Test/Data/Array/Prim.hs+45−2
@@ -8,5 +8,48 @@
8
8
9module Streamly.Test.Data.Array.Prim where
9module Streamly.Test.Data.Array.Prim where
10
10
11−#define DATA_ARRAY_PRIM
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"
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)))