Skip to content

Commit d036de6

Browse files
Add property tests for the validity of traversal functions. (#226)
2 parents 9c1d425 + 4bc4d13 commit d036de6

File tree

1 file changed

+94
-1
lines changed

1 file changed

+94
-1
lines changed

src/test/Data/MonoidMap/ValiditySpec.hs

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import Data.Data
1717
( Proxy (Proxy) )
1818
import Data.Function
1919
( (&) )
20+
import Data.Functor.Identity
21+
( Identity )
2022
import Data.Group
2123
( Group )
2224
import Data.Map.Strict
@@ -63,8 +65,17 @@ import Test.Common
6365
import Test.Hspec
6466
( Spec, it )
6567
import Test.QuickCheck
66-
( Fun, Property, applyFun, applyFun2, conjoin, counterexample, cover )
68+
( Fun
69+
, Property
70+
, applyFun
71+
, applyFun2
72+
, applyFun3
73+
, conjoin
74+
, counterexample
75+
, cover
76+
)
6777

78+
import qualified Data.Foldable as F
6879
import qualified Data.Map.Strict as Map
6980
import qualified Data.Monoid.Null as Null
7081
import qualified Data.MonoidMap as MonoidMap
@@ -181,6 +192,24 @@ specValidMonoidNull = makeSpec $ do
181192
it "propValid_mapKeysWith" $
182193
propValid_mapKeysWith
183194
@k @v & property
195+
it "propValid_mapAccumL" $
196+
propValid_mapAccumL
197+
@k @v & property
198+
it "propValid_mapAccumR" $
199+
propValid_mapAccumR
200+
@k @v & property
201+
it "propValid_mapAccumLWithKey" $
202+
propValid_mapAccumLWithKey
203+
@k @v & property
204+
it "propValid_mapAccumRWithKey" $
205+
propValid_mapAccumRWithKey
206+
@k @v & property
207+
it "propValid_traverse" $
208+
propValid_traverse
209+
@k @v & property
210+
it "propValid_traverseWithKey" $
211+
propValid_traverseWithKey
212+
@k @v & property
184213
it "propValid_intersectionWith" $
185214
propValid_intersectionWith
186215
@k @v & property
@@ -475,6 +504,70 @@ propValid_mapKeysWith
475504
propValid_mapKeysWith (applyFun2 -> f) (applyFun -> g) m =
476505
propValid (MonoidMap.mapKeysWith f g m)
477506

507+
propValid_mapAccumL
508+
:: forall k v s. s ~ Int
509+
=> Test k v
510+
=> Fun (s, v) (s, v)
511+
-> s
512+
-> MonoidMap k v
513+
-> Property
514+
propValid_mapAccumL (applyFun2 -> f) s m =
515+
propValid $ snd $ MonoidMap.mapAccumL f s m
516+
517+
propValid_mapAccumR
518+
:: forall k v s. s ~ Int
519+
=> Test k v
520+
=> Fun (s, v) (s, v)
521+
-> s
522+
-> MonoidMap k v
523+
-> Property
524+
propValid_mapAccumR (applyFun2 -> f) s m =
525+
propValid $ snd $ MonoidMap.mapAccumR f s m
526+
527+
propValid_mapAccumLWithKey
528+
:: forall k v s. s ~ Int
529+
=> Test k v
530+
=> Fun (s, k, v) (s, v)
531+
-> s
532+
-> MonoidMap k v
533+
-> Property
534+
propValid_mapAccumLWithKey (applyFun3 -> f) s m =
535+
propValid $ snd $ MonoidMap.mapAccumLWithKey f s m
536+
537+
propValid_mapAccumRWithKey
538+
:: forall k v s. s ~ Int
539+
=> Test k v
540+
=> Fun (s, k, v) (s, v)
541+
-> s
542+
-> MonoidMap k v
543+
-> Property
544+
propValid_mapAccumRWithKey (applyFun3 -> f) s m =
545+
propValid $ snd $ MonoidMap.mapAccumRWithKey f s m
546+
547+
propValid_traverse
548+
:: forall k v t. (Applicative t, Foldable t, Test k v)
549+
=> t ~ Identity
550+
=> Fun v (t v)
551+
-> MonoidMap k v
552+
-> Property
553+
propValid_traverse (applyFun -> f) m
554+
= conjoin
555+
$ fmap propValid
556+
$ F.toList @t
557+
$ MonoidMap.traverse f m
558+
559+
propValid_traverseWithKey
560+
:: forall k v t. (Applicative t, Foldable t, Test k v)
561+
=> t ~ Identity
562+
=> Fun (k, v) (t v)
563+
-> MonoidMap k v
564+
-> Property
565+
propValid_traverseWithKey (applyFun2 -> f) m
566+
= conjoin
567+
$ fmap propValid
568+
$ F.toList @t
569+
$ MonoidMap.traverseWithKey f m
570+
478571
propValid_intersection
479572
:: (Test k v, GCDMonoid v) => MonoidMap k v -> MonoidMap k v -> Property
480573
propValid_intersection m1 m2 =

0 commit comments

Comments
 (0)