on master help sign in
Create another test group for transformation & add multiple unfolds

Unfolds added: mapM mapMWithInput

commite01474b07795d8128a0f8e9c2731b370a8a78b8c authoradithyaov <adithya@composewell.com> dateTue 20 Oct 2020, 06:40 (6 years ago) parentcf2ae21
1 file changed+42−6
test/Streamly/Test/Data/Unfold.hs+42−6
test/Streamly/Test/Data/Unfold.hs+42−6
@@ -20,7 +20,7 @@ import qualified Data.List as List
2020
2121import Control.Monad.Trans.State.Strict
2222import Data.Functor.Identity
23−import Prelude hiding (const, take, drop, concat)
23+import Prelude hiding (const, take, drop, concat, mapM)
2424import Streamly.Prelude (SerialT)
2525import Test.Hspec as H
2626import Test.Hspec.QuickCheck
@@ -228,6 +228,30 @@ enumerateFromToIntegral =
228228 let unf = UF.enumerateFromToIntegral t
229229 in testUnfoldD unf f [f .. t]
230230
231+-------------------------------------------------------------------------------
232+-- Stream transformation
233+-------------------------------------------------------------------------------
234+
235+mapM :: Property
236+mapM =
237+ property
238+ $ \f list ->
239+ let fA = apply f :: Int -> Int
240+ fM x = modify (+ 1) >> return (fA x)
241+ unf = UF.mapM fM UF.fromList
242+ mList = Prelude.map fA list
243+ in testUnfoldAD unf 0 (length list) list mList
244+
245+mapMWithInput :: Property
246+mapMWithInput =
247+ property
248+ $ \f list ->
249+ let fA = applyFun2 f :: [Int] -> Int -> Int
250+ fM x y = modify (+ 1) >> return (fA x y)
251+ unf = UF.mapMWithInput fM UF.fromList
252+ mList = Prelude.map (fA list) list
253+ in testUnfoldAD unf 0 (length list) list mList
254+
231255take :: Property
232256take =
233257 property
@@ -359,6 +383,22 @@ testGeneration =
359383 -- prop "numFrom" numFrom
360384 prop "enumerateFromToFractional" enumerateFromToFractional
361385
386+testTransformation :: Spec
387+testTransformation =
388+ describe "Transformation"
389+ $ do
390+ -- prop "map" map
391+ prop "mapM" mapM
392+ prop "mapMWithInput" mapMWithInput
393+ prop "takeWhileM" takeWhileM
394+ -- prop "takeWhile" takeWhile
395+ prop "take" take
396+ -- prop "filter" filter
397+ prop "filterM" filterM
398+ prop "drop" drop
399+ -- prop "dropWhile" dropWhile
400+ prop "dropWhileM" dropWhileM
401+
362402-------------------------------------------------------------------------------
363403-- Main
364404-------------------------------------------------------------------------------
@@ -367,12 +407,8 @@ main :: IO ()
367407main = hspec $ do
368408 testInputOps
369409 testGeneration
410+ testTransformation
370411 describe "Unfold tests" $ do
371− prop "take" take
372− prop "takeWhileM" takeWhileM
373− prop "filterM" filterM
374− prop "drop" drop
375− prop "dropWhileM" dropWhileM
376412 prop "zipWithM" zipWithM
377413 prop "concat" concat
378414 prop "outerProduct" outerProduct