on master help sign in
Refactor Ahead ops into a separate test suite.
commit7d4cf315f4673acd3460208ff8ae6e51f2ace7ba authorPranay Sashank <pranaysashank@composewell.com> dateFri 24 Jul 2020, 20:37 (6 years ago) parentcfb9535
4 files changed+116−60
streamly.cabal+8 test/Prop.hs+1−60 test/Streamly/Test/Prelude.hs+22 test/Streamly/Test/Prelude/Ahead.hs+85
streamly.cabal+8
@@ -616,6 +616,14 @@ test-suite Prelude.ZipAsync
616616 other-modules: Streamly.Test.Common
617617 , Streamly.Test.Prelude
618618
619+test-suite Prelude.Ahead
620+ import: test-options, prelude-test-options
621+ type: exitcode-stdio-1.0
622+ main-is: Streamly/Test/Prelude/Ahead.hs
623+ ghc-options: -main-is Streamly.Test.Prelude.Ahead.main
624+ other-modules: Streamly.Test.Common
625+ , Streamly.Test.Prelude
626+
619627test-suite array-test
620628 import: test-options
621629 type: exitcode-stdio-1.0
test/Prop.hs+1−60
@@ -2,7 +2,6 @@
22
33module Main (main) where
44
5−import Control.Applicative (ZipList(..))
65import Control.Concurrent (MVar, takeMVar, putMVar, newEmptyMVar)
76import Control.Exception
87 (BlockedIndefinitelyOnMVar(..), catches,
@@ -212,31 +211,6 @@ concurrentFoldrApplication n =
212211 (return [])
213212 listEquals (==) stream list
214213
215−-------------------------------------------------------------------------------
216−-- Zip operations
217−-------------------------------------------------------------------------------
218−
219−zipAsyncMonadic
220− :: IsStream t
221− => ([Int] -> t IO Int)
222− -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
223− -> (t IO (Int, Int) -> SerialT IO (Int, Int))
224− -> ([Int], [Int])
225− -> Property
226−zipAsyncMonadic constr eq t (a, b) = withMaxSuccess maxTestCount $
227− monadicIO $ do
228− stream1 <-
229− run
230− ((S.toList . t)
231− (S.zipWithM (curry return) (constr a) (constr b)))
232− stream2 <-
233− run
234− ((S.toList . t)
235− (S.zipAsyncWithM (curry return) (constr a) (constr b)))
236− let list = getZipList $ (,) <$> ZipList a <*> ZipList b
237− listEquals eq stream1 list
238− listEquals eq stream2 list
239−
240214main :: IO ()
241215main = hspec
242216 $ H.parallel
@@ -264,11 +238,6 @@ main = hspec
264238 wAsyncOps spec = mapOps spec $ makeOps wAsyncly
265239#ifndef COVERAGE_BUILD
266240 <> [("maxBuffer (-1)", wAsyncly . maxBuffer (-1))]
267−#endif
268− let aheadOps :: IsStream t => ((AheadT IO a -> t IO a) -> Spec) -> Spec
269− aheadOps spec = mapOps spec $ makeOps aheadly
270−#ifndef COVERAGE_BUILD
271− <> [("maxBuffer (-1)", aheadly . maxBuffer (-1))]
272241#endif
273242 let parallelCommonOps :: IsStream t => [(String, ParallelT m a -> t m a)]
274243 parallelCommonOps = []
@@ -286,7 +255,6 @@ main = hspec
286255 mapOps spec $ makeConcurrentAppOps parallely <> parallelCommonOps
287256
288257 describe "Construction" $ do
289− aheadOps $ prop "aheadly replicateM" . constructWithReplicateM
290258 asyncOps $ prop "asyncly replicateM" . constructWithReplicateM
291259 wAsyncOps $ prop "wAsyncly replicateM" . constructWithReplicateM
292260 parallelOps $ prop "parallely replicateM" . constructWithReplicateM
@@ -301,8 +269,6 @@ main = hspec
301269 -- XXX add tests for fromIndices
302270
303271 describe "Functor operations" $ do
304− aheadOps $ functorOps S.fromFoldable "aheadly" (==)
305− aheadOps $ functorOps folded "aheadly folded" (==)
306272 asyncOps $ functorOps S.fromFoldable "asyncly" sortEq
307273 asyncOps $ functorOps folded "asyncly folded" sortEq
308274 wAsyncOps $ functorOps S.fromFoldable "wAsyncly" sortEq
@@ -311,14 +277,11 @@ main = hspec
311277 parallelOps $ functorOps folded "parallely folded" sortEq
312278
313279 describe "Semigroup operations" $ do
314− aheadOps $ semigroupOps "aheadly" (==)
315280 asyncOps $ semigroupOps "asyncly" sortEq
316281 wAsyncOps $ semigroupOps "wAsyncly" sortEq
317282 parallelOps $ semigroupOps "parallely" sortEq
318283
319284 describe "Applicative operations" $ do
320− aheadOps $ prop "aheadly applicative" . applicativeOps S.fromFoldable (==)
321− aheadOps $ prop "aheadly applicative folded" . applicativeOps folded (==)
322285 asyncOps $ prop "asyncly applicative" . applicativeOps S.fromFoldable sortEq
323286 asyncOps $ prop "asyncly applicative folded" . applicativeOps folded sortEq
324287 wAsyncOps $ prop "wAsyncly applicative" . applicativeOps S.fromFoldable sortEq
@@ -330,8 +293,6 @@ main = hspec
330293 -- We test only the serial zip with serial streams and the parallel
331294 -- stream, because the rate setting in these streams can slow down
332295 -- zipAsync.
333− aheadOps $ prop "zip monadic aheadly" . zipAsyncMonadic S.fromFoldable (==)
334− aheadOps $ prop "zip monadic aheadly folded" . zipAsyncMonadic folded (==)
335296 asyncOps $ prop "zip monadic asyncly" . zipAsyncMonadic S.fromFoldable (==)
336297 asyncOps $ prop "zip monadic asyncly folded" . zipAsyncMonadic folded (==)
337298 wAsyncOps $ prop "zip monadic wAsyncly" . zipAsyncMonadic S.fromFoldable (==)
@@ -345,22 +306,18 @@ main = hspec
345306 -- describe "Merge operations" $ do
346307
347308 describe "Monad operations" $ do
348− aheadOps $ prop "aheadly monad then" . monadThen S.fromFoldable (==)
349309 asyncOps $ prop "asyncly monad then" . monadThen S.fromFoldable sortEq
350310 wAsyncOps $ prop "wAsyncly monad then" . monadThen S.fromFoldable sortEq
351311 parallelOps $ prop "parallely monad then" . monadThen S.fromFoldable sortEq
352312
353− aheadOps $ prop "aheadly monad then folded" . monadThen folded (==)
354313 asyncOps $ prop "asyncly monad then folded" . monadThen folded sortEq
355314 wAsyncOps $ prop "wAsyncly monad then folded" . monadThen folded sortEq
356315 parallelOps $ prop "parallely monad then folded" . monadThen folded sortEq
357316
358− aheadOps $ prop "aheadly monad bind" . monadBind S.fromFoldable (==)
359317 asyncOps $ prop "asyncly monad bind" . monadBind S.fromFoldable sortEq
360318 wAsyncOps $ prop "wAsyncly monad bind" . monadBind S.fromFoldable sortEq
361319 parallelOps $ prop "parallely monad bind" . monadBind S.fromFoldable sortEq
362320
363− aheadOps $ prop "aheadly monad bind folded" . monadBind folded (==)
364321 asyncOps $ prop "asyncly monad bind folded" . monadBind folded sortEq
365322 wAsyncOps $ prop "wAsyncly monad bind folded" . monadBind folded sortEq
366323 parallelOps $ prop "parallely monad bind folded" . monadBind folded sortEq
@@ -393,7 +350,7 @@ main = hspec
393350 describe "Concurrent application" $ do
394351-- serialOps $ prop "serial" . concurrentApplication (==)
395352 asyncOps $ prop "async" . concurrentApplication sortEq
396− aheadOps $ prop "ahead" . concurrentApplication (==)
353+-- aheadOps $ prop "ahead" . concurrentApplication (==)
397354 parallelConcurrentAppOps $
398355 prop "parallel" . concurrentApplication sortEq
399356
@@ -403,43 +360,27 @@ main = hspec
403360 concurrentFoldlApplication
404361
405362 describe "Stream transform and combine operations" $ do
406− aheadOps $ transformCombineOpsCommon S.fromFoldable "aheadly" (==)
407363 asyncOps $ transformCombineOpsCommon S.fromFoldable "asyncly" sortEq
408364 wAsyncOps $ transformCombineOpsCommon S.fromFoldable "wAsyncly" sortEq
409365 parallelOps $ transformCombineOpsCommon S.fromFoldable "parallely" sortEq
410366
411− aheadOps $ transformCombineOpsCommon folded "aheadly" (==)
412367 asyncOps $ transformCombineOpsCommon folded "asyncly" sortEq
413368 wAsyncOps $ transformCombineOpsCommon folded "wAsyncly" sortEq
414369 parallelOps $ transformCombineOpsCommon folded "parallely" sortEq
415370
416− aheadOps $ transformCombineOpsOrdered S.fromFoldable "aheadly" (==)
417−
418− aheadOps $ transformCombineOpsOrdered folded "aheadly" (==)
419−
420371 describe "Stream elimination operations" $ do
421− aheadOps $ eliminationOps S.fromFoldable "aheadly"
422372 asyncOps $ eliminationOps S.fromFoldable "asyncly"
423373 wAsyncOps $ eliminationOps S.fromFoldable "wAsyncly"
424374 parallelOps $ eliminationOps S.fromFoldable "parallely"
425375
426− aheadOps $ eliminationOps folded "aheadly folded"
427376 asyncOps $ eliminationOps folded "asyncly folded"
428377 wAsyncOps $ eliminationOps folded "wAsyncly folded"
429378 parallelOps $ eliminationOps folded "parallely folded"
430379
431− aheadOps $ eliminationOpsWord8 S.fromFoldable "aheadly"
432380 asyncOps $ eliminationOpsWord8 S.fromFoldable "asyncly"
433381 wAsyncOps $ eliminationOpsWord8 S.fromFoldable "wAsyncly"
434382 parallelOps $ eliminationOpsWord8 S.fromFoldable "parallely"
435383
436− aheadOps $ eliminationOpsWord8 folded "aheadly folded"
437384 asyncOps $ eliminationOpsWord8 folded "asyncly folded"
438385 wAsyncOps $ eliminationOpsWord8 folded "wAsyncly folded"
439386 parallelOps $ eliminationOpsWord8 folded "parallely folded"
440−
441− -- XXX Add a test where we chain all transformation APIs and make sure that
442− -- the state is being passed through all of them.
443− describe "Stream serial elimination operations" $ do
444− aheadOps $ eliminationOpsOrdered S.fromFoldable "aheadly"
445− aheadOps $ eliminationOpsOrdered folded "aheadly folded"
test/Streamly/Test/Prelude.hs+22
@@ -41,6 +41,7 @@ module Streamly.Test.Prelude
4141 -- * ZipOperations
4242 , zipApplicative
4343 , zipMonadic
44+ , zipAsyncMonadic
4445 -- * Default values
4546 , maxTestCount
4647 , maxStreamLen
@@ -746,6 +747,27 @@ zipMonadic constr eq t (a, b) = withMaxSuccess maxTestCount $
746747 let list = getZipList $ (,) <$> ZipList a <*> ZipList b
747748 listEquals eq stream1 list
748749
750+zipAsyncMonadic
751+ :: IsStream t
752+ => ([Int] -> t IO Int)
753+ -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
754+ -> (t IO (Int, Int) -> SerialT IO (Int, Int))
755+ -> ([Int], [Int])
756+ -> Property
757+zipAsyncMonadic constr eq t (a, b) = withMaxSuccess maxTestCount $
758+ monadicIO $ do
759+ stream1 <-
760+ run
761+ ((S.toList . t)
762+ (S.zipWithM (curry return) (constr a) (constr b)))
763+ stream2 <-
764+ run
765+ ((S.toList . t)
766+ (S.zipAsyncWithM (curry return) (constr a) (constr b)))
767+ let list = getZipList $ (,) <$> ZipList a <*> ZipList b
768+ listEquals eq stream1 list
769+ listEquals eq stream2 list
770+
749771-------------------------------------------------------------------------------
750772-- Helper operations
751773-------------------------------------------------------------------------------
test/Streamly/Test/Prelude/Ahead.hsnew file+85
@@ -0,0 +1,85 @@
1+-- |
2+-- Module : Streamly.Test.Prelude.Ahead
3+-- Copyright : (c) 2020 Composewell Technologies
4+--
5+-- License : BSD-3-Clause
6+-- Maintainer : streamly@composewell.com
7+-- Stability : experimental
8+-- Portability : GHC
9+
10+module Streamly.Test.Prelude.Ahead where
11+
12+#if __GLASGOW_HASKELL__ < 808
13+import Data.Semigroup ((<>))
14+#endif
15+import Test.Hspec.QuickCheck
16+import Test.Hspec as H
17+
18+import Streamly
19+import qualified Streamly.Prelude as S
20+
21+import Streamly.Test.Prelude
22+
23+main :: IO ()
24+main = hspec
25+ $ H.parallel
26+#ifdef COVERAGE_BUILD
27+ $ modifyMaxSuccess (const 10)
28+#endif
29+ $ do
30+ let aheadOps :: IsStream t => ((AheadT IO a -> t IO a) -> Spec) -> Spec
31+ aheadOps spec = mapOps spec $ makeOps aheadly
32+#ifndef COVERAGE_BUILD
33+ <> [("maxBuffer (-1)", aheadly . maxBuffer (-1))]
34+#endif
35+
36+ describe "Construction" $ do
37+ aheadOps $ prop "aheadly replicateM" . constructWithReplicateM
38+
39+ describe "Functor operations" $ do
40+ aheadOps $ functorOps S.fromFoldable "aheadly" (==)
41+ aheadOps $ functorOps folded "aheadly folded" (==)
42+
43+ describe "Semigroup operations" $ do
44+ aheadOps $ semigroupOps "aheadly" (==)
45+
46+ describe "Applicative operations" $ do
47+ aheadOps $ prop "aheadly applicative" . applicativeOps S.fromFoldable (==)
48+ aheadOps $ prop "aheadly applicative folded" . applicativeOps folded (==)
49+
50+ -- XXX add tests for indexed/indexedR
51+ describe "Zip operations" $ do
52+ -- We test only the serial zip with serial streams and the parallel
53+ -- stream, because the rate setting in these streams can slow down
54+ -- zipAsync.
55+ aheadOps $ prop "zip monadic aheadly" . zipAsyncMonadic S.fromFoldable (==)
56+ aheadOps $ prop "zip monadic aheadly folded" . zipAsyncMonadic folded (==)
57+
58+ -- XXX add merge tests like zip tests
59+ -- for mergeBy, we can split a list randomly into two lists and
60+ -- then merge them, it should result in original list
61+ -- describe "Merge operations" $ do
62+
63+ describe "Monad operations" $ do
64+ aheadOps $ prop "aheadly monad then" . monadThen S.fromFoldable (==)
65+ aheadOps $ prop "aheadly monad then folded" . monadThen folded (==)
66+ aheadOps $ prop "aheadly monad bind" . monadBind S.fromFoldable (==)
67+ aheadOps $ prop "aheadly monad bind folded" . monadBind folded (==)
68+
69+ describe "Stream transform and combine operations" $ do
70+ aheadOps $ transformCombineOpsCommon S.fromFoldable "aheadly" (==)
71+ aheadOps $ transformCombineOpsCommon folded "aheadly" (==)
72+ aheadOps $ transformCombineOpsOrdered S.fromFoldable "aheadly" (==)
73+ aheadOps $ transformCombineOpsOrdered folded "aheadly" (==)
74+
75+ describe "Stream elimination operations" $ do
76+ aheadOps $ eliminationOps S.fromFoldable "aheadly"
77+ aheadOps $ eliminationOps folded "aheadly folded"
78+ aheadOps $ eliminationOpsWord8 S.fromFoldable "aheadly"
79+ aheadOps $ eliminationOpsWord8 folded "aheadly folded"
80+
81+ -- XXX Add a test where we chain all transformation APIs and make sure that
82+ -- the state is being passed through all of them.
83+ describe "Stream serial elimination operations" $ do
84+ aheadOps $ eliminationOpsOrdered S.fromFoldable "aheadly"
85+ aheadOps $ eliminationOpsOrdered folded "aheadly folded"