on master help sign in
Plug in common array test code cleanly in Data.Array.Prim
commit561ec1edf1c814b872d00505752922bba17c3a7c authoradithyaov <adithya@composewell.com> dateSat 27 Nov 2021, 02:41 (5 years ago) parenta2f7e57
2 files changed+47−12
test/Streamly/Test/Common/Array.hs+2−10 test/Streamly/Test/Data/Array/Prim.hs+45−2
test/Streamly/Test/Common/Array.hs+2−10
@@ -31,8 +31,7 @@ import Streamly.Test.Common (listEquals)
3131
3232import qualified Streamly.Prelude as S
3333
34−#if defined(DATA_ARRAY_PRIM) ||\
35− defined(DATA_ARRAY_PRIM_PINNED)
34+#if defined(DATA_ARRAY_PRIM_PINNED)
3635import qualified Streamly.Internal.Data.Fold as Fold
3736#endif
3837
@@ -43,10 +42,6 @@ type Array = A.SmallArray
4342import qualified Streamly.Internal.Data.Array.Prim.Pinned as A
4443import qualified Streamly.Internal.Data.Array.Prim.Pinned.Type as A
4544type 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
5045#endif
5146
5247moduleName :: String
@@ -54,8 +49,6 @@ moduleName :: String
5449moduleName = "Data.SmallArray"
5550#elif defined(DATA_ARRAY_PRIM_PINNED)
5651moduleName = "Data.Array.Prim.Pinned"
57−#elif defined(DATA_ARRAY_PRIM)
58−moduleName = "Data.Array.Prim"
5952#endif
6053
6154-- Coverage build takes too long with default number of tests
@@ -197,8 +190,7 @@ main =
197190 prop "fromList" testFromList
198191#endif
199192
200−#if defined(DATA_ARRAY_PRIM) ||\
201− defined(DATA_ARRAY_PRIM_PINNED)
193+#if defined(DATA_ARRAY_PRIM_PINNED)
202194 prop "foldMany with writeNUnsafe concats to original"
203195 (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))
204196#endif
test/Streamly/Test/Data/Array/Prim.hs+45−2
@@ -8,5 +8,48 @@
88
99module Streamly.Test.Data.Array.Prim where
1010
11−#define DATA_ARRAY_PRIM
12−#include "Streamly/Test/Common/Array.hs"
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+
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)))