on master help sign in
Add tests for cons, consM, .:, |:.
57f4383pranaysashank
test/Streamly/Test/Prelude/Ahead.hs+5−1
@@ -55,6 +55,10 @@ main = hspec
55
55
56 describe "Construction" $ do
56 describe "Construction" $ do
57 aheadOps $ prop "aheadly replicateM" . constructWithReplicateM
57 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
58
62
59 describe "Functor operations" $ do
63 describe "Functor operations" $ do
60 aheadOps $ functorOps S.fromFoldable "aheadly" (==)
64 aheadOps $ functorOps S.fromFoldable "aheadly" (==)
@@ -121,7 +125,7 @@ main = hspec
121 describe "Stream serial elimination operations" $ do
125 describe "Stream serial elimination operations" $ do
122 aheadOps $ eliminationOpsOrdered S.fromFoldable "aheadly"
126 aheadOps $ eliminationOpsOrdered S.fromFoldable "aheadly"
123 aheadOps $ eliminationOpsOrdered folded "aheadly folded"
127 aheadOps $ eliminationOpsOrdered folded "aheadly folded"
124−
128+
125 describe "Composed MonadThrow aheadly" $ composeWithMonadThrow S.aheadly
129 describe "Composed MonadThrow aheadly" $ composeWithMonadThrow S.aheadly
126
130
127 -- Ad-hoc tests
131 -- Ad-hoc tests
test/Streamly/Test/Prelude/Async.hs+4
@@ -36,6 +36,10 @@ main = hspec
36
36
37 describe "Construction" $ do
37 describe "Construction" $ do
38 asyncOps $ prop "asyncly replicateM" . constructWithReplicateM
38 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
39
43
40 describe "Functor operations" $ do
44 describe "Functor operations" $ do
41 asyncOps $ functorOps S.fromFoldable "asyncly" sortEq
45 asyncOps $ functorOps S.fromFoldable "asyncly" sortEq
test/Streamly/Test/Prelude/Common.hs+35
@@ -20,6 +20,8 @@ module Streamly.Test.Prelude.Common
20 , constructWithIterateM
20 , constructWithIterateM
21 , constructWithFromIndices
21 , constructWithFromIndices
22 , constructWithFromIndicesM
22 , constructWithFromIndicesM
23+ , constructWithCons
24+ , constructWithConsM
23 -- * Applicative operations
25 -- * Applicative operations
24 , applicativeOps
26 , applicativeOps
25 , applicativeOps1
27 , applicativeOps1
@@ -251,6 +253,39 @@ constructWithFromIndicesM op len =
251 streamEffect <- run $ readIORef mvl
253 streamEffect <- run $ readIORef mvl
252 listEquals (==) streamEffect list
254 listEquals (==) streamEffect list
253
255
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+
254-------------------------------------------------------------------------------
289-------------------------------------------------------------------------------
255-- Applicative operations
290-- Applicative operations
256-------------------------------------------------------------------------------
291-------------------------------------------------------------------------------
test/Streamly/Test/Prelude/Parallel.hs+4
@@ -40,6 +40,10 @@ main = hspec
40
40
41 describe "Construction" $ do
41 describe "Construction" $ do
42 parallelOps $ prop "parallely replicateM" . constructWithReplicateM
42 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
43
47
44 describe "Functor operations" $ do
48 describe "Functor operations" $ do
45 parallelOps $ functorOps S.fromFoldable "parallely" sortEq
49 parallelOps $ functorOps S.fromFoldable "parallely" sortEq
test/Streamly/Test/Prelude/Serial.hs+4
@@ -470,6 +470,10 @@ main = hspec
470 serialOps $ prop "serially iterateM" . constructWithIterateM
470 serialOps $ prop "serially iterateM" . constructWithIterateM
471 serialOps $ prop "serially fromIndices" . constructWithFromIndices
471 serialOps $ prop "serially fromIndices" . constructWithFromIndices
472 serialOps $ prop "serially fromIndicesM" . constructWithFromIndicesM
472 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
473
477
474 describe "From Generators" $ do
478 describe "From Generators" $ do
475 prop "unfold" unfold
479 prop "unfold" unfold
test/Streamly/Test/Prelude/WAsync.hs+5−1
@@ -40,6 +40,10 @@ main = hspec
40 describe "Construction" $ do
40 describe "Construction" $ do
41 wAsyncOps $ prop "wAsyncly replicateM" . constructWithReplicateM
41 wAsyncOps $ prop "wAsyncly replicateM" . constructWithReplicateM
42 -- XXX add tests for fromIndices
42 -- 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
43
47
44 describe "Functor operations" $ do
48 describe "Functor operations" $ do
45 wAsyncOps $ functorOps S.fromFoldable "wAsyncly" sortEq
49 wAsyncOps $ functorOps S.fromFoldable "wAsyncly" sortEq
@@ -93,7 +97,7 @@ main = hspec
93 wAsyncOps $ eliminationOps folded "wAsyncly folded"
97 wAsyncOps $ eliminationOps folded "wAsyncly folded"
94 wAsyncOps $ eliminationOpsWord8 S.fromFoldable "wAsyncly"
98 wAsyncOps $ eliminationOpsWord8 S.fromFoldable "wAsyncly"
95 wAsyncOps $ eliminationOpsWord8 folded "wAsyncly folded"
99 wAsyncOps $ eliminationOpsWord8 folded "wAsyncly folded"
96−
100+
97 -- describe "WAsync interleaved (<>) ordering check" $
101 -- describe "WAsync interleaved (<>) ordering check" $
98 -- interleaveCheck wAsyncly (<>)
102 -- interleaveCheck wAsyncly (<>)
99 -- describe "WAsync interleaved mappend ordering check" $
103 -- describe "WAsync interleaved mappend ordering check" $
test/Streamly/Test/Prelude/WSerial.hs+4
@@ -71,6 +71,10 @@ main = hspec
71
71
72 describe "Construction" $ do
72 describe "Construction" $ do
73 wSerialOps $ prop "wSerially replicateM" . constructWithReplicateM
73 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
74
78
75 describe "Functor operations" $ do
79 describe "Functor operations" $ do
76 wSerialOps $ functorOps S.fromFoldable "wSerially" (==)
80 wSerialOps $ functorOps S.fromFoldable "wSerially" (==)