Add tests for cons, consM, .:, |:.

This commit is contained in:
pranaysashank 2020-11-19 03:40:06 +05:30 committed by Pranay Sashank
parent 287e9edbf8
commit 57f43838a5
7 changed files with 61 additions and 2 deletions

View File

@ -55,6 +55,10 @@ main = hspec
describe "Construction" $ do
aheadOps $ prop "aheadly replicateM" . constructWithReplicateM
aheadOps $ prop "aheadly cons" . constructWithCons S.cons
aheadOps $ prop "aheadly consM" . constructWithConsM S.consM id
aheadOps $ prop "aheadly (.:)" . constructWithCons (S..:)
aheadOps $ prop "aheadly (|:)" . constructWithConsM (S.|:) id
describe "Functor operations" $ do
aheadOps $ functorOps S.fromFoldable "aheadly" (==)
@ -121,7 +125,7 @@ main = hspec
describe "Stream serial elimination operations" $ do
aheadOps $ eliminationOpsOrdered S.fromFoldable "aheadly"
aheadOps $ eliminationOpsOrdered folded "aheadly folded"
describe "Composed MonadThrow aheadly" $ composeWithMonadThrow S.aheadly
-- Ad-hoc tests

View File

@ -36,6 +36,10 @@ main = hspec
describe "Construction" $ do
asyncOps $ prop "asyncly replicateM" . constructWithReplicateM
asyncOps $ prop "asyncly cons" . constructWithCons S.cons
asyncOps $ prop "asyncly consM" . constructWithConsM S.consM sort
asyncOps $ prop "asyncly (.:)" . constructWithCons (S..:)
asyncOps $ prop "asyncly (|:)" . constructWithConsM (S.|:) sort
describe "Functor operations" $ do
asyncOps $ functorOps S.fromFoldable "asyncly" sortEq

View File

@ -20,6 +20,8 @@ module Streamly.Test.Prelude.Common
, constructWithIterateM
, constructWithFromIndices
, constructWithFromIndicesM
, constructWithCons
, constructWithConsM
-- * Applicative operations
, applicativeOps
, applicativeOps1
@ -251,6 +253,39 @@ constructWithFromIndicesM op len =
streamEffect <- run $ readIORef mvl
listEquals (==) streamEffect list
constructWithCons ::
IsStream t
=> (Int -> t IO Int -> t IO Int)
-> (t IO Int -> SerialT IO Int)
-> Word8
-> Property
constructWithCons cons op len =
withMaxSuccess maxTestCount $
monadicIO $ do
strm <-
run $
S.toList . op . S.take (fromIntegral len) $
foldr cons S.nil (repeat 0)
let list = replicate (fromIntegral len) 0
listEquals (==) strm list
constructWithConsM ::
IsStream t
=> (IO Int -> t IO Int -> t IO Int)
-> ([Int] -> [Int])
-> (t IO Int -> SerialT IO Int)
-> Word8
-> Property
constructWithConsM consM listT op len =
withMaxSuccess maxTestCount $
monadicIO $ do
strm <-
run $
S.toList . op . S.take (fromIntegral len) $
foldr consM S.nil (repeat (return 0))
let list = replicate (fromIntegral len) 0
listEquals (==) (listT strm) list
-------------------------------------------------------------------------------
-- Applicative operations
-------------------------------------------------------------------------------

View File

@ -40,6 +40,10 @@ main = hspec
describe "Construction" $ do
parallelOps $ prop "parallely replicateM" . constructWithReplicateM
parallelOps $ prop "parallely cons" . constructWithCons S.cons
-- parallelOps $ prop "parallely consM" . constructWithConsM S.consM sort
parallelOps $ prop "parallely (.:)" . constructWithCons (S..:)
-- parallelOps $ prop "parallely (|:)" . constructWithConsM (S.|:) sort
describe "Functor operations" $ do
parallelOps $ functorOps S.fromFoldable "parallely" sortEq

View File

@ -470,6 +470,10 @@ main = hspec
serialOps $ prop "serially iterateM" . constructWithIterateM
serialOps $ prop "serially fromIndices" . constructWithFromIndices
serialOps $ prop "serially fromIndicesM" . constructWithFromIndicesM
serialOps $ prop "serially cons" . constructWithCons S.cons
serialOps $ prop "serially consM" . constructWithConsM S.consM id
serialOps $ prop "serially (.:)" . constructWithCons (S..:)
serialOps $ prop "serially (|:)" . constructWithConsM (S.|:) id
describe "From Generators" $ do
prop "unfold" unfold

View File

@ -40,6 +40,10 @@ main = hspec
describe "Construction" $ do
wAsyncOps $ prop "wAsyncly replicateM" . constructWithReplicateM
-- XXX add tests for fromIndices
wAsyncOps $ prop "wAsyncly cons" . constructWithCons S.cons
wAsyncOps $ prop "wAsyncly consM" . constructWithConsM S.consM sort
wAsyncOps $ prop "wAsyncly (.:)" . constructWithCons (S..:)
wAsyncOps $ prop "wAsyncly (|:)" . constructWithConsM (S.|:) sort
describe "Functor operations" $ do
wAsyncOps $ functorOps S.fromFoldable "wAsyncly" sortEq
@ -93,7 +97,7 @@ main = hspec
wAsyncOps $ eliminationOps folded "wAsyncly folded"
wAsyncOps $ eliminationOpsWord8 S.fromFoldable "wAsyncly"
wAsyncOps $ eliminationOpsWord8 folded "wAsyncly folded"
-- describe "WAsync interleaved (<>) ordering check" $
-- interleaveCheck wAsyncly (<>)
-- describe "WAsync interleaved mappend ordering check" $

View File

@ -71,6 +71,10 @@ main = hspec
describe "Construction" $ do
wSerialOps $ prop "wSerially replicateM" . constructWithReplicateM
wSerialOps $ prop "wSerially cons" . constructWithCons S.cons
wSerialOps $ prop "wSerially consM" . constructWithConsM S.consM id
wSerialOps $ prop "wSerially (.:)" . constructWithCons (S..:)
wSerialOps $ prop "wSerially (|:)" . constructWithConsM (S.|:) id
describe "Functor operations" $ do
wSerialOps $ functorOps S.fromFoldable "wSerially" (==)