on master help sign in
Remove redundant stuff & testUnfoldA -> testUnfoldM in unfold tests
commite786c094234612db001181b4fecbade20356c5a7 authoradithyaov <adithya@composewell.com> dateTue 20 Oct 2020, 07:17 (6 years ago) parentde680fb
1 file changed+25−40
test/Streamly/Test/Data/Unfold.hs+25−40
test/Streamly/Test/Data/Unfold.hs+25−40
@@ -11,12 +11,12 @@ module Main (main) where
1111
1212import Streamly.Internal.Data.Unfold (Unfold)
1313
14+import qualified Data.List as List
15+import qualified Prelude
1416import qualified Streamly.Internal.Data.Unfold as UF
1517import qualified Streamly.Internal.Data.Stream.IsStream as S
1618import qualified Streamly.Internal.Data.Stream.StreamD as D
1719import qualified Streamly.Internal.Data.Stream.StreamK as K
18−import qualified Prelude
19−import qualified Data.List as List
2020
2121import Control.Monad.Trans.State.Strict
2222import Data.Functor.Identity
@@ -27,15 +27,13 @@ import Test.Hspec.QuickCheck
2727import Test.QuickCheck
2828import Test.QuickCheck.Function
2929
30−-- We check for side effects in most cases
31−
3230-------------------------------------------------------------------------------
3331-- Helper functions
3432-------------------------------------------------------------------------------
3533
36−testUnfoldA ::
34+testUnfoldM ::
3735 (Eq s, Eq b) => Unfold (State s) a b -> s -> s -> a -> [b] -> Bool
38−testUnfoldA unf si sf seed lst = evalState action si
36+testUnfoldM unf si sf seed lst = evalState action si
3937
4038 where
4139
@@ -44,8 +42,8 @@ testUnfoldA unf si sf seed lst = evalState action si
4442 y <- get
4543 return $ x == lst && y == sf
4644
47−testUnfoldAD :: Unfold (State Int) a Int -> Int -> Int -> a -> [Int] -> Bool
48−testUnfoldAD = testUnfoldA
45+testUnfoldMD :: Unfold (State Int) a Int -> Int -> Int -> a -> [Int] -> Bool
46+testUnfoldMD = testUnfoldM
4947
5048testUnfold :: Eq b => Unfold Identity a b -> a -> [b] -> Bool
5149testUnfold unf seed lst = runIdentity action
@@ -66,7 +64,7 @@ testUnfoldD = testUnfold
6664lmapM :: Bool
6765lmapM =
6866 let unf = UF.lmapM (\x -> modify (+ 1) >> return x) (UF.singleton id)
69− in testUnfoldAD unf 0 1 1 [1]
67+ in testUnfoldMD unf 0 1 1 [1]
7068
7169supply :: Bool
7270supply =
@@ -121,28 +119,28 @@ fromStreamK =
121119nilM :: Bool
122120nilM =
123121 let unf = UF.nilM put
124− in testUnfoldAD unf 0 1 1 []
122+ in testUnfoldMD unf 0 1 1 []
125123
126124consM :: Bool
127125consM =
128126 let cns = UF.consM (\a -> modify (+ a) >> get)
129127 unf = cns $ cns $ UF.nilM $ \a -> modify (+ a)
130− in testUnfoldAD unf 0 3 1 [1, 2]
128+ in testUnfoldMD unf 0 3 1 [1, 2]
131129
132130effect :: Bool
133131effect =
134132 let unf = UF.effect (modify (+ 1) >> get)
135− in testUnfoldAD unf 0 1 undefined [1]
133+ in testUnfoldMD unf 0 1 undefined [1]
136134
137135singletonM :: Bool
138136singletonM =
139137 let unf = UF.singletonM (\a -> modify (+ a) >> get)
140− in testUnfoldAD unf 0 1 1 [1]
138+ in testUnfoldMD unf 0 1 1 [1]
141139
142140const :: Bool
143141const =
144142 let unf = UF.take 10 $ UF.const (modify (+ 1) >> get)
145− in testUnfoldAD unf 0 10 (0 :: Int) [1 .. 10]
143+ in testUnfoldMD unf 0 10 (0 :: Int) [1 .. 10]
146144
147145unfoldrM :: Property
148146unfoldrM =
@@ -154,14 +152,14 @@ unfoldrM =
154152 unf = UF.take 100 $ UF.unfoldrM genM
155153 ll = length list
156154 fs = if ll < 100 then ll + 1 else 100
157− in testUnfoldAD unf 0 fs 1 list
155+ in testUnfoldMD unf 0 fs 1 list
158156
159157fromListM :: Property
160158fromListM =
161159 property
162160 $ \n ->
163161 let lst = Prelude.map (\x -> modify (+ 1) >> return x) n
164− in testUnfoldAD UF.fromListM 0 (length n) lst n
162+ in testUnfoldMD UF.fromListM 0 (length n) lst n
165163
166164replicateM :: Property
167165replicateM =
@@ -169,11 +167,11 @@ replicateM =
169167 $ \i ->
170168 let ns = max 0 i
171169 seed = modify (+ 1) >> get
172− in testUnfoldAD (UF.replicateM i) 0 ns seed [1 .. i]
170+ in testUnfoldMD (UF.replicateM i) 0 ns seed [1 .. i]
173171
174172repeatM :: Bool
175173repeatM =
176− testUnfoldAD (UF.take 10 UF.repeatM) 0 10 (modify (+ 1) >> get) [1 .. 10]
174+ testUnfoldMD (UF.take 10 UF.repeatM) 0 10 (modify (+ 1) >> get) [1 .. 10]
177175
178176iterateM :: Property
179177iterateM =
@@ -183,7 +181,7 @@ iterateM =
183181 nextM x = modify (+ 1) >> return (nextA x)
184182 list = Prelude.take 100 $ List.iterate nextA 1
185183 unf = UF.take 100 $ UF.iterateM nextM
186− in testUnfoldAD unf 0 110 (modify (+ 10) >> return 1) list
184+ in testUnfoldMD unf 0 110 (modify (+ 10) >> return 1) list
187185
188186fromIndicesM :: Property
189187fromIndicesM =
@@ -193,7 +191,7 @@ fromIndicesM =
193191 indFM x = modify (+ 1) >> return (indFA x)
194192 list = Prelude.take 100 $ Prelude.map indFA [1 ..]
195193 unf = UF.take 100 $ UF.fromIndicesM indFM
196− in testUnfoldAD unf 0 (length list) 1 list
194+ in testUnfoldMD unf 0 (length list) 1 list
197195
198196enumerateFromStepNum :: Property
199197enumerateFromStepNum =
@@ -240,7 +238,7 @@ mapM =
240238 fM x = modify (+ 1) >> return (fA x)
241239 unf = UF.mapM fM UF.fromList
242240 mList = Prelude.map fA list
243− in testUnfoldAD unf 0 (length list) list mList
241+ in testUnfoldMD unf 0 (length list) list mList
244242
245243mapMWithInput :: Property
246244mapMWithInput =
@@ -250,7 +248,7 @@ mapMWithInput =
250248 fM x y = modify (+ 1) >> return (fA x y)
251249 unf = UF.mapMWithInput fM UF.fromList
252250 mList = Prelude.map (fA list) list
253− in testUnfoldAD unf 0 (length list) list mList
251+ in testUnfoldMD unf 0 (length list) list mList
254252
255253take :: Property
256254take =
@@ -272,7 +270,7 @@ takeWhileM =
272270 unf = UF.takeWhileM fM UF.fromList
273271 fL = Prelude.takeWhile (apply f) n
274272 fS = Prelude.length fL
275− in testUnfoldAD unf 0 fS n fL
273+ in testUnfoldMD unf 0 fS n fL
276274
277275filterM :: Property
278276filterM =
@@ -285,7 +283,7 @@ filterM =
285283 unf = UF.filterM fM UF.fromList
286284 fL = Prelude.filter (apply f) n
287285 fS = Prelude.length fL
288− in testUnfoldAD unf 0 fS n fL
286+ in testUnfoldMD unf 0 fS n fL
289287
290288drop :: Property
291289drop =
@@ -306,7 +304,7 @@ dropWhileM =
306304 unf = UF.dropWhileM fM UF.fromList
307305 fL = Prelude.dropWhile (apply f) n
308306 fS = Prelude.length n - Prelude.length fL
309− in testUnfoldAD unf 0 fS n fL
307+ in testUnfoldMD unf 0 fS n fL
310308
311309-------------------------------------------------------------------------------
312310-- Stream combination
@@ -322,7 +320,7 @@ zipWithM =
322320 fM a b = modify (+ 1) >> return (fA a b)
323321 unf = UF.zipWithM fM unf1 unf2
324322 lst = Prelude.zipWith fA [1 .. 10] [1 .. 20]
325− in testUnfoldAD unf 0 10 (1, 1) lst
323+ in testUnfoldMD unf 0 10 (1, 1) lst
326324
327325concat :: Bool
328326concat =
@@ -354,7 +352,7 @@ concatMapM =
354352 unfOut = UF.enumerateFromToIntegral 10
355353 unf = UF.concatMapM unfInF unfOut
356354 list = List.concatMap listInF [1 .. 10]
357− in testUnfoldAD unf 0 110 1 list
355+ in testUnfoldMD unf 0 110 1 list
358356
359357-------------------------------------------------------------------------------
360358-- Test groups
@@ -419,7 +417,6 @@ testTransformation =
419417 -- prop "dropWhile" dropWhile
420418 prop "dropWhileM" dropWhileM
421419
422−
423420testCombination :: Spec
424421testCombination =
425422 describe "Transformation"
@@ -434,7 +431,6 @@ testCombination =
434431 -- prop "apDiscardFst" apDiscardFst
435432 -- prop "apDiscardSnd" apDiscardSnd
436433
437−
438434-------------------------------------------------------------------------------
439435-- Main
440436-------------------------------------------------------------------------------
@@ -448,14 +444,3 @@ main =
448444 testGeneration
449445 testTransformation
450446 testCombination
451− -- prop "concatMapM" concatMapM
452− -- prop "gbracket" gbracket
453− -- prop "gbracketIO" gbracketIO
454− -- prop "before" before
455− -- prop "after" after
456− -- prop "afterIO" afterIO
457− -- prop "onException" onException
458− -- prop "finally" finally
459− -- prop "finallyIO" finallyIO
460− -- prop "bracket" bracket
461− -- prop "bracketIO" bracketIO