@@ -31,8 +31,7 @@ import Streamly.Test.Common (listEquals)
32import qualified Streamly.Prelude as S
32import qualified Streamly.Prelude as S
34−#if defined(TEST_ARRAY) ||\
35− defined(DATA_ARRAY_PRIM) ||\
34+#if defined(DATA_ARRAY_PRIM) ||\
36 defined(DATA_ARRAY_PRIM_PINNED)
35 defined(DATA_ARRAY_PRIM_PINNED)
37import qualified Streamly.Internal.Data.Fold as Fold
36import qualified Streamly.Internal.Data.Fold as Fold
@@ -40,14 +39,6 @@ import qualified Streamly.Internal.Data.Fold as Fold
40#ifdef TEST_SMALL_ARRAY
39#ifdef TEST_SMALL_ARRAY
41import qualified Streamly.Internal.Data.SmallArray as A
40import qualified Streamly.Internal.Data.SmallArray as A
42type Array = A.SmallArray
41type Array = A.SmallArray
43−#elif defined(TEST_ARRAY)
44−import Data.Word(Word8)
46−import qualified Streamly.Internal.Data.Array.Foreign as A
47−import qualified Streamly.Internal.Data.Array.Foreign.Type as A
48−import qualified Streamly.Internal.Data.Array.Foreign.Mut.Type as MA
49−import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
51#elif defined(DATA_ARRAY_PRIM_PINNED)
42#elif defined(DATA_ARRAY_PRIM_PINNED)
52import qualified Streamly.Internal.Data.Array.Prim.Pinned as A
43import qualified Streamly.Internal.Data.Array.Prim.Pinned as A
53import qualified Streamly.Internal.Data.Array.Prim.Pinned.Type as A
44import qualified Streamly.Internal.Data.Array.Prim.Pinned.Type as A
@@ -61,8 +52,6 @@ type Array = A.Array
61moduleName :: String
52moduleName :: String
62#ifdef TEST_SMALL_ARRAY
53#ifdef TEST_SMALL_ARRAY
63moduleName = "Data.SmallArray"
54moduleName = "Data.SmallArray"
64−#elif defined(TEST_ARRAY)
65−moduleName = "Data.Array.Foreign"
66#elif defined(DATA_ARRAY_PRIM_PINNED)
55#elif defined(DATA_ARRAY_PRIM_PINNED)
67moduleName = "Data.Array.Prim.Pinned"
56moduleName = "Data.Array.Prim.Pinned"
68#elif defined(DATA_ARRAY_PRIM)
57#elif defined(DATA_ARRAY_PRIM)
@@ -185,55 +174,6 @@ foldManyWith f =
185 $ S.fromList list
174 $ S.fromList list
186 assert (xs == list)
175 assert (xs == list)
190−unsafeWriteIndex :: [Int] -> Int -> Int -> IO Bool
191−unsafeWriteIndex xs i x = do
192− arr <- MA.fromList xs
193− MA.putIndexUnsafe arr i x
194− x1 <- MA.getIndexUnsafe arr i
197−lastN :: Int -> [a] -> [a]
198−lastN n l = drop (length l - n) l
200−testLastN :: Property
202− forAll (choose (0, maxArrLen)) $ \len ->
203− forAll (choose (0, len)) $ \n ->
204− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
208− $ S.fold (A.writeLastN n)
210− assert (xs == lastN n list)
212−testLastN_LN :: Int -> Int -> IO Bool
213−testLastN_LN len n = do
215− l1 <- fmap A.toList $ S.fold (A.writeLastN n) $ S.fromList list
216− let l2 = lastN n list
219−-- Instead of hard coding 10000 here we can have maxStreamLength for operations
220−-- that use stream of arrays.
221−concatArrayW8 :: Property
223− forAll (vectorOf 10000 (arbitrary :: Gen Word8))
225− let w8ArrList = A.fromList . (: []) <$> w8List
226− f2 <- S.toList $ AS.concat $ S.fromList w8ArrList
227− w8List `shouldBe` f2
229−unsafeSlice :: Int -> Int -> [Int] -> Bool
230−unsafeSlice i n list =
231− let lst = take n $ drop i $ list
232− arr = A.toList $ A.getSliceUnsafe i n $ A.fromList list
237main :: IO ()
177main :: IO ()
@@ -257,30 +197,10 @@ main =
257 prop "fromList" testFromList
197 prop "fromList" testFromList
260−#if defined(TEST_ARRAY) ||\
261− defined(DATA_ARRAY_PRIM) ||\
200+#if defined(DATA_ARRAY_PRIM) ||\
262 defined(DATA_ARRAY_PRIM_PINNED)
201 defined(DATA_ARRAY_PRIM_PINNED)
263 prop "foldMany with writeNUnsafe concats to original"
202 prop "foldMany with writeNUnsafe concats to original"
264 (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))
203 (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))
266 prop "foldMany with writeN concats to original"
205 prop "foldMany with writeN concats to original"
267 (foldManyWith A.writeN)
206 (foldManyWith A.writeN)
270− prop "AS.concat . (A.fromList . (:[]) <$>) === id" $ concatArrayW8
271− describe "unsafeSlice" $ do
272− it "partial" $ unsafeSlice 2 4 [1..10]
273− it "none" $ unsafeSlice 10 0 [1..10]
274− it "full" $ unsafeSlice 0 10 [1..10]
275− describe "Mut.unsafeWriteIndex" $ do
276− it "first" (unsafeWriteIndex [1..10] 0 0 `shouldReturn` True)
277− it "middle" (unsafeWriteIndex [1..10] 5 0 `shouldReturn` True)
278− it "last" (unsafeWriteIndex [1..10] 9 0 `shouldReturn` True)
279− describe "Fold" $ do
280− prop "writeLastN : 0 <= n <= len" $ testLastN
281− describe "writeLastN boundary conditions" $ do
282− it "writeLastN -1" (testLastN_LN 10 (-1) `shouldReturn` True)
283− it "writeLastN 0" (testLastN_LN 10 0 `shouldReturn` True)
284− it "writeLastN length" (testLastN_LN 10 10 `shouldReturn` True)
285− it "writeLastN (length + 1)" (testLastN_LN 10 11 `shouldReturn` True)