on master help sign in
Add a test case for Mut.unsafeWriteIndex
commitd3cc553ef9c205b6c898755186858dfd4af657c9 authorAdithya Kumar <adithya@composewell.com> dateMon 5 Apr 2021, 02:39 (6 years ago) parent7aa0e0d
1 file changed+12
test/Streamly/Test/Common/Array.hs+12
test/Streamly/Test/Common/Array.hs+12
@@ -30,6 +30,7 @@ import Data.Word(Word8)
3030
3131import qualified Streamly.Internal.Data.Array.Foreign as A
3232import qualified Streamly.Internal.Data.Array.Foreign.Type as A
33+import qualified Streamly.Internal.Data.Array.Foreign.Mut.Type as MA
3334import qualified Streamly.Internal.Data.Stream.IsStream as IP
3435import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
3536type Array = A.Array
@@ -187,6 +188,13 @@ testArraysOf =
187188
188189#ifdef TEST_ARRAY
189190
191+unsafeWriteIndex :: [Int] -> Int -> Int -> IO Bool
192+unsafeWriteIndex xs i x = do
193+ let arr = MA.fromList xs
194+ arr1 <- MA.unsafeWriteIndex arr i x
195+ x1 <- MA.unsafeIndexIO arr1 i
196+ return $ x1 == x
197+
190198lastN :: Int -> [a] -> [a]
191199lastN n l = drop (length l - n) l
192200
@@ -262,6 +270,10 @@ main =
262270 it "partial" $ unsafeSlice 2 4 [1..10]
263271 it "none" $ unsafeSlice 10 0 [1..10]
264272 it "full" $ unsafeSlice 0 10 [1..10]
273+ describe "Mut.unsafeWriteIndex" $ do
274+ it "first" (unsafeWriteIndex [1..10] 0 0 `shouldReturn` True)
275+ it "middle" (unsafeWriteIndex [1..10] 5 0 `shouldReturn` True)
276+ it "last" (unsafeWriteIndex [1..10] 9 0 `shouldReturn` True)
265277 describe "Fold" $ do
266278 prop "lastN : 0 <= n <= len" $ testLastN
267279 describe "lastN boundary conditions" $ do