on master help sign in
Add tests for foldIterateM
commiteda484641a713ec3d86c22e8df9d8f8bfb2f44b8 authorAdithya Kumar <adithya@composewell.com> dateSat 6 Mar 2021, 06:01 (6 years ago) parent7da0593
1 file changed+21−1
test/Streamly/Test/Prelude/Serial.hs+21−1
test/Streamly/Test/Prelude/Serial.hs+21−1
@@ -20,6 +20,7 @@ import Foreign.Storable (Storable)
2020#if __GLASGOW_HASKELL__ < 808
2121import Data.Semigroup ((<>))
2222#endif
23+import Data.Semigroup (Sum(..), getSum)
2324import Test.Hspec.QuickCheck
2425import Test.QuickCheck
2526 ( Gen
@@ -43,7 +44,7 @@ import Streamly.Prelude (SerialT, IsStream, serial, serially)
4344import Streamly.Prelude (avgRate, maxBuffer)
4445#endif
4546import qualified Streamly.Prelude as S
46−import qualified Streamly.Data.Fold as FL
47+import qualified Streamly.Internal.Data.Fold as FL
4748import qualified Streamly.Internal.Data.Unfold as UF
4849import qualified Streamly.Internal.Data.Stream.IsStream as IS
4950import qualified Streamly.Data.Array.Foreign as A
@@ -485,6 +486,22 @@ testFromCallback = do
485486 threadDelay 100000
486487 return Nothing
487488
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+
488505main :: IO ()
489506main = hspec
490507 $ H.parallel
@@ -651,3 +668,6 @@ main = hspec
651668 describe "Composed MonadThrow serially" $ composeWithMonadThrow serially
652669
653670 it "fromCallback" $ testFromCallback `shouldReturn` (50*101)
671+
672+ describe "Nesting" $ do
673+ prop "foldIterateM" foldIterateM