Skip to content

Add missing QCheck2 float tests and fix QCheck2.Gen.exponential shrinker#382

Merged
jmid merged 6 commits intoc-cube:mainfrom
jmid:more-qcheck2-float-tests
Dec 11, 2025
Merged

Add missing QCheck2 float tests and fix QCheck2.Gen.exponential shrinker#382
jmid merged 6 commits intoc-cube:mainfrom
jmid:more-qcheck2-float-tests

Conversation

@jmid
Copy link
Collaborator

@jmid jmid commented Dec 11, 2025

As part of #367 I discovered that QCheck2 was missing a bunch of expect tests for float compared to QCheck.

This PR therefore adds those tests as mostly a copy-paste job.

Adding the tests however turned out to be a good idea, because it revealed that QCheck2.Gen.exponential (added in 0.23) and the newly added QCheck2.Gen.float_exp from #367 (making exponential an alias) would shrink to infinity - not something an end-user would expect of a generator with an exponential distribution...

The reason is that integrated shrinking Gen.maps the shrinking candidate 0. to infinity.
To fix it, I've therefore decided to just let float_exp's resulting generator shrink towards 0. rather than having to special-case 0. in the mapped function (or as a shrink invariant).

The PR documents the situation

  • 3908e7c adds the missing tests
  • cf776d0 updates and documents the unwanted expect test outputs
  • 8399c30 moves QCheck2.ml definitions to prepare for the fix
  • e559a96 contains the actual fix
  • 6791cc1 updates the expect test outputs to reflect the fix

@jmid jmid changed the title Add missing QCheck2 float tests Add missing QCheck2 float tests and fix QCheck2.Gen.exponential shrinker Dec 11, 2025
@jmid jmid merged commit 2786121 into c-cube:main Dec 11, 2025
24 checks passed
@jmid jmid deleted the more-qcheck2-float-tests branch December 11, 2025 11:23
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

Successfully merging this pull request may close these issues.

1 participant