on master help sign in
Remove redundant stuff & testUnfoldA -> testUnfoldM in unfold tests
e786c09adithyaov
test/Streamly/Test/Data/Unfold.hs+25−40
@@ -11,12 +11,12 @@ module Main (main) where
11
11
12import Streamly.Internal.Data.Unfold (Unfold)
12import Streamly.Internal.Data.Unfold (Unfold)
13
13
14+import qualified Data.List as List
15+import qualified Prelude
14import qualified Streamly.Internal.Data.Unfold as UF
16import qualified Streamly.Internal.Data.Unfold as UF
15import qualified Streamly.Internal.Data.Stream.IsStream as S
17import qualified Streamly.Internal.Data.Stream.IsStream as S
16import qualified Streamly.Internal.Data.Stream.StreamD as D
18import qualified Streamly.Internal.Data.Stream.StreamD as D
17import qualified Streamly.Internal.Data.Stream.StreamK as K
19import qualified Streamly.Internal.Data.Stream.StreamK as K
18−import qualified Prelude
19−import qualified Data.List as List
20
20
21import Control.Monad.Trans.State.Strict
21import Control.Monad.Trans.State.Strict
22import Data.Functor.Identity
22import Data.Functor.Identity
@@ -27,15 +27,13 @@ import Test.Hspec.QuickCheck
27import Test.QuickCheck
27import Test.QuickCheck
28import Test.QuickCheck.Function
28import Test.QuickCheck.Function
29
29
30−-- We check for side effects in most cases
31−
32-------------------------------------------------------------------------------
30-------------------------------------------------------------------------------
33-- Helper functions
31-- Helper functions
34-------------------------------------------------------------------------------
32-------------------------------------------------------------------------------
35
33
36−testUnfoldA ::
34+testUnfoldM ::
37 (Eq s, Eq b) => Unfold (State s) a b -> s -> s -> a -> [b] -> Bool
35 (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
39
37
40 where
38 where
41
39
@@ -44,8 +42,8 @@ testUnfoldA unf si sf seed lst = evalState action si
44 y <- get
42 y <- get
45 return $ x == lst && y == sf
43 return $ x == lst && y == sf
46
44
47−testUnfoldAD :: Unfold (State Int) a Int -> Int -> Int -> a -> [Int] -> Bool
45+testUnfoldMD :: Unfold (State Int) a Int -> Int -> Int -> a -> [Int] -> Bool
48−testUnfoldAD = testUnfoldA
46+testUnfoldMD = testUnfoldM
49
47
50testUnfold :: Eq b => Unfold Identity a b -> a -> [b] -> Bool
48testUnfold :: Eq b => Unfold Identity a b -> a -> [b] -> Bool
51testUnfold unf seed lst = runIdentity action
49testUnfold unf seed lst = runIdentity action
@@ -66,7 +64,7 @@ testUnfoldD = testUnfold
66lmapM :: Bool
64lmapM :: Bool
67lmapM =
65lmapM =
68 let unf = UF.lmapM (\x -> modify (+ 1) >> return x) (UF.singleton id)
66 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]
70
68
71supply :: Bool
69supply :: Bool
72supply =
70supply =
@@ -121,28 +119,28 @@ fromStreamK =
121nilM :: Bool
119nilM :: Bool
122nilM =
120nilM =
123 let unf = UF.nilM put
121 let unf = UF.nilM put
124− in testUnfoldAD unf 0 1 1 []
122+ in testUnfoldMD unf 0 1 1 []
125
123
126consM :: Bool
124consM :: Bool
127consM =
125consM =
128 let cns = UF.consM (\a -> modify (+ a) >> get)
126 let cns = UF.consM (\a -> modify (+ a) >> get)
129 unf = cns $ cns $ UF.nilM $ \a -> modify (+ a)
127 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]
131
129
132effect :: Bool
130effect :: Bool
133effect =
131effect =
134 let unf = UF.effect (modify (+ 1) >> get)
132 let unf = UF.effect (modify (+ 1) >> get)
135− in testUnfoldAD unf 0 1 undefined [1]
133+ in testUnfoldMD unf 0 1 undefined [1]
136
134
137singletonM :: Bool
135singletonM :: Bool
138singletonM =
136singletonM =
139 let unf = UF.singletonM (\a -> modify (+ a) >> get)
137 let unf = UF.singletonM (\a -> modify (+ a) >> get)
140− in testUnfoldAD unf 0 1 1 [1]
138+ in testUnfoldMD unf 0 1 1 [1]
141
139
142const :: Bool
140const :: Bool
143const =
141const =
144 let unf = UF.take 10 $ UF.const (modify (+ 1) >> get)
142 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]
146
144
147unfoldrM :: Property
145unfoldrM :: Property
148unfoldrM =
146unfoldrM =
@@ -154,14 +152,14 @@ unfoldrM =
154 unf = UF.take 100 $ UF.unfoldrM genM
152 unf = UF.take 100 $ UF.unfoldrM genM
155 ll = length list
153 ll = length list
156 fs = if ll < 100 then ll + 1 else 100
154 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
158
156
159fromListM :: Property
157fromListM :: Property
160fromListM =
158fromListM =
161 property
159 property
162 $ \n ->
160 $ \n ->
163 let lst = Prelude.map (\x -> modify (+ 1) >> return x) n
161 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
165
163
166replicateM :: Property
164replicateM :: Property
167replicateM =
165replicateM =
@@ -169,11 +167,11 @@ replicateM =
169 $ \i ->
167 $ \i ->
170 let ns = max 0 i
168 let ns = max 0 i
171 seed = modify (+ 1) >> get
169 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]
173
171
174repeatM :: Bool
172repeatM :: Bool
175repeatM =
173repeatM =
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]
177
175
178iterateM :: Property
176iterateM :: Property
179iterateM =
177iterateM =
@@ -183,7 +181,7 @@ iterateM =
183 nextM x = modify (+ 1) >> return (nextA x)
181 nextM x = modify (+ 1) >> return (nextA x)
184 list = Prelude.take 100 $ List.iterate nextA 1
182 list = Prelude.take 100 $ List.iterate nextA 1
185 unf = UF.take 100 $ UF.iterateM nextM
183 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
187
185
188fromIndicesM :: Property
186fromIndicesM :: Property
189fromIndicesM =
187fromIndicesM =
@@ -193,7 +191,7 @@ fromIndicesM =
193 indFM x = modify (+ 1) >> return (indFA x)
191 indFM x = modify (+ 1) >> return (indFA x)
194 list = Prelude.take 100 $ Prelude.map indFA [1 ..]
192 list = Prelude.take 100 $ Prelude.map indFA [1 ..]
195 unf = UF.take 100 $ UF.fromIndicesM indFM
193 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
197
195
198enumerateFromStepNum :: Property
196enumerateFromStepNum :: Property
199enumerateFromStepNum =
197enumerateFromStepNum =
@@ -240,7 +238,7 @@ mapM =
240 fM x = modify (+ 1) >> return (fA x)
238 fM x = modify (+ 1) >> return (fA x)
241 unf = UF.mapM fM UF.fromList
239 unf = UF.mapM fM UF.fromList
242 mList = Prelude.map fA list
240 mList = Prelude.map fA list
243− in testUnfoldAD unf 0 (length list) list mList
241+ in testUnfoldMD unf 0 (length list) list mList
244
242
245mapMWithInput :: Property
243mapMWithInput :: Property
246mapMWithInput =
244mapMWithInput =
@@ -250,7 +248,7 @@ mapMWithInput =
250 fM x y = modify (+ 1) >> return (fA x y)
248 fM x y = modify (+ 1) >> return (fA x y)
251 unf = UF.mapMWithInput fM UF.fromList
249 unf = UF.mapMWithInput fM UF.fromList
252 mList = Prelude.map (fA list) list
250 mList = Prelude.map (fA list) list
253− in testUnfoldAD unf 0 (length list) list mList
251+ in testUnfoldMD unf 0 (length list) list mList
254
252
255take :: Property
253take :: Property
256take =
254take =
@@ -272,7 +270,7 @@ takeWhileM =
272 unf = UF.takeWhileM fM UF.fromList
270 unf = UF.takeWhileM fM UF.fromList
273 fL = Prelude.takeWhile (apply f) n
271 fL = Prelude.takeWhile (apply f) n
274 fS = Prelude.length fL
272 fS = Prelude.length fL
275− in testUnfoldAD unf 0 fS n fL
273+ in testUnfoldMD unf 0 fS n fL
276
274
277filterM :: Property
275filterM :: Property
278filterM =
276filterM =
@@ -285,7 +283,7 @@ filterM =
285 unf = UF.filterM fM UF.fromList
283 unf = UF.filterM fM UF.fromList
286 fL = Prelude.filter (apply f) n
284 fL = Prelude.filter (apply f) n
287 fS = Prelude.length fL
285 fS = Prelude.length fL
288− in testUnfoldAD unf 0 fS n fL
286+ in testUnfoldMD unf 0 fS n fL
289
287
290drop :: Property
288drop :: Property
291drop =
289drop =
@@ -306,7 +304,7 @@ dropWhileM =
306 unf = UF.dropWhileM fM UF.fromList
304 unf = UF.dropWhileM fM UF.fromList
307 fL = Prelude.dropWhile (apply f) n
305 fL = Prelude.dropWhile (apply f) n
308 fS = Prelude.length n - Prelude.length fL
306 fS = Prelude.length n - Prelude.length fL
309− in testUnfoldAD unf 0 fS n fL
307+ in testUnfoldMD unf 0 fS n fL
310
308
311-------------------------------------------------------------------------------
309-------------------------------------------------------------------------------
312-- Stream combination
310-- Stream combination
@@ -322,7 +320,7 @@ zipWithM =
322 fM a b = modify (+ 1) >> return (fA a b)
320 fM a b = modify (+ 1) >> return (fA a b)
323 unf = UF.zipWithM fM unf1 unf2
321 unf = UF.zipWithM fM unf1 unf2
324 lst = Prelude.zipWith fA [1 .. 10] [1 .. 20]
322 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
326
324
327concat :: Bool
325concat :: Bool
328concat =
326concat =
@@ -354,7 +352,7 @@ concatMapM =
354 unfOut = UF.enumerateFromToIntegral 10
352 unfOut = UF.enumerateFromToIntegral 10
355 unf = UF.concatMapM unfInF unfOut
353 unf = UF.concatMapM unfInF unfOut
356 list = List.concatMap listInF [1 .. 10]
354 list = List.concatMap listInF [1 .. 10]
357− in testUnfoldAD unf 0 110 1 list
355+ in testUnfoldMD unf 0 110 1 list
358
356
359-------------------------------------------------------------------------------
357-------------------------------------------------------------------------------
360-- Test groups
358-- Test groups
@@ -419,7 +417,6 @@ testTransformation =
419 -- prop "dropWhile" dropWhile
417 -- prop "dropWhile" dropWhile
420 prop "dropWhileM" dropWhileM
418 prop "dropWhileM" dropWhileM
421
419
422−
423testCombination :: Spec
420testCombination :: Spec
424testCombination =
421testCombination =
425 describe "Transformation"
422 describe "Transformation"
@@ -434,7 +431,6 @@ testCombination =
434 -- prop "apDiscardFst" apDiscardFst
431 -- prop "apDiscardFst" apDiscardFst
435 -- prop "apDiscardSnd" apDiscardSnd
432 -- prop "apDiscardSnd" apDiscardSnd
436
433
437−
438-------------------------------------------------------------------------------
434-------------------------------------------------------------------------------
439-- Main
435-- Main
440-------------------------------------------------------------------------------
436-------------------------------------------------------------------------------
@@ -448,14 +444,3 @@ main =
448 testGeneration
444 testGeneration
449 testTransformation
445 testTransformation
450 testCombination
446 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