on master help sign in
Refactor ZipSerial ops into a separate test suite.
commit9cec13f69902ec1a1f6907b7b8ee1d9a0e3f0b47 authorPranay Sashank <pranaysashank@composewell.com> dateFri 24 Jul 2020, 20:10 (6 years ago) parent80daa14
4 files changed+94−39
streamly.cabal+8 test/Prop.hs−39 test/Streamly/Test/Prelude.hs+18 test/Streamly/Test/Prelude/ZipSerial.hs+68
streamly.cabal+8
@@ -600,6 +600,14 @@ test-suite Prelude.WSerial
600600 other-modules: Streamly.Test.Common
601601 , Streamly.Test.Prelude
602602
603+test-suite Prelude.ZipSerial
604+ import: test-options, prelude-test-options
605+ type: exitcode-stdio-1.0
606+ main-is: Streamly/Test/Prelude/ZipSerial.hs
607+ ghc-options: -main-is Streamly.Test.Prelude.ZipSerial.main
608+ other-modules: Streamly.Test.Common
609+ , Streamly.Test.Prelude
610+
603611test-suite array-test
604612 import: test-options
605613 type: exitcode-stdio-1.0
test/Prop.hs−39
@@ -216,23 +216,6 @@ concurrentFoldrApplication n =
216216-- Zip operations
217217-------------------------------------------------------------------------------
218218
219−zipApplicative
220− :: (IsStream t, Applicative (t IO))
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−zipApplicative constr eq t (a, b) = withMaxSuccess maxTestCount $
227− monadicIO $ do
228− stream1 <- run ((S.toList . t) ((,) <$> constr a <*> constr b))
229− stream2 <- run ((S.toList . t) (pure (,) <*> constr a <*> constr b))
230− stream3 <- run ((S.toList . t) (S.zipWith (,) (constr a) (constr b)))
231− let list = getZipList $ (,) <$> ZipList a <*> ZipList b
232− listEquals eq stream1 list
233− listEquals eq stream2 list
234− listEquals eq stream3 list
235−
236219zipAsyncMonadic
237220 :: IsStream t
238221 => ([Int] -> t IO Int)
@@ -302,13 +285,6 @@ main = hspec
302285 parallelConcurrentAppOps spec =
303286 mapOps spec $ makeConcurrentAppOps parallely <> parallelCommonOps
304287
305− let zipSerialOps :: IsStream t
306− => ((ZipSerialM IO a -> t IO a) -> Spec) -> Spec
307− zipSerialOps spec = mapOps spec $ makeOps zipSerially
308−#ifndef COVERAGE_BUILD
309− <> [("rate AvgRate 0.00000001", zipSerially . avgRate 0.00000001)]
310− <> [("maxBuffer (-1)", zipSerially . maxBuffer (-1))]
311−#endif
312288 -- Note, the "pure" of applicative Zip streams generates and infinite
313289 -- stream and therefore maxBuffer (-1) must not be used for that case.
314290 let zipAsyncOps :: IsStream t => ((ZipAsyncM IO a -> t IO a) -> Spec) -> Spec
@@ -338,8 +314,6 @@ main = hspec
338314 wAsyncOps $ functorOps folded "wAsyncly folded" sortEq
339315 parallelOps $ functorOps S.fromFoldable "parallely" sortEq
340316 parallelOps $ functorOps folded "parallely folded" sortEq
341− zipSerialOps $ functorOps S.fromFoldable "zipSerially" (==)
342− zipSerialOps $ functorOps folded "zipSerially folded" (==)
343317 zipAsyncOps $ functorOps S.fromFoldable "zipAsyncly" (==)
344318 zipAsyncOps $ functorOps folded "zipAsyncly folded" (==)
345319
@@ -348,7 +322,6 @@ main = hspec
348322 asyncOps $ semigroupOps "asyncly" sortEq
349323 wAsyncOps $ semigroupOps "wAsyncly" sortEq
350324 parallelOps $ semigroupOps "parallely" sortEq
351− zipSerialOps $ semigroupOps "zipSerially" (==)
352325 zipAsyncOps $ semigroupOps "zipAsyncly" (==)
353326
354327 describe "Applicative operations" $ do
@@ -362,8 +335,6 @@ main = hspec
362335
363336 -- XXX add tests for indexed/indexedR
364337 describe "Zip operations" $ do
365− zipSerialOps $ prop "zipSerially applicative" . zipApplicative S.fromFoldable (==)
366− zipSerialOps $ prop "zipSerially applicative folded" . zipApplicative folded (==)
367338 zipAsyncOps $ prop "zipAsyncly applicative" . zipApplicative S.fromFoldable (==)
368339 zipAsyncOps $ prop "zipAsyncly applicative folded" . zipApplicative folded (==)
369340
@@ -447,22 +418,18 @@ main = hspec
447418 asyncOps $ transformCombineOpsCommon S.fromFoldable "asyncly" sortEq
448419 wAsyncOps $ transformCombineOpsCommon S.fromFoldable "wAsyncly" sortEq
449420 parallelOps $ transformCombineOpsCommon S.fromFoldable "parallely" sortEq
450− zipSerialOps $ transformCombineOpsCommon S.fromFoldable "zipSerially" (==)
451421 zipAsyncOps $ transformCombineOpsCommon S.fromFoldable "zipAsyncly" (==)
452422
453423 aheadOps $ transformCombineOpsCommon folded "aheadly" (==)
454424 asyncOps $ transformCombineOpsCommon folded "asyncly" sortEq
455425 wAsyncOps $ transformCombineOpsCommon folded "wAsyncly" sortEq
456426 parallelOps $ transformCombineOpsCommon folded "parallely" sortEq
457− zipSerialOps $ transformCombineOpsCommon folded "zipSerially" (==)
458427 zipAsyncOps $ transformCombineOpsCommon folded "zipAsyncly" (==)
459428
460429 aheadOps $ transformCombineOpsOrdered S.fromFoldable "aheadly" (==)
461− zipSerialOps $ transformCombineOpsOrdered S.fromFoldable "zipSerially" (==)
462430 zipAsyncOps $ transformCombineOpsOrdered S.fromFoldable "zipAsyncly" (==)
463431
464432 aheadOps $ transformCombineOpsOrdered folded "aheadly" (==)
465− zipSerialOps $ transformCombineOpsOrdered folded "zipSerially" (==)
466433 zipAsyncOps $ transformCombineOpsOrdered folded "zipAsyncly" (==)
467434
468435 describe "Stream elimination operations" $ do
@@ -470,37 +437,31 @@ main = hspec
470437 asyncOps $ eliminationOps S.fromFoldable "asyncly"
471438 wAsyncOps $ eliminationOps S.fromFoldable "wAsyncly"
472439 parallelOps $ eliminationOps S.fromFoldable "parallely"
473− zipSerialOps $ eliminationOps S.fromFoldable "zipSerially"
474440 zipAsyncOps $ eliminationOps S.fromFoldable "zipAsyncly"
475441
476442 aheadOps $ eliminationOps folded "aheadly folded"
477443 asyncOps $ eliminationOps folded "asyncly folded"
478444 wAsyncOps $ eliminationOps folded "wAsyncly folded"
479445 parallelOps $ eliminationOps folded "parallely folded"
480− zipSerialOps $ eliminationOps folded "zipSerially folded"
481446 zipAsyncOps $ eliminationOps folded "zipAsyncly folded"
482447
483448 aheadOps $ eliminationOpsWord8 S.fromFoldable "aheadly"
484449 asyncOps $ eliminationOpsWord8 S.fromFoldable "asyncly"
485450 wAsyncOps $ eliminationOpsWord8 S.fromFoldable "wAsyncly"
486451 parallelOps $ eliminationOpsWord8 S.fromFoldable "parallely"
487− zipSerialOps $ eliminationOpsWord8 S.fromFoldable "zipSerially"
488452 zipAsyncOps $ eliminationOpsWord8 S.fromFoldable "zipAsyncly"
489453
490454 aheadOps $ eliminationOpsWord8 folded "aheadly folded"
491455 asyncOps $ eliminationOpsWord8 folded "asyncly folded"
492456 wAsyncOps $ eliminationOpsWord8 folded "wAsyncly folded"
493457 parallelOps $ eliminationOpsWord8 folded "parallely folded"
494− zipSerialOps $ eliminationOpsWord8 folded "zipSerially folded"
495458 zipAsyncOps $ eliminationOpsWord8 folded "zipAsyncly folded"
496459
497460 -- XXX Add a test where we chain all transformation APIs and make sure that
498461 -- the state is being passed through all of them.
499462 describe "Stream serial elimination operations" $ do
500463 aheadOps $ eliminationOpsOrdered S.fromFoldable "aheadly"
501− zipSerialOps $ eliminationOpsOrdered S.fromFoldable "zipSerially"
502464 zipAsyncOps $ eliminationOpsOrdered S.fromFoldable "zipAsyncly"
503465
504466 aheadOps $ eliminationOpsOrdered folded "aheadly folded"
505− zipSerialOps $ eliminationOpsOrdered folded "zipSerially folded"
506467 zipAsyncOps $ eliminationOpsOrdered folded "zipAsyncly folded"
test/Streamly/Test/Prelude.hs+18
@@ -39,6 +39,7 @@ module Streamly.Test.Prelude
3939 , monadBind
4040 , monadThen
4141 -- * ZipOperations
42+ , zipApplicative
4243 , zipMonadic
4344 -- * Default values
4445 , maxTestCount
@@ -712,6 +713,23 @@ monadBind constr eq t (a, b) = withMaxSuccess maxTestCount $
712713-- Zip operations
713714-------------------------------------------------------------------------------
714715
716+zipApplicative
717+ :: (IsStream t, Applicative (t IO))
718+ => ([Int] -> t IO Int)
719+ -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
720+ -> (t IO (Int, Int) -> SerialT IO (Int, Int))
721+ -> ([Int], [Int])
722+ -> Property
723+zipApplicative constr eq t (a, b) = withMaxSuccess maxTestCount $
724+ monadicIO $ do
725+ stream1 <- run ((S.toList . t) ((,) <$> constr a <*> constr b))
726+ stream2 <- run ((S.toList . t) (pure (,) <*> constr a <*> constr b))
727+ stream3 <- run ((S.toList . t) (S.zipWith (,) (constr a) (constr b)))
728+ let list = getZipList $ (,) <$> ZipList a <*> ZipList b
729+ listEquals eq stream1 list
730+ listEquals eq stream2 list
731+ listEquals eq stream3 list
732+
715733zipMonadic
716734 :: IsStream t
717735 => ([Int] -> t IO Int)
test/Streamly/Test/Prelude/ZipSerial.hsnew file+68
@@ -0,0 +1,68 @@
1+-- |
2+-- Module : Streamly.Test.Prelude.ZipSerial
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.ZipSerial 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 zipSerialOps :: IsStream t
31+ => ((ZipSerialM IO a -> t IO a) -> Spec) -> Spec
32+ zipSerialOps spec = mapOps spec $ makeOps zipSerially
33+#ifndef COVERAGE_BUILD
34+ <> [("rate AvgRate 0.00000001", zipSerially . avgRate 0.00000001)]
35+ <> [("maxBuffer (-1)", zipSerially . maxBuffer (-1))]
36+#endif
37+
38+ describe "Functor operations" $ do
39+ zipSerialOps $ functorOps S.fromFoldable "zipSerially" (==)
40+ zipSerialOps $ functorOps folded "zipSerially folded" (==)
41+
42+ describe "Semigroup operations" $ do
43+ zipSerialOps $ semigroupOps "zipSerially" (==)
44+
45+ -- XXX add tests for indexed/indexedR
46+ describe "Zip operations" $ do
47+ zipSerialOps $
48+ prop "zipSerially applicative" . zipApplicative S.fromFoldable (==)
49+ zipSerialOps $
50+ prop "zipSerially applicative folded" . zipApplicative folded (==)
51+
52+ describe "Stream transform and combine operations" $ do
53+ zipSerialOps $ transformCombineOpsCommon S.fromFoldable "zipSerially" (==)
54+ zipSerialOps $ transformCombineOpsCommon folded "zipSerially" (==)
55+ zipSerialOps $ transformCombineOpsOrdered S.fromFoldable "zipSerially" (==)
56+ zipSerialOps $ transformCombineOpsOrdered folded "zipSerially" (==)
57+
58+ describe "Stream elimination operations" $ do
59+ zipSerialOps $ eliminationOps S.fromFoldable "zipSerially"
60+ zipSerialOps $ eliminationOps folded "zipSerially folded"
61+ zipSerialOps $ eliminationOpsWord8 S.fromFoldable "zipSerially"
62+ zipSerialOps $ eliminationOpsWord8 folded "zipSerially folded"
63+
64+ -- XXX Add a test where we chain all transformation APIs and make sure that
65+ -- the state is being passed through all of them.
66+ describe "Stream serial elimination operations" $ do
67+ zipSerialOps $ eliminationOpsOrdered S.fromFoldable "zipSerially"
68+ zipSerialOps $ eliminationOpsOrdered folded "zipSerially folded"