Skip to content

Commit

Permalink
Smarter generation of sized sets
Browse files Browse the repository at this point in the history
Don't add/remove one element at a time. We know how many are missing/extra.
  • Loading branch information
UlfNorell committed Jan 31, 2023
1 parent e6efabb commit d0b7580
Showing 1 changed file with 4 additions and 2 deletions.
Expand Up @@ -44,8 +44,10 @@ fixSet numtrys size genA s = help numtrys s
else error ("Ran out of trys in fixSet: " ++ show trys)
help trys set = case compare (Set.size set) size of
EQ -> pure set
GT -> help (trys - 1) (Set.deleteMin set)
LT -> do a <- genA; help (trys - 1) (Set.insert a set)
GT -> help (trys - 1) (iterate Set.deleteMin set !! (Set.size set - size))
LT -> do
new <- Set.fromList <$> vectorOf (size - Set.size set) genA
help (trys - 1) (Set.union new set)

mapSized :: Ord a => Int -> Gen a -> Gen b -> Gen (Map a b)
mapSized size genA genB = setSized size genA >>= addRange
Expand Down

0 comments on commit d0b7580

Please sign in to comment.