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

cover does not work when actual percentage 0 #26

Closed
nh2 opened this issue Oct 13, 2014 · 2 comments
Closed

cover does not work when actual percentage 0 #26

nh2 opened this issue Oct 13, 2014 · 2 comments

Comments

@nh2
Copy link
Contributor

nh2 commented Oct 13, 2014

If you write with cover: "I want that x% (e.g. 100%) of my generated characters are a", and no as are generated at all, cover doesn't warn you when it should.

Example 1:

quickCheck $ forAll (return 'b') $ \c -> cover (c == 'a') 100 "a" True
+++ OK, passed 100 tests.

The problem is that quickcheck only considers stamps that actually occur.

This also happens if the percentage is very small so that with high probability no suitable sample is found; example 2:

> quickCheck $ forAll arbitrary $ \c -> cover (c == 'a') 100 "a" True
+++ OK, passed 100 tests (only 1% a; not 100%).
> quickCheck $ forAll arbitrary $ \c -> cover (c == 'a') 100 "a" True
+++ OK, passed 100 tests.

The location where cover is handled is covers in success :: State -> IO () in QuickCheck.Test.

@nh2
Copy link
Contributor Author

nh2 commented Oct 13, 2014

Our temporary workaround for this: http://git.ganeti.org/?p=ganeti.git;a=commitdiff;h=8a1b6f9bc3d63c101404bfa320887309a890a9a7

-- | A stable version of QuickCheck's `cover`. In its current implementation,
-- cover will not detect insufficient coverage if the actual coverage in the
-- sample is 0. Work around this by lifting the probability to at least
-- 10 percent.
-- The underlying issue is tracked at
-- https://github.com/nick8325/quickcheck/issues/26
stableCover :: Testable prop => Bool -> Int -> String -> prop -> Property
stableCover pred percent label prop =
  let newlabel = "(stabilized to at least 10%) " ++ label
  in forAll (frequency [(1, return True), (9, return False)]) $ \ basechance ->
     cover (basechance || pred) (10 + (percent * 9 `div` 10)) newlabel prop

@nick8325
Copy link
Owner

nick8325 commented Jan 8, 2015

Thanks for the bug report, this should be fixed now!

@nick8325 nick8325 closed this as completed Jan 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants