on master help sign in
Add a simple test for ArrayStream.concat
6bc64a4Adithya Kumar
test/Streamly/Test/Common/Array.hs+15
@@ -26,9 +26,12 @@ import qualified Streamly.Prelude as S
26import qualified Streamly.Internal.Data.SmallArray as A
26import qualified Streamly.Internal.Data.SmallArray as A
27type Array = A.SmallArray
27type Array = A.SmallArray
28#elif defined(TEST_ARRAY)
28#elif defined(TEST_ARRAY)
29+import Data.Word(Word8)
30+
29import qualified Streamly.Internal.Data.Array.Storable.Foreign as A
31import qualified Streamly.Internal.Data.Array.Storable.Foreign as A
30import qualified Streamly.Internal.Data.Array.Storable.Foreign.Types as A
32import qualified Streamly.Internal.Data.Array.Storable.Foreign.Types as A
31import qualified Streamly.Internal.Data.Stream.IsStream as IP
33import qualified Streamly.Internal.Data.Stream.IsStream as IP
34+import qualified Streamly.Internal.Memory.ArrayStream as AS
32type Array = A.Array
35type Array = A.Array
33#elif defined(DATA_ARRAY_PRIM_PINNED)
36#elif defined(DATA_ARRAY_PRIM_PINNED)
34import qualified Streamly.Internal.Data.Array.Prim.Pinned as A
37import qualified Streamly.Internal.Data.Array.Prim.Pinned as A
@@ -173,6 +176,17 @@ testLastN_LN len n = do
173 l1 <- fmap A.toList $ S.fold (A.lastN n) $ S.fromList list
176 l1 <- fmap A.toList $ S.fold (A.lastN n) $ S.fromList list
174 let l2 = lastN n list
177 let l2 = lastN n list
175 return $ l1 == l2
178 return $ l1 == l2
179+
180+-- Instead of hard coding 10000 here we can have maxStreamLength for operations
181+-- that use stream of arrays.
182+concatArrayW8 :: Property
183+concatArrayW8 =
184+ forAll (vectorOf 10000 (arbitrary :: Gen Word8))
185+ $ \w8List -> do
186+ let w8ArrList = A.fromList . (: []) <$> w8List
187+ f2 <- S.toList $ AS.concat $ S.fromList w8ArrList
188+ w8List `shouldBe` f2
189+
176#endif
190#endif
177
191
178main :: IO ()
192main :: IO ()
@@ -201,6 +215,7 @@ main =
201#endif
215#endif
202
216
203#ifdef TEST_ARRAY
217#ifdef TEST_ARRAY
218+ prop "AS.concat . (A.fromList . (:[]) <$>) === id" $ concatArrayW8
204 describe "Fold" $ do
219 describe "Fold" $ do
205 prop "lastN : 0 <= n <= len" $ testLastN
220 prop "lastN : 0 <= n <= len" $ testLastN
206 describe "lastN boundary conditions" $ do
221 describe "lastN boundary conditions" $ do