@@ -3,6 +3,7 @@ module Tests.Vector (tests) where
3
3
import Boilerplater
4
4
import Utilities as Util
5
5
6
+ import Data.Functor.Identity
6
7
import qualified Data.Traversable as T (Traversable (.. ))
7
8
import Data.Foldable (Foldable (foldMap ))
8
9
@@ -113,7 +114,7 @@ testPolymorphicFunctions _ = $(testProperties [
113
114
114
115
-- Initialisation (FIXME)
115
116
'prop_empty, 'prop_singleton, 'prop_replicate,
116
- 'prop_generate, 'prop_iterateN,
117
+ 'prop_generate, 'prop_iterateN, 'prop_iterateNM,
117
118
118
119
-- Monadic initialisation (FIXME)
119
120
'prop_createT,
@@ -231,7 +232,8 @@ testPolymorphicFunctions _ = $(testProperties [
231
232
= (\ n _ -> n < 1000 ) ===> V. generate `eq` Util. generate
232
233
prop_iterateN :: P (Int -> (a -> a ) -> a -> v a )
233
234
= (\ n _ _ -> n < 1000 ) ===> V. iterateN `eq` (\ n f -> take n . iterate f)
234
-
235
+ prop_iterateNM :: P (Int -> (a -> Writer [Int ] a ) -> a -> Writer [Int ] (v a ))
236
+ = (\ n _ _ -> n < 1000 ) ===> V. iterateNM `eq` Util. iterateNM
235
237
prop_createT :: P ((a , v a ) -> (a , v a ))
236
238
prop_createT = (\ v -> V. createT (T. mapM V. thaw v)) `eq` id
237
239
@@ -433,10 +435,18 @@ testPolymorphicFunctions _ = $(testProperties [
433
435
limitUnfolds f (theirs, ours) | ours >= 0
434
436
, Just (out, theirs') <- f theirs = Just (out, (theirs', ours - 1 ))
435
437
| otherwise = Nothing
438
+ limitUnfoldsM f (theirs, ours)
439
+ | ours >= 0 = do r <- f theirs
440
+ return $ (\ (a,b) -> (a,(b,ours - 1 ))) `fmap` r
441
+ | otherwise = return Nothing
442
+
443
+
436
444
prop_unfoldr :: P (Int -> (Int -> Maybe (a ,Int )) -> Int -> v a )
437
445
= (\ n f a -> V. unfoldr (limitUnfolds f) (a, n))
438
446
`eq` (\ n f a -> unfoldr (limitUnfolds f) (a, n))
439
-
447
+ prop_unfoldrM :: P (Int -> (Int -> Writer [Int ] (Maybe (a ,Int ))) -> Int -> Writer [Int ] (v a ))
448
+ = (\ n f a -> V. unfoldrM (limitUnfoldsM f) (a,n))
449
+ `eq` (\ n f a -> Util. unfoldrM (limitUnfoldsM f) (a, n))
440
450
prop_constructN = \ f -> forAll (choose (0 ,20 )) $ \ n -> unP prop n f
441
451
where
442
452
prop :: P (Int -> (v a -> a ) -> v a ) = V. constructN `eq` constructN []
0 commit comments