Skip to content

Commit

Permalink
Add shrinker function shrinkMapToSubmaps.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed May 3, 2024
1 parent cdc59b9 commit 06fd951
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/test-utils/src/Test/QuickCheck/Extra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module Test.QuickCheck.Extra
-- * Generating and shrinking maps
, genMapWith
, genMapFromKeysWith
, shrinkMapToSubmaps
, shrinkMapWith
, shrinkMapValuesWith

Expand Down Expand Up @@ -610,6 +611,21 @@ genMapFromKeysWith :: Ord k => Gen v -> Set k -> Gen (Map k v)
genMapFromKeysWith genValue =
fmap Map.fromList . mapM (\k -> (k,) <$> genValue) . Set.toList

-- | Shrinks a 'Map' to list of proper submaps.
--
-- Satisfies the following property:
--
-- @
-- all (`Map.isProperSubmapOf` m) (shrinkMapToSubmaps m)
-- @
--
shrinkMapToSubmaps :: Ord k => Map k v -> [Map k v]
shrinkMapToSubmaps =
shrinkMapBy Map.fromList Map.toList shrinkListToSublist
where
shrinkListToSublist :: [a] -> [[a]]
shrinkListToSublist = shrinkList (const [])

-- | Shrinks a 'Map' with the given key and value shrinking functions.
--
shrinkMapWith
Expand Down

0 comments on commit 06fd951

Please sign in to comment.