on master help sign in
Add tests for cons, consM, .:, |:.
commit57f43838a5c7c55c9c2c95bf36701f54309c4bb3 authorpranaysashank <pranaysashank@composewell.com> dateThu 19 Nov 2020, 03:40 (6 years ago) parent287e9ed
7 files changed+61−2
test/Streamly/Test/Prelude/Ahead.hs+5−1 test/Streamly/Test/Prelude/Async.hs+4 test/Streamly/Test/Prelude/Common.hs+35 test/Streamly/Test/Prelude/Parallel.hs+4 test/Streamly/Test/Prelude/Serial.hs+4 test/Streamly/Test/Prelude/WAsync.hs+5−1 test/Streamly/Test/Prelude/WSerial.hs+4
test/Streamly/Test/Prelude/Ahead.hs+5−1
@@ -55,6 +55,10 @@ main = hspec
5555
5656 describe "Construction" $ do
5757 aheadOps $ prop "aheadly replicateM" . constructWithReplicateM
58+ aheadOps $ prop "aheadly cons" . constructWithCons S.cons
59+ aheadOps $ prop "aheadly consM" . constructWithConsM S.consM id
60+ aheadOps $ prop "aheadly (.:)" . constructWithCons (S..:)
61+ aheadOps $ prop "aheadly (|:)" . constructWithConsM (S.|:) id
5862
5963 describe "Functor operations" $ do
6064 aheadOps $ functorOps S.fromFoldable "aheadly" (==)
@@ -121,7 +125,7 @@ main = hspec
121125 describe "Stream serial elimination operations" $ do
122126 aheadOps $ eliminationOpsOrdered S.fromFoldable "aheadly"
123127 aheadOps $ eliminationOpsOrdered folded "aheadly folded"
124−
128+
125129 describe "Composed MonadThrow aheadly" $ composeWithMonadThrow S.aheadly
126130
127131 -- Ad-hoc tests
test/Streamly/Test/Prelude/Async.hs+4
@@ -36,6 +36,10 @@ main = hspec
3636
3737 describe "Construction" $ do
3838 asyncOps $ prop "asyncly replicateM" . constructWithReplicateM
39+ asyncOps $ prop "asyncly cons" . constructWithCons S.cons
40+ asyncOps $ prop "asyncly consM" . constructWithConsM S.consM sort
41+ asyncOps $ prop "asyncly (.:)" . constructWithCons (S..:)
42+ asyncOps $ prop "asyncly (|:)" . constructWithConsM (S.|:) sort
3943
4044 describe "Functor operations" $ do
4145 asyncOps $ functorOps S.fromFoldable "asyncly" sortEq
test/Streamly/Test/Prelude/Common.hs+35
@@ -20,6 +20,8 @@ module Streamly.Test.Prelude.Common
2020 , constructWithIterateM
2121 , constructWithFromIndices
2222 , constructWithFromIndicesM
23+ , constructWithCons
24+ , constructWithConsM
2325 -- * Applicative operations
2426 , applicativeOps
2527 , applicativeOps1
@@ -251,6 +253,39 @@ constructWithFromIndicesM op len =
251253 streamEffect <- run $ readIORef mvl
252254 listEquals (==) streamEffect list
253255
256+constructWithCons ::
257+ IsStream t
258+ => (Int -> t IO Int -> t IO Int)
259+ -> (t IO Int -> SerialT IO Int)
260+ -> Word8
261+ -> Property
262+constructWithCons cons op len =
263+ withMaxSuccess maxTestCount $
264+ monadicIO $ do
265+ strm <-
266+ run $
267+ S.toList . op . S.take (fromIntegral len) $
268+ foldr cons S.nil (repeat 0)
269+ let list = replicate (fromIntegral len) 0
270+ listEquals (==) strm list
271+
272+constructWithConsM ::
273+ IsStream t
274+ => (IO Int -> t IO Int -> t IO Int)
275+ -> ([Int] -> [Int])
276+ -> (t IO Int -> SerialT IO Int)
277+ -> Word8
278+ -> Property
279+constructWithConsM consM listT op len =
280+ withMaxSuccess maxTestCount $
281+ monadicIO $ do
282+ strm <-
283+ run $
284+ S.toList . op . S.take (fromIntegral len) $
285+ foldr consM S.nil (repeat (return 0))
286+ let list = replicate (fromIntegral len) 0
287+ listEquals (==) (listT strm) list
288+
254289-------------------------------------------------------------------------------
255290-- Applicative operations
256291-------------------------------------------------------------------------------
test/Streamly/Test/Prelude/Parallel.hs+4
@@ -40,6 +40,10 @@ main = hspec
4040
4141 describe "Construction" $ do
4242 parallelOps $ prop "parallely replicateM" . constructWithReplicateM
43+ parallelOps $ prop "parallely cons" . constructWithCons S.cons
44+-- parallelOps $ prop "parallely consM" . constructWithConsM S.consM sort
45+ parallelOps $ prop "parallely (.:)" . constructWithCons (S..:)
46+-- parallelOps $ prop "parallely (|:)" . constructWithConsM (S.|:) sort
4347
4448 describe "Functor operations" $ do
4549 parallelOps $ functorOps S.fromFoldable "parallely" sortEq
test/Streamly/Test/Prelude/Serial.hs+4
@@ -470,6 +470,10 @@ main = hspec
470470 serialOps $ prop "serially iterateM" . constructWithIterateM
471471 serialOps $ prop "serially fromIndices" . constructWithFromIndices
472472 serialOps $ prop "serially fromIndicesM" . constructWithFromIndicesM
473+ serialOps $ prop "serially cons" . constructWithCons S.cons
474+ serialOps $ prop "serially consM" . constructWithConsM S.consM id
475+ serialOps $ prop "serially (.:)" . constructWithCons (S..:)
476+ serialOps $ prop "serially (|:)" . constructWithConsM (S.|:) id
473477
474478 describe "From Generators" $ do
475479 prop "unfold" unfold
test/Streamly/Test/Prelude/WAsync.hs+5−1
@@ -40,6 +40,10 @@ main = hspec
4040 describe "Construction" $ do
4141 wAsyncOps $ prop "wAsyncly replicateM" . constructWithReplicateM
4242 -- XXX add tests for fromIndices
43+ wAsyncOps $ prop "wAsyncly cons" . constructWithCons S.cons
44+ wAsyncOps $ prop "wAsyncly consM" . constructWithConsM S.consM sort
45+ wAsyncOps $ prop "wAsyncly (.:)" . constructWithCons (S..:)
46+ wAsyncOps $ prop "wAsyncly (|:)" . constructWithConsM (S.|:) sort
4347
4448 describe "Functor operations" $ do
4549 wAsyncOps $ functorOps S.fromFoldable "wAsyncly" sortEq
@@ -93,7 +97,7 @@ main = hspec
9397 wAsyncOps $ eliminationOps folded "wAsyncly folded"
9498 wAsyncOps $ eliminationOpsWord8 S.fromFoldable "wAsyncly"
9599 wAsyncOps $ eliminationOpsWord8 folded "wAsyncly folded"
96−
100+
97101 -- describe "WAsync interleaved (<>) ordering check" $
98102 -- interleaveCheck wAsyncly (<>)
99103 -- describe "WAsync interleaved mappend ordering check" $
test/Streamly/Test/Prelude/WSerial.hs+4
@@ -71,6 +71,10 @@ main = hspec
7171
7272 describe "Construction" $ do
7373 wSerialOps $ prop "wSerially replicateM" . constructWithReplicateM
74+ wSerialOps $ prop "wSerially cons" . constructWithCons S.cons
75+ wSerialOps $ prop "wSerially consM" . constructWithConsM S.consM id
76+ wSerialOps $ prop "wSerially (.:)" . constructWithCons (S..:)
77+ wSerialOps $ prop "wSerially (|:)" . constructWithConsM (S.|:) id
7478
7579 describe "Functor operations" $ do
7680 wSerialOps $ functorOps S.fromFoldable "wSerially" (==)