mirror of
https://github.com/composewell/streamly.git
synced 2024-09-11 11:37:22 +03:00
Add tests for unboxed ring array
This commit is contained in:
parent
c361a315e3
commit
aaa279c9b2
@ -98,6 +98,7 @@ extra-source-files:
|
||||
test/Streamly/Test/Data/Array/Prim.hs
|
||||
test/Streamly/Test/Data/Array/Prim/Pinned.hs
|
||||
test/Streamly/Test/Data/Array/Foreign.hs
|
||||
test/Streamly/Test/Data/Ring/Unboxed.hs
|
||||
test/Streamly/Test/Data/Array/Stream/Foreign.hs
|
||||
test/Streamly/Test/Data/Parser/ParserD.hs
|
||||
test/Streamly/Test/FileSystem/Event.hs
|
||||
|
53
test/Streamly/Test/Data/Ring/Unboxed.hs
Normal file
53
test/Streamly/Test/Data/Ring/Unboxed.hs
Normal file
@ -0,0 +1,53 @@
|
||||
-- |
|
||||
-- Module : Streamly.Test.Data.Ring.Unboxed
|
||||
-- Copyright : (c) 2022 Composewell Technologies
|
||||
-- License : BSD-3-Clause
|
||||
-- Maintainer : streamly@composewell.com
|
||||
-- Stability : experimental
|
||||
-- Portability : GHC
|
||||
|
||||
module Streamly.Test.Data.Ring.Unboxed (main) where
|
||||
|
||||
import Control.Monad (void)
|
||||
|
||||
import qualified Streamly.Internal.Data.Array.Foreign.Type as Array
|
||||
import qualified Streamly.Internal.Data.Ring.Foreign as Ring
|
||||
|
||||
import Prelude as P
|
||||
import qualified Data.Foldable as P
|
||||
|
||||
import Test.Hspec as H
|
||||
|
||||
unsafeEqArrayN :: [Int] -> [Int] -> Int -> Int -> Bool -> IO ()
|
||||
unsafeEqArrayN lstArr lstRing startR nelem expected = do
|
||||
let arr = Array.fromList lstArr
|
||||
(ring, rh) <- Ring.new (length lstRing)
|
||||
void $ P.foldlM (Ring.unsafeInsert ring) rh lstRing
|
||||
Ring.unsafeEqArrayN ring (Ring.moveBy startR ring rh) arr nelem
|
||||
`shouldBe` expected
|
||||
|
||||
unsafeEqArray :: [Int] -> [Int] -> Int -> Bool -> IO ()
|
||||
unsafeEqArray lstArr lstRing startR expected = do
|
||||
let arr = Array.fromList lstArr
|
||||
(ring, rh) <- Ring.new (length lstRing)
|
||||
void $ P.foldlM (Ring.unsafeInsert ring) rh lstRing
|
||||
Ring.unsafeEqArray ring (Ring.moveBy startR ring rh) arr
|
||||
`shouldBe` expected
|
||||
|
||||
moduleName :: String
|
||||
moduleName = "Data.Ring.Unboxed"
|
||||
|
||||
main :: IO ()
|
||||
main = hspec $ do
|
||||
describe moduleName $ do
|
||||
describe "Eq" $ do
|
||||
let lstArr = [0..99]
|
||||
lstRing = [50..99] ++ [0..49]
|
||||
it "unsafeEqArrayN True (n < len)"
|
||||
$ unsafeEqArrayN lstArr lstRing 50 75 True
|
||||
it "unsafeEqArrayN True (n > len)"
|
||||
$ unsafeEqArrayN lstArr lstRing 50 200 True
|
||||
it "unsafeEqArrayN False"
|
||||
$ unsafeEqArrayN lstArr lstRing 10 75 False
|
||||
it "unsafeEqArray True" $ unsafeEqArray lstArr lstRing 50 True
|
||||
it "unsafeEqArray False" $ unsafeEqArray lstArr lstRing 20 False
|
@ -241,6 +241,12 @@ test-suite Data.Array.Foreign
|
||||
main-is: Streamly/Test/Data/Array/Foreign.hs
|
||||
ghc-options: -main-is Streamly.Test.Data.Array.Foreign.main
|
||||
|
||||
test-suite Data.Ring.Unboxed
|
||||
import: test-options
|
||||
type: exitcode-stdio-1.0
|
||||
main-is: Streamly/Test/Data/Ring/Unboxed.hs
|
||||
ghc-options: -main-is Streamly.Test.Data.Ring.Unboxed.main
|
||||
|
||||
test-suite Data.Array.Stream.Foreign
|
||||
import: test-options
|
||||
type: exitcode-stdio-1.0
|
||||
|
Loading…
Reference in New Issue
Block a user