Skip to content

Commit f693565

Browse files
committed
Add test for intersection
1 parent 1df3a89 commit f693565

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Data/HashMap/Internal.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ module Data.HashMap.Internal
110110

111111
-- * Debugging
112112
, valid
113-
, Validity
114-
, Error
113+
, Validity(..)
114+
, Error(..)
115115
, SubHash
116-
, SubHashPath
116+
, SubHashPath(..)
117117

118118
-- ** Internals used by the strict version
119119
, Hash

tests/Properties/HashMapLazy.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Test.Tasty.QuickCheck (testProperty)
3535
import qualified Data.Foldable as Foldable
3636
import qualified Data.List as List
3737
import qualified Test.QuickCheck as QC
38+
import qualified Data.HashMap.Internal as HMI
3839

3940
#if defined(STRICT)
4041
import Data.HashMap.Strict (HashMap)
@@ -87,7 +88,8 @@ mask :: Int
8788
mask = sum [bit n | n <- [0, 3, 8, 14, 61]]
8889

8990
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
9193

9294
keyToInt :: Key -> Int
9395
keyToInt (K h x) = h * fromEnum x
@@ -365,6 +367,9 @@ pIntersection xs ys =
365367
`eq_` HM.intersection (HM.fromList xs)
366368
$ ys
367369

370+
pIntersectionValid :: HashMap Key () -> HashMap Key () -> Property
371+
pIntersectionValid x y = HMI.valid (HM.intersection x y) === HMI.Valid
372+
368373
pIntersectionWith :: [(Key, Int)] -> [(Key, Int)] -> Property
369374
pIntersectionWith xs ys = M.intersectionWith (-) (M.fromList xs) `eq_`
370375
HM.intersectionWith (-) (HM.fromList xs) $ ys
@@ -575,6 +580,7 @@ tests =
575580
[ testProperty "difference" pDifference
576581
, testProperty "differenceWith" pDifferenceWith
577582
, testProperty "intersection" pIntersection
583+
, testProperty "intersection produces valid HashMap" pIntersectionValid
578584
, testProperty "intersectionWith" pIntersectionWith
579585
, testProperty "intersectionWithKey" pIntersectionWithKey
580586
]

0 commit comments

Comments
 (0)