@@ -13,11 +13,13 @@ import Data.List (sort)
1313#if __GLASGOW_HASKELL__ < 808
1414import Data.Semigroup ((<>))
1515#endif
16−import Test.QuickCheck (Property)
16+import Test.QuickCheck (Property, forAll)
1717import Test.Hspec.QuickCheck
1818import Test.QuickCheck.Monadic (monadicIO, run)
1919import Test.Hspec as H
2020
21+import qualified Streamly.Internal.Data.Stream.Serial as Serial
22+
2123import Streamly.Prelude hiding (repeat)
2224import qualified Streamly.Prelude as S
2325
@@ -55,6 +57,17 @@ interleaveCheck t f =
5557 singleton :: IsStream t => a -> t m a
5658 singleton a = a .: nil
5759
60+wSerialMinLengthProp :: Property
61+wSerialMinLengthProp =
62+ forAll (chooseInt (0, 10))
63+ $ \len -> S.length (combined len) `shouldReturn` 2 * len + 1
64+
65+ where
66+
67+ finiteStream len = S.take len $ S.repeat (1 :: Int)
68+ infiniteStream = S.repeat 1
69+ combined len = infiniteStream `Serial.wSerialMin` finiteStream len
70+
5871main :: IO ()
5972main = hspec
6073 $ H.parallel
@@ -158,3 +171,11 @@ main = hspec
158171
159172 describe "Tests for exceptions" $ wSerialOps $ exceptionOps "wSerially"
160173 describe "Composed MonadThrow wSerially" $ composeWithMonadThrow wSerially
174+
175+ ---------------------------------------------------------------------------
176+ -- Termination checks
177+ ---------------------------------------------------------------------------
178+
179+ describe "wSerialMin termination" $
180+ prop "len (infinite `wSerialMin` finite) = 2 * len(finite) + 1"
181+ wSerialMinLengthProp