@@ -31,9 +31,12 @@ import Test.QuickCheck.Function
31-- Helper functions
31-- Helper functions
32-------------------------------------------------------------------------------
32-------------------------------------------------------------------------------
34+-- | @testUnfoldM unf seed initial final xs@, runs an unfold under state monad
35+-- using @initial@ as the initial state. @final@ is the expected state after
36+-- running it and @xs@ is the list of elements the stream must produce.
34testUnfoldM ::
37testUnfoldM ::
35− (Eq s, Eq b) => Unfold (State s) a b -> s -> s -> a -> [b] -> Bool
38+ (Eq s, Eq b) => Unfold (State s) a b -> a -> s -> s -> [b] -> Bool
36−testUnfoldM unf si sf seed lst = evalState action si
39+testUnfoldM unf seed si sf lst = evalState action si
@@ -42,9 +45,10 @@ testUnfoldM unf si sf seed lst = evalState action si
43 return $ x == lst && y == sf
46 return $ x == lst && y == sf
45−testUnfoldMD :: Unfold (State Int) a Int -> Int -> Int -> a -> [Int] -> Bool
48+testUnfoldMD :: Unfold (State Int) a Int -> a -> Int -> Int -> [Int] -> Bool
46testUnfoldMD = testUnfoldM
49testUnfoldMD = testUnfoldM
51+-- | This is similar to 'testUnfoldM' but without the state monad.
48testUnfold :: Eq b => Unfold Identity a b -> a -> [b] -> Bool
52testUnfold :: Eq b => Unfold Identity a b -> a -> [b] -> Bool
49testUnfold unf seed lst = runIdentity action
53testUnfold unf seed lst = runIdentity action
@@ -64,7 +68,7 @@ testUnfoldD = testUnfold
64lmapM :: Bool
68lmapM :: Bool
66 let unf = UF.lmapM (\x -> modify (+ 1) >> return x) (UF.singleton id)
70 let unf = UF.lmapM (\x -> modify (+ 1) >> return x) (UF.singleton id)
67− in testUnfoldMD unf 0 1 1 [1]
71+ in testUnfoldMD unf 1 0 1 [1]
69supply :: Bool
73supply :: Bool
@@ -119,28 +123,28 @@ fromStreamK =
119nilM :: Bool
123nilM :: Bool
121 let unf = UF.nilM put
125 let unf = UF.nilM put
122− in testUnfoldMD unf 0 1 1 []
126+ in testUnfoldMD unf 1 0 1 []
124consM :: Bool
128consM :: Bool
126 let cns = UF.consM (\a -> modify (+ a) >> get)
130 let cns = UF.consM (\a -> modify (+ a) >> get)
127 unf = cns $ cns $ UF.nilM $ \a -> modify (+ a)
131 unf = cns $ cns $ UF.nilM $ \a -> modify (+ a)
128− in testUnfoldMD unf 0 3 1 [1, 2]
132+ in testUnfoldMD unf 1 0 3 [1, 2]
130effect :: Bool
134effect :: Bool
132 let unf = UF.effect (modify (+ 1) >> get)
136 let unf = UF.effect (modify (+ 1) >> get)
133− in testUnfoldMD unf 0 1 undefined [1]
137+ in testUnfoldMD unf undefined 0 1 [1]
135singletonM :: Bool
139singletonM :: Bool
136singletonM =
140singletonM =
137 let unf = UF.singletonM (\a -> modify (+ a) >> get)
141 let unf = UF.singletonM (\a -> modify (+ a) >> get)
138− in testUnfoldMD unf 0 1 1 [1]
142+ in testUnfoldMD unf 1 0 1 [1]
140const :: Bool
144const :: Bool
142 let unf = UF.take 10 $ UF.const (modify (+ 1) >> get)
146 let unf = UF.take 10 $ UF.const (modify (+ 1) >> get)
143− in testUnfoldMD unf 0 10 (0 :: Int) [1 .. 10]
147+ in testUnfoldMD unf (0 :: Int) 0 10 [1 .. 10]
145unfoldrM :: Property
149unfoldrM :: Property
146unfoldrM =
150unfoldrM =
@@ -152,14 +156,14 @@ unfoldrM =
152 unf = UF.take 100 $ UF.unfoldrM genM
156 unf = UF.take 100 $ UF.unfoldrM genM
153 ll = length list
157 ll = length list
154 fs = if ll < 100 then ll + 1 else 100
158 fs = if ll < 100 then ll + 1 else 100
155− in testUnfoldMD unf 0 fs 1 list
159+ in testUnfoldMD unf 1 0 fs list
157fromListM :: Property
161fromListM :: Property
158fromListM =
162fromListM =
161 let lst = Prelude.map (\x -> modify (+ 1) >> return x) n
165 let lst = Prelude.map (\x -> modify (+ 1) >> return x) n
162− in testUnfoldMD UF.fromListM 0 (length n) lst n
166+ in testUnfoldMD UF.fromListM lst 0 (length n) n
164replicateM :: Property
168replicateM :: Property
165replicateM =
169replicateM =
@@ -167,11 +171,11 @@ replicateM =
168 let ns = max 0 i
172 let ns = max 0 i
169 seed = modify (+ 1) >> get
173 seed = modify (+ 1) >> get
170− in testUnfoldMD (UF.replicateM i) 0 ns seed [1 .. i]
174+ in testUnfoldMD (UF.replicateM i) seed 0 ns [1 .. i]
172repeatM :: Bool
176repeatM :: Bool
174− testUnfoldMD (UF.take 10 UF.repeatM) 0 10 (modify (+ 1) >> get) [1 .. 10]
178+ testUnfoldMD (UF.take 10 UF.repeatM) (modify (+ 1) >> get) 0 10 [1 .. 10]
176iterateM :: Property
180iterateM :: Property
177iterateM =
181iterateM =
@@ -181,7 +185,7 @@ iterateM =
181 nextM x = modify (+ 1) >> return (nextA x)
185 nextM x = modify (+ 1) >> return (nextA x)
182 list = Prelude.take 100 $ List.iterate nextA 1
186 list = Prelude.take 100 $ List.iterate nextA 1
183 unf = UF.take 100 $ UF.iterateM nextM
187 unf = UF.take 100 $ UF.iterateM nextM
184− in testUnfoldMD unf 0 110 (modify (+ 10) >> return 1) list
188+ in testUnfoldMD unf (modify (+ 10) >> return 1) 0 110 list
186fromIndicesM :: Property
190fromIndicesM :: Property
187fromIndicesM =
191fromIndicesM =
@@ -191,7 +195,7 @@ fromIndicesM =
191 indFM x = modify (+ 1) >> return (indFA x)
195 indFM x = modify (+ 1) >> return (indFA x)
192 list = Prelude.take 100 $ Prelude.map indFA [1 ..]
196 list = Prelude.take 100 $ Prelude.map indFA [1 ..]
193 unf = UF.take 100 $ UF.fromIndicesM indFM
197 unf = UF.take 100 $ UF.fromIndicesM indFM
194− in testUnfoldMD unf 0 (length list) 1 list
198+ in testUnfoldMD unf 1 0 (length list) list
196enumerateFromStepNum :: Property
200enumerateFromStepNum :: Property
197enumerateFromStepNum =
201enumerateFromStepNum =
@@ -238,7 +242,7 @@ mapM =
238 fM x = modify (+ 1) >> return (fA x)
242 fM x = modify (+ 1) >> return (fA x)
239 unf = UF.mapM fM UF.fromList
243 unf = UF.mapM fM UF.fromList
240 mList = Prelude.map fA list
244 mList = Prelude.map fA list
241− in testUnfoldMD unf 0 (length list) list mList
245+ in testUnfoldMD unf list 0 (length list) mList
243mapMWithInput :: Property
247mapMWithInput :: Property
244mapMWithInput =
248mapMWithInput =
@@ -248,7 +252,7 @@ mapMWithInput =
248 fM x y = modify (+ 1) >> return (fA x y)
252 fM x y = modify (+ 1) >> return (fA x y)
249 unf = UF.mapMWithInput fM UF.fromList
253 unf = UF.mapMWithInput fM UF.fromList
250 mList = Prelude.map (fA list) list
254 mList = Prelude.map (fA list) list
251− in testUnfoldMD unf 0 (length list) list mList
255+ in testUnfoldMD unf list 0 (length list) mList
253take :: Property
257take :: Property
@@ -270,7 +274,7 @@ takeWhileM =
270 unf = UF.takeWhileM fM UF.fromList
274 unf = UF.takeWhileM fM UF.fromList
271 fL = Prelude.takeWhile (apply f) n
275 fL = Prelude.takeWhile (apply f) n
272 fS = Prelude.length fL
276 fS = Prelude.length fL
273− in testUnfoldMD unf 0 fS n fL
277+ in testUnfoldMD unf n 0 fS fL
275filterM :: Property
279filterM :: Property
@@ -283,7 +287,7 @@ filterM =
283 unf = UF.filterM fM UF.fromList
287 unf = UF.filterM fM UF.fromList
284 fL = Prelude.filter (apply f) n
288 fL = Prelude.filter (apply f) n
285 fS = Prelude.length fL
289 fS = Prelude.length fL
286− in testUnfoldMD unf 0 fS n fL
290+ in testUnfoldMD unf n 0 fS fL
288drop :: Property
292drop :: Property
@@ -304,7 +308,7 @@ dropWhileM =
304 unf = UF.dropWhileM fM UF.fromList
308 unf = UF.dropWhileM fM UF.fromList
305 fL = Prelude.dropWhile (apply f) n
309 fL = Prelude.dropWhile (apply f) n
306 fS = Prelude.length n - Prelude.length fL
310 fS = Prelude.length n - Prelude.length fL
307− in testUnfoldMD unf 0 fS n fL
311+ in testUnfoldMD unf n 0 fS fL
309-------------------------------------------------------------------------------
313-------------------------------------------------------------------------------
310-- Stream combination
314-- Stream combination
@@ -320,7 +324,7 @@ zipWithM =
320 fM a b = modify (+ 1) >> return (fA a b)
324 fM a b = modify (+ 1) >> return (fA a b)
321 unf = UF.zipWithM fM unf1 unf2
325 unf = UF.zipWithM fM unf1 unf2
322 lst = Prelude.zipWith fA [1 .. 10] [1 .. 20]
326 lst = Prelude.zipWith fA [1 .. 10] [1 .. 20]
323− in testUnfoldMD unf 0 10 (1, 1) lst
327+ in testUnfoldMD unf (1, 1) 0 10 lst
325concat :: Bool
329concat :: Bool
@@ -352,7 +356,7 @@ concatMapM =
352 unfOut = UF.enumerateFromToIntegral 10
356 unfOut = UF.enumerateFromToIntegral 10
353 unf = UF.concatMapM unfInF unfOut
357 unf = UF.concatMapM unfInF unfOut
354 list = List.concatMap listInF [1 .. 10]
358 list = List.concatMap listInF [1 .. 10]
355− in testUnfoldMD unf 0 110 1 list
359+ in testUnfoldMD unf 1 0 110 list
357-------------------------------------------------------------------------------
361-------------------------------------------------------------------------------
358-- Test groups
362-- Test groups