on master help sign in
Add tests for foldIterateM
eda4846Adithya Kumar
test/Streamly/Test/Prelude/Serial.hs+21−1
@@ -20,6 +20,7 @@ import Foreign.Storable (Storable)
20#if __GLASGOW_HASKELL__ < 808
20#if __GLASGOW_HASKELL__ < 808
21import Data.Semigroup ((<>))
21import Data.Semigroup ((<>))
22#endif
22#endif
23+import Data.Semigroup (Sum(..), getSum)
23import Test.Hspec.QuickCheck
24import Test.Hspec.QuickCheck
24import Test.QuickCheck
25import Test.QuickCheck
25 ( Gen
26 ( Gen
@@ -43,7 +44,7 @@ import Streamly.Prelude (SerialT, IsStream, serial, serially)
43import Streamly.Prelude (avgRate, maxBuffer)
44import Streamly.Prelude (avgRate, maxBuffer)
44#endif
45#endif
45import qualified Streamly.Prelude as S
46import qualified Streamly.Prelude as S
46−import qualified Streamly.Data.Fold as FL
47+import qualified Streamly.Internal.Data.Fold as FL
47import qualified Streamly.Internal.Data.Unfold as UF
48import qualified Streamly.Internal.Data.Unfold as UF
48import qualified Streamly.Internal.Data.Stream.IsStream as IS
49import qualified Streamly.Internal.Data.Stream.IsStream as IS
49import qualified Streamly.Data.Array.Foreign as A
50import qualified Streamly.Data.Array.Foreign as A
@@ -485,6 +486,22 @@ testFromCallback = do
485 threadDelay 100000
486 threadDelay 100000
486 return Nothing
487 return Nothing
487
488
489+foldIterateM :: Property
490+foldIterateM =
491+ forAll (listOf (chooseInt (0, max_length))) $ \lst -> monadicIO $ do
492+ let s1 = Prelude.sum lst
493+ strm = S.fromList lst
494+ ms2 <-
495+ S.last
496+ $ S.map getSum
497+ $ IS.foldIterateM
498+ (return . FL.take 1 . FL.sconcat)
499+ (Sum 0)
500+ $ S.map Sum strm
501+ case ms2 of
502+ Nothing -> assert $ s1 == 0
503+ Just s2 -> assert $ s1 == s2
504+
488main :: IO ()
505main :: IO ()
489main = hspec
506main = hspec
490 $ H.parallel
507 $ H.parallel
@@ -651,3 +668,6 @@ main = hspec
651 describe "Composed MonadThrow serially" $ composeWithMonadThrow serially
668 describe "Composed MonadThrow serially" $ composeWithMonadThrow serially
652
669
653 it "fromCallback" $ testFromCallback `shouldReturn` (50*101)
670 it "fromCallback" $ testFromCallback `shouldReturn` (50*101)
671+
672+ describe "Nesting" $ do
673+ prop "foldIterateM" foldIterateM