on master help sign in
Remove nested-loops test suite.
16db9cfpranaysashank
streamly.cabal+1−11
@@ -583,6 +583,7 @@ test-suite Prelude
583 , containers >= 0.5 && < 0.7
583 , containers >= 0.5 && < 0.7
584 , transformers >= 0.4 && < 0.6
584 , transformers >= 0.4 && < 0.6
585 , mtl >= 2.2 && < 3
585 , mtl >= 2.2 && < 3
586+ , random >= 1.0.0 && < 2
586
587
587test-suite Prelude.Serial
588test-suite Prelude.Serial
588 import: test-options, prelude-test-options
589 import: test-options, prelude-test-options
@@ -816,17 +817,6 @@ test-suite string-test
816 , hspec >= 2.0 && < 3
817 , hspec >= 2.0 && < 3
817 default-language: Haskell2010
818 default-language: Haskell2010
818
819
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−
830test-suite parallel-loops
820test-suite parallel-loops
831 import: test-options
821 import: test-options
832 type: exitcode-stdio-1.0
822 type: exitcode-stdio-1.0
test/Streamly/Test/Prelude.hs+24−1
@@ -9,7 +9,7 @@
9
9
10module Streamly.Test.Prelude (main) where
10module Streamly.Test.Prelude (main) where
11
11
12−import Control.Concurrent (threadDelay)
12+import Control.Concurrent (myThreadId, threadDelay)
13import Control.Exception (Exception, try)
13import Control.Exception (Exception, try)
14import Control.Monad (when)
14import Control.Monad (when)
15import Control.Monad.Catch (throwM)
15import Control.Monad.Catch (throwM)
@@ -23,6 +23,8 @@ import Data.Maybe (fromJust, isJust)
23#if !(MIN_VERSION_base(4,11,0))
23#if !(MIN_VERSION_base(4,11,0))
24import Data.Semigroup (Semigroup(..))
24import Data.Semigroup (Semigroup(..))
25#endif
25#endif
26+import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
27+import System.Random (randomIO)
26import Test.Hspec as H
28import Test.Hspec as H
27import Test.Hspec.QuickCheck (prop)
29import Test.Hspec.QuickCheck (prop)
28import Test.QuickCheck (Property, choose)
30import Test.QuickCheck (Property, choose)
@@ -227,6 +229,26 @@ mixedOpsAheadly =
227 return (x1 + y1 + z1)
229 return (x1 + y1 + z1)
228 return (x + y + z)
230 return (x + y + z)
229
231
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+
230main :: IO ()
252main :: IO ()
231main = hspec $ H.parallel $ do
253main = hspec $ H.parallel $ do
232 describe "Filtering" $ do
254 describe "Filtering" $ do
@@ -243,6 +265,7 @@ main = hspec $ H.parallel $ do
243 describe "Miscellaneous combined examples aheadly" mixedOpsAheadly
265 describe "Miscellaneous combined examples aheadly" mixedOpsAheadly
244 describe "Simple MonadError and MonadThrow" simpleMonadError
266 describe "Simple MonadError and MonadThrow" simpleMonadError
245
267
268+ it "Nested loops" nestedLoops
246 {-
269 {-
247 describe "Composed MonadError serially" $ composeWithMonadError serially
270 describe "Composed MonadError serially" $ composeWithMonadError serially
248 describe "Composed MonadError wSerially" $ composeWithMonadError wSerially
271 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