mirror of
https://github.com/ilyakooo0/streamly.git
synced 2024-09-11 08:25:40 +03:00
Add test cases for async
This commit is contained in:
parent
4d4732577d
commit
64e9eeafc5
@ -15,17 +15,33 @@ import Data.List (sort)
|
||||
import Data.Semigroup ((<>))
|
||||
#endif
|
||||
import Test.Hspec.QuickCheck
|
||||
import Test.QuickCheck (Property, withMaxSuccess)
|
||||
import Test.QuickCheck.Monadic (monadicIO, run)
|
||||
import Test.Hspec as H
|
||||
|
||||
import Streamly.Prelude
|
||||
import qualified Streamly.Prelude as S
|
||||
|
||||
import Data.IORef
|
||||
import Streamly.Test.Common
|
||||
import Streamly.Test.Prelude.Common
|
||||
|
||||
|
||||
moduleName :: String
|
||||
moduleName = "Prelude.Async"
|
||||
|
||||
constructfromAsyncSingleThread ::
|
||||
S.AsyncT IO Int -> S.AsyncT IO Int-> [Int] -> Property
|
||||
constructfromAsyncSingleThread s1 s2 res =
|
||||
withMaxSuccess maxTestCount $
|
||||
monadicIO $ do
|
||||
x <- run
|
||||
$ S.toList
|
||||
$ S.fromAsync
|
||||
$ S.maxThreads 1
|
||||
$ s1 `S.async` s2
|
||||
equals (==) x res
|
||||
|
||||
concurrentApplicative :: IO ()
|
||||
concurrentApplicative = do
|
||||
ref <- newIORef []
|
||||
@ -56,6 +72,11 @@ main = hspec
|
||||
asyncOps $ prop "asyncly consM" . constructWithConsM S.consM sort
|
||||
asyncOps $ prop "asyncly (.:)" . constructWithCons (S..:)
|
||||
asyncOps $ prop "asyncly (|:)" . constructWithConsM (S.|:) sort
|
||||
prop "asyncSingleThreaded" $
|
||||
constructfromAsyncSingleThread
|
||||
(S.fromList [1,2,3,4,5])
|
||||
(S.fromList [6,7,8,9,10])
|
||||
[1,2,3,4,5,6,7,8,9,10]
|
||||
|
||||
describe "Functor operations" $ do
|
||||
asyncOps $ functorOps S.fromFoldable "asyncly" sortEq
|
||||
|
@ -17,16 +17,31 @@ import Data.List (sort)
|
||||
import Data.Semigroup ((<>))
|
||||
#endif
|
||||
import Test.Hspec.QuickCheck
|
||||
import Test.QuickCheck (Property, withMaxSuccess)
|
||||
import Test.QuickCheck.Monadic (monadicIO, run)
|
||||
import Test.Hspec as H
|
||||
|
||||
import Streamly.Prelude
|
||||
import qualified Streamly.Prelude as S
|
||||
|
||||
import Streamly.Test.Common
|
||||
import Streamly.Test.Prelude.Common
|
||||
|
||||
moduleName :: String
|
||||
moduleName = "Prelude.WAsync"
|
||||
|
||||
constructfromWAsync ::
|
||||
S.WAsyncT IO Int -> S.WAsyncT IO Int-> [Int] -> Property
|
||||
constructfromWAsync s1 s2 res =
|
||||
withMaxSuccess maxTestCount $
|
||||
monadicIO $ do
|
||||
x <- run
|
||||
$ S.toList
|
||||
$ S.fromWAsync
|
||||
$ S.maxThreads 1
|
||||
$ s1 `S.wAsync` s2
|
||||
equals (==) x res
|
||||
|
||||
main :: IO ()
|
||||
main = hspec
|
||||
$ H.parallel
|
||||
@ -47,11 +62,42 @@ main = hspec
|
||||
wAsyncOps $ prop "wAsyncly consM" . constructWithConsM S.consM sort
|
||||
wAsyncOps $ prop "wAsyncly (.:)" . constructWithCons (S..:)
|
||||
wAsyncOps $ prop "wAsyncly (|:)" . constructWithConsM (S.|:) sort
|
||||
prop "wAsync" $
|
||||
prop "wAsync1" $
|
||||
constructfromWAsync
|
||||
(S.fromList [1,2,3])
|
||||
(S.fromList [4,5,6])
|
||||
[1,4,2,5,3,6]
|
||||
(S.fromList [1,2,3,4,5])
|
||||
(S.fromList [6,7,8,9,10])
|
||||
[1,6,2,7,3,8,4,9,5,10]
|
||||
|
||||
prop "wAsync2" $
|
||||
constructfromWAsync
|
||||
(S.fromList [1,2,3,4,5,6,7])
|
||||
(S.fromList [8,9,10])
|
||||
[1,8,2,9,3,10,4,5,6,7]
|
||||
|
||||
prop "wAsync3" $
|
||||
constructfromWAsync
|
||||
(S.fromList [1,2,3,4])
|
||||
(S.fromList [5,6,7,8,9,10])
|
||||
[1,5,2,6,3,7,4,8,9,10]
|
||||
|
||||
prop "wAsync4" $
|
||||
constructfromWAsync
|
||||
(S.fromList [])
|
||||
(S.fromList [5,6,7,8,9,10])
|
||||
[5,6,7,8,9,10]
|
||||
|
||||
prop "wAsync5" $
|
||||
constructfromWAsync
|
||||
(S.fromList [1,2,3,4])
|
||||
(S.fromList [])
|
||||
[1,2,3,4]
|
||||
|
||||
prop "wAsync6" $
|
||||
constructfromWAsync
|
||||
(S.fromList [])
|
||||
(S.fromList [])
|
||||
[]
|
||||
|
||||
|
||||
describe "Functor operations" $ do
|
||||
wAsyncOps $ functorOps S.fromFoldable "wAsyncly" sortEq
|
||||
|
@ -31,7 +31,6 @@ module Streamly.Test.Prelude.Common
|
||||
, constructWithConsM
|
||||
, constructWithFromPure
|
||||
, constructWithFromEffect
|
||||
, constructfromWAsync
|
||||
, simpleOps
|
||||
-- * Applicative operations
|
||||
, applicativeOps
|
||||
@ -291,18 +290,6 @@ constructWithFromIndicesM op len =
|
||||
streamEffect <- run $ readIORef mvl
|
||||
listEquals (==) streamEffect list
|
||||
|
||||
constructfromWAsync ::
|
||||
S.WAsyncT IO Int -> S.WAsyncT IO Int-> [Int] -> Property
|
||||
constructfromWAsync s1 s2 res =
|
||||
withMaxSuccess maxTestCount $
|
||||
monadicIO $ do
|
||||
x <- run
|
||||
$ S.toList
|
||||
$ S.fromWAsync
|
||||
$ S.maxThreads 1
|
||||
$ s1 `S.wAsync` s2
|
||||
equals (==) x res
|
||||
|
||||
constructWithCons ::
|
||||
IsStream t
|
||||
=> (Int -> t IO Int -> t IO Int)
|
||||
|
Loading…
Reference in New Issue
Block a user