on master help sign in
Remove nested-loops test suite.

- Add it to the Prelude test suite.

commit16db9cf7e04ef56f1f5b9b019ffb5e5369a803f6 authorpranaysashank <pranaysashank@composewell.com> dateWed 14 Oct 2020, 11:34 (6 years ago) parent2f3d30c
3 files changed+25−39
streamly.cabal+1−11 test/Streamly/Test/Prelude.hs+24−1 test/nested-loops.hs−27
streamly.cabal+1−11
@@ -583,6 +583,7 @@ test-suite Prelude
583583 , containers >= 0.5 && < 0.7
584584 , transformers >= 0.4 && < 0.6
585585 , mtl >= 2.2 && < 3
586+ , random >= 1.0.0 && < 2
586587
587588test-suite Prelude.Serial
588589 import: test-options, prelude-test-options
@@ -816,17 +817,6 @@ test-suite string-test
816817 , hspec >= 2.0 && < 3
817818 default-language: Haskell2010
818819
819−test-suite nested-loops
820− import: test-options
821− type: exitcode-stdio-1.0
822− default-language: Haskell2010
823− main-is: nested-loops.hs
824− hs-source-dirs: test
825− build-Depends:
826− streamly
827− , base >= 4.9 && < 5
828− , random >= 1.0.0 && < 2
829−
830820test-suite parallel-loops
831821 import: test-options
832822 type: exitcode-stdio-1.0
test/Streamly/Test/Prelude.hs+24−1
@@ -9,7 +9,7 @@
99
1010module Streamly.Test.Prelude (main) where
1111
12−import Control.Concurrent (threadDelay)
12+import Control.Concurrent (myThreadId, threadDelay)
1313import Control.Exception (Exception, try)
1414import Control.Monad (when)
1515import Control.Monad.Catch (throwM)
@@ -23,6 +23,8 @@ import Data.Maybe (fromJust, isJust)
2323#if !(MIN_VERSION_base(4,11,0))
2424import Data.Semigroup (Semigroup(..))
2525#endif
26+import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
27+import System.Random (randomIO)
2628import Test.Hspec as H
2729import Test.Hspec.QuickCheck (prop)
2830import Test.QuickCheck (Property, choose)
@@ -227,6 +229,26 @@ mixedOpsAheadly =
227229 return (x1 + y1 + z1)
228230 return (x + y + z)
229231
232+nestedLoops :: IO ()
233+nestedLoops = S.drain $ do
234+ S.yieldM $ hSetBuffering stdout LineBuffering
235+ x <- loop "A " 2
236+ y <- loop "B " 2
237+ S.yieldM $ myThreadId >>= putStr . show
238+ >> putStr " "
239+ >> print (x, y)
240+
241+ where
242+
243+ -- we can just use
244+ -- parallely $ mconcat $ replicate n $ yieldM (...)
245+ loop :: String -> Int -> SerialT IO String
246+ loop name n = do
247+ rnd <- S.yieldM (randomIO :: IO Int)
248+ let result = name <> show rnd
249+ repeatIt = if n > 1 then loop name (n - 1) else S.nil
250+ in return result `S.wAsync` repeatIt
251+
230252main :: IO ()
231253main = hspec $ H.parallel $ do
232254 describe "Filtering" $ do
@@ -243,6 +265,7 @@ main = hspec $ H.parallel $ do
243265 describe "Miscellaneous combined examples aheadly" mixedOpsAheadly
244266 describe "Simple MonadError and MonadThrow" simpleMonadError
245267
268+ it "Nested loops" nestedLoops
246269 {-
247270 describe "Composed MonadError serially" $ composeWithMonadError serially
248271 describe "Composed MonadError wSerially" $ composeWithMonadError wSerially
test/nested-loops.hsdeleted−27
@@ -1,27 +0,0 @@
1−#if !(MIN_VERSION_base(4,11,0))
2−import Data.Semigroup ((<>))
3−#endif
4−import Control.Concurrent (myThreadId)
5−import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
6−import System.Random (randomIO)
7−import Streamly.Prelude
8−
9−main :: IO ()
10−main = drain $ do
11− yieldM $ hSetBuffering stdout LineBuffering
12− x <- loop "A " 2
13− y <- loop "B " 2
14− yieldM $ myThreadId >>= putStr . show
15− >> putStr " "
16− >> print (x, y)
17−
18− where
19−
20− -- we can just use
21− -- parallely $ mconcat $ replicate n $ yieldM (...)
22− loop :: String -> Int -> SerialT IO String
23− loop name n = do
24− rnd <- yieldM (randomIO :: IO Int)
25− let result = name <> show rnd
26− repeatIt = if n > 1 then loop name (n - 1) else nil
27− in return result `wAsync` repeatIt