on master help sign in
Add more tests
commit6c12266b1f35fa9cd76922d4be722baac33e1e37 authorHarendra Kumar <harendra.kumar@gmail.com> dateMon 3 Jul 2017, 08:08 (9 years ago) parent1e4950d
2 files changed+29−2
test/3-sample.hs+1−1 test/Main.hs+28−1
test/3-sample.hs+1−1
@@ -11,7 +11,7 @@ import Control.Monad.Catch (MonadThrow)
1111
1212import Asyncly
1313
14−main = wait_ $ threads 3 $ do
14+main = wait_ $ threads 0 $ do
1515 liftIO $ hSetBuffering stdout LineBuffering
1616 mainThread <- liftIO myThreadId
1717 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
test/Main.hs+28−1
@@ -3,7 +3,7 @@ module Main (main) where
33import Test.Hspec
44
55import Control.Applicative ((<|>))
6−--import Control.Monad.IO.Class (liftIO)
6+import Control.Monad.IO.Class (liftIO)
77import Asyncly
88import Data.List (sort)
99
@@ -34,3 +34,30 @@ main = hspec $ do
3434 it "Nested async tasks with Alternative" $
3535 (wait (async (async $ return 0) <|> return 1) >>= return . sort)
3636 `shouldReturn` ([0,1] :: [Int])
37+ it "General example" $
38+ (wait generalExample >>= return . sort)
39+ `shouldReturn` ([7,7,8,8,8,8,8,8,9,9,9,9,9,9,10,10] :: [Int])
40+ it "General example synchronous" $
41+ (wait (threads 0 generalExample) >>= return . sort)
42+ `shouldReturn` ([7,7,8,8,8,8,8,8,9,9,9,9,9,9,10,10] :: [Int])
43+
44+generalExample :: AsyncT IO Int
45+generalExample = do
46+ liftIO $ return ()
47+ liftIO $ print "hello"
48+ x <- async (return 1)
49+ y <- async (return 2)
50+ z <- do
51+ x1 <- async (return 1) <|> async (return 2)
52+ liftIO $ return ()
53+ liftIO $ print "hello"
54+ y1 <- (return 1) <|> async (return 2)
55+ z1 <- do
56+ x11 <- async (return 1) <|> (return 2)
57+ y11 <- async (return 1) <|> async (return 2)
58+ z11 <- async (return 1) <|> (return 2)
59+ liftIO $ return ()
60+ liftIO $ print "hello"
61+ return (x11 + y11)
62+ return (x1 + y1 + z1)
63+ return (x + y + z)