Add tests for unboxed ring array

This commit is contained in:
Adithya Kumar 2022-07-11 11:39:28 +05:30
parent c361a315e3
commit aaa279c9b2
3 changed files with 60 additions and 0 deletions

View File

@ -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

View 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

View File

@ -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