Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower requirement for coverage percent in genericCoverTable #386

Merged
merged 1 commit into from
Jun 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions hydra-test-utils/src/Test/Hydra/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,17 @@ genericCoverTable xs =
coverTable tableName requirements . tabulate tableName (show <$> xs)
where
tableName = show $ typeRep (Proxy :: Proxy a)
requirements =
[ (show lbl, weight)
| let weight = fromRational (100 % (3 * lengthI allLabels))
, lbl <- allLabels
]
requirements = [(show lbl, percent) | lbl <- allLabels]
-- NOTE: We lower the requirement of minimum coverage depending on the number
-- of labels, e.g. 3 labels would have an ideal, uniform distribution of 33%
-- each, but we only require 33% / 3 = 11%. With 10 labels evenly distributed
-- means 10%, but getting 10% / 3 = 3% would be much harder to achieve with
-- this bigger set to draw from. Hence we only expect 10% / 10 = 1% coverage
-- in that case and consequently should reasonable numbers of tests required.
percent = fromRational (100 % (numberOfLabels * numberOfLabels))
allLabels = enumerate :: [a]
enumerate = [minBound .. maxBound]
lengthI = toInteger . length
numberOfLabels = toInteger $ length allLabels

-- | Shorthand for using 2 generated values in a property.
forAll2 ::
Expand Down