Skip to content

Commit

Permalink
Add testing function genNonEmptyDisjointMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed May 7, 2024
1 parent 2209fa2 commit ce5307f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/test-utils/src/Test/QuickCheck/Extra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module Test.QuickCheck.Extra
-- * Generating and shrinking maps
, genMapWith
, genMapFromKeysWith
, genNonEmptyDisjointMap
, shrinkMapToSubmaps
, shrinkMapWith
, shrinkMapValuesWith
Expand Down Expand Up @@ -634,6 +635,18 @@ genMapFromKeysWith :: Ord k => Gen v -> Set k -> Gen (Map k v)
genMapFromKeysWith genValue =
fmap Map.fromList . mapM (\k -> (k,) <$> genValue) . Set.toList

-- | Generates a non-empty 'Map' that is disjoint to an existing 'Map'.
--
-- The size of the resultant map depends on the implicit size parameter.
--
-- Caution: if the given key generator is incapable of generating keys that are
-- outside the existing map's domain, then this function will not terminate.
--
genNonEmptyDisjointMap :: Ord k => Gen k -> Gen v -> Map k v -> Gen (Map k v)
genNonEmptyDisjointMap genKey genValue existingMap =
genMapFromKeysWith genValue =<<
genNonEmptyDisjointSet genKey (Map.keysSet existingMap)

-- | Shrinks a 'Map' to list of proper submaps.
--
-- Satisfies the following property:
Expand Down

0 comments on commit ce5307f

Please sign in to comment.