mirror of
https://github.com/ilyakooo0/streamly.git
synced 2024-10-06 05:07:07 +03:00
Remove nested-loops test suite.
- Add it to the Prelude test suite.
This commit is contained in:
parent
2f3d30c72d
commit
16db9cf7e0
@ -583,6 +583,7 @@ test-suite Prelude
|
||||
, containers >= 0.5 && < 0.7
|
||||
, transformers >= 0.4 && < 0.6
|
||||
, mtl >= 2.2 && < 3
|
||||
, random >= 1.0.0 && < 2
|
||||
|
||||
test-suite Prelude.Serial
|
||||
import: test-options, prelude-test-options
|
||||
@ -816,17 +817,6 @@ test-suite string-test
|
||||
, hspec >= 2.0 && < 3
|
||||
default-language: Haskell2010
|
||||
|
||||
test-suite nested-loops
|
||||
import: test-options
|
||||
type: exitcode-stdio-1.0
|
||||
default-language: Haskell2010
|
||||
main-is: nested-loops.hs
|
||||
hs-source-dirs: test
|
||||
build-Depends:
|
||||
streamly
|
||||
, base >= 4.9 && < 5
|
||||
, random >= 1.0.0 && < 2
|
||||
|
||||
test-suite parallel-loops
|
||||
import: test-options
|
||||
type: exitcode-stdio-1.0
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
module Streamly.Test.Prelude (main) where
|
||||
|
||||
import Control.Concurrent (threadDelay)
|
||||
import Control.Concurrent (myThreadId, threadDelay)
|
||||
import Control.Exception (Exception, try)
|
||||
import Control.Monad (when)
|
||||
import Control.Monad.Catch (throwM)
|
||||
@ -23,6 +23,8 @@ import Data.Maybe (fromJust, isJust)
|
||||
#if !(MIN_VERSION_base(4,11,0))
|
||||
import Data.Semigroup (Semigroup(..))
|
||||
#endif
|
||||
import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
|
||||
import System.Random (randomIO)
|
||||
import Test.Hspec as H
|
||||
import Test.Hspec.QuickCheck (prop)
|
||||
import Test.QuickCheck (Property, choose)
|
||||
@ -227,6 +229,26 @@ mixedOpsAheadly =
|
||||
return (x1 + y1 + z1)
|
||||
return (x + y + z)
|
||||
|
||||
nestedLoops :: IO ()
|
||||
nestedLoops = S.drain $ do
|
||||
S.yieldM $ hSetBuffering stdout LineBuffering
|
||||
x <- loop "A " 2
|
||||
y <- loop "B " 2
|
||||
S.yieldM $ myThreadId >>= putStr . show
|
||||
>> putStr " "
|
||||
>> print (x, y)
|
||||
|
||||
where
|
||||
|
||||
-- we can just use
|
||||
-- parallely $ mconcat $ replicate n $ yieldM (...)
|
||||
loop :: String -> Int -> SerialT IO String
|
||||
loop name n = do
|
||||
rnd <- S.yieldM (randomIO :: IO Int)
|
||||
let result = name <> show rnd
|
||||
repeatIt = if n > 1 then loop name (n - 1) else S.nil
|
||||
in return result `S.wAsync` repeatIt
|
||||
|
||||
main :: IO ()
|
||||
main = hspec $ H.parallel $ do
|
||||
describe "Filtering" $ do
|
||||
@ -243,6 +265,7 @@ main = hspec $ H.parallel $ do
|
||||
describe "Miscellaneous combined examples aheadly" mixedOpsAheadly
|
||||
describe "Simple MonadError and MonadThrow" simpleMonadError
|
||||
|
||||
it "Nested loops" nestedLoops
|
||||
{-
|
||||
describe "Composed MonadError serially" $ composeWithMonadError serially
|
||||
describe "Composed MonadError wSerially" $ composeWithMonadError wSerially
|
||||
|
@ -1,27 +0,0 @@
|
||||
#if !(MIN_VERSION_base(4,11,0))
|
||||
import Data.Semigroup ((<>))
|
||||
#endif
|
||||
import Control.Concurrent (myThreadId)
|
||||
import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
|
||||
import System.Random (randomIO)
|
||||
import Streamly.Prelude
|
||||
|
||||
main :: IO ()
|
||||
main = drain $ do
|
||||
yieldM $ hSetBuffering stdout LineBuffering
|
||||
x <- loop "A " 2
|
||||
y <- loop "B " 2
|
||||
yieldM $ myThreadId >>= putStr . show
|
||||
>> putStr " "
|
||||
>> print (x, y)
|
||||
|
||||
where
|
||||
|
||||
-- we can just use
|
||||
-- parallely $ mconcat $ replicate n $ yieldM (...)
|
||||
loop :: String -> Int -> SerialT IO String
|
||||
loop name n = do
|
||||
rnd <- yieldM (randomIO :: IO Int)
|
||||
let result = name <> show rnd
|
||||
repeatIt = if n > 1 then loop name (n - 1) else nil
|
||||
in return result `wAsync` repeatIt
|
Loading…
Reference in New Issue
Block a user