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

constrained-generators: poor useability for interaction between forAll and dependsOn #4161

Open
MaximilianAlgehed opened this issue Mar 5, 2024 · 0 comments
Assignees
Labels
🕵️ testing enhancement New feature or request

Comments

@MaximilianAlgehed
Copy link
Collaborator

If you write the following code:

listSetRelation :: Spec BaseFn ([Int], Set Int)
listSetRelation = constrained' $ \xs ys ->
  [ forAll xs $ \ x ->
      [ x `member_` ys
      , 0 <. x
      ]
  , ys `dependsOn` xs
  ]

The intention is to generate a list of positive numbers, and then put them all in the set. However, what happens instead is that we generate a list of numbers, and then fail generation if any of them happen to be non-positive:

$> quickCheck $ checkCoverage $ prop_sound listSetRelation 
*** Failed! Insufficient coverage (after 100 tests):  
 8% successful

Only 8% successful, but expected 80%

However, you can rewrite the generator by splitting the forAll:

listSetRelation' :: Spec BaseFn ([Int], Set Int)
listSetRelation' = constrained' $ \xs ys ->
  [ forAll xs $ \ x -> 0 <. x
  , ys `dependsOn` xs
  , forAll xs $ \ x -> x `member_` ys
  ]

and quickCheck is happy as ever:

$> quickCheck $ checkCoverage $ prop_sound listSetRelation'
+++ OK, passed 100 tests (100% successful).

Now, if you understand how the system works this is something you can work around, but it would be nice for usability if we did the split automatically (it can be inferred from the dependsOn).

@MaximilianAlgehed MaximilianAlgehed self-assigned this Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🕵️ testing enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant