@@ -35,6 +35,7 @@ import Test.Tasty.QuickCheck (testProperty)
35
35
import qualified Data.Foldable as Foldable
36
36
import qualified Data.List as List
37
37
import qualified Test.QuickCheck as QC
38
+ import qualified Data.HashMap.Internal as HMI
38
39
39
40
#if defined(STRICT)
40
41
import Data.HashMap.Strict (HashMap )
@@ -87,7 +88,8 @@ mask :: Int
87
88
mask = sum [bit n | n <- [0 , 3 , 8 , 14 , 61 ]]
88
89
89
90
instance (Eq k , Hashable k , Arbitrary k , Arbitrary v ) => Arbitrary (HashMap k v ) where
90
- arbitrary = fmap (HM. fromList) arbitrary
91
+ arbitrary = HM. fromList <$> arbitrary
92
+ shrink = fmap HM. fromList . shrink . HM. toList
91
93
92
94
keyToInt :: Key -> Int
93
95
keyToInt (K h x) = h * fromEnum x
@@ -365,6 +367,9 @@ pIntersection xs ys =
365
367
`eq_` HM. intersection (HM. fromList xs)
366
368
$ ys
367
369
370
+ pIntersectionValid :: HashMap Key () -> HashMap Key () -> Property
371
+ pIntersectionValid x y = HMI. valid (HM. intersection x y) === HMI. Valid
372
+
368
373
pIntersectionWith :: [(Key , Int )] -> [(Key , Int )] -> Property
369
374
pIntersectionWith xs ys = M. intersectionWith (-) (M. fromList xs) `eq_`
370
375
HM. intersectionWith (-) (HM. fromList xs) $ ys
@@ -575,6 +580,7 @@ tests =
575
580
[ testProperty " difference" pDifference
576
581
, testProperty " differenceWith" pDifferenceWith
577
582
, testProperty " intersection" pIntersection
583
+ , testProperty " intersection produces valid HashMap" pIntersectionValid
578
584
, testProperty " intersectionWith" pIntersectionWith
579
585
, testProperty " intersectionWithKey" pIntersectionWithKey
580
586
]
0 commit comments