on master help sign in
Plug in common array test code cleanly in Data.Array.Prim.Pinned
commit420ee10869054b050dc47e6e6e79118157020eae authoradithyaov <adithya@composewell.com> dateSat 27 Nov 2021, 02:47 (5 years ago) parent561ec1e
2 files changed+45−17
test/Streamly/Test/Common/Array.hs−15 test/Streamly/Test/Data/Array/Prim/Pinned.hs+45−2
test/Streamly/Test/Common/Array.hs−15
@@ -31,24 +31,14 @@ import Streamly.Test.Common (listEquals)
3131
3232import qualified Streamly.Prelude as S
3333
34−#if defined(DATA_ARRAY_PRIM_PINNED)
35−import qualified Streamly.Internal.Data.Fold as Fold
36−#endif
37−
3834#ifdef TEST_SMALL_ARRAY
3935import qualified Streamly.Internal.Data.SmallArray as A
4036type 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
4537#endif
4638
4739moduleName :: String
4840#ifdef TEST_SMALL_ARRAY
4941moduleName = "Data.SmallArray"
50−#elif defined(DATA_ARRAY_PRIM_PINNED)
51−moduleName = "Data.Array.Prim.Pinned"
5242#endif
5343
5444-- Coverage build takes too long with default number of tests
@@ -189,10 +179,5 @@ main =
189179 prop "read . write === id" testFoldUnfold
190180 prop "fromList" testFromList
191181#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
197182 prop "foldMany with writeN concats to original"
198183 (foldManyWith A.writeN)
test/Streamly/Test/Data/Array/Prim/Pinned.hs+45−2
@@ -8,5 +8,48 @@
88
99module Streamly.Test.Data.Array.Prim.Pinned where
1010
11−#define DATA_ARRAY_PRIM_PINNED
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.Pinned"
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)))