@@ -12,14 +12,34 @@ module Streamly.Test.Prelude.WSerial where
1212#if __GLASGOW_HASKELL__ < 808
1313import Data.Semigroup ((<>))
1414#endif
15+import Test.QuickCheck (Property)
1516import Test.Hspec.QuickCheck
17+import Test.QuickCheck.Monadic (monadicIO, run)
1618import Test.Hspec as H
1719
1820import Streamly
1921import qualified Streamly.Prelude as S
2022
23+import Streamly.Test.Common
2124import Streamly.Test.Prelude
2225
26+associativityCheck
27+ :: String
28+ -> (WSerialT IO Int -> SerialT IO Int)
29+ -> Spec
30+associativityCheck desc t = prop desc assocCheckProp
31+ where
32+ assocCheckProp :: [Int] -> [Int] -> [Int] -> Property
33+ assocCheckProp xs ys zs =
34+ monadicIO $ do
35+ let xStream = S.fromList xs
36+ yStream = S.fromList ys
37+ zStream = S.fromList zs
38+ infixAssocstream <-
39+ run $ S.toList $ t $ xStream `wSerial` yStream `wSerial` zStream
40+ assocStream <- run $ S.toList $ t $ xStream <> yStream <> zStream
41+ listEquals (==) infixAssocstream assocStream
42+
2343main :: IO ()
2444main = hspec
2545 $ H.parallel
@@ -45,7 +65,8 @@ main = hspec
4565 wSerialOps $ monoidOps "wSerially" mempty sortEq
4666
4767 describe "Semigroup operations" $ do
48− wSerialOps $ semigroupOps "wSerially" (==)
68+ wSerialOps $ semigroupOps "wSerially" (==)
69+ wSerialOps $ associativityCheck "wSerial == <>"
4970
5071 describe "Applicative operations" $ do
5172 wSerialOps $ applicativeOps S.fromFoldable "wSerially applicative" sortEq