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

Usage of Double_0_1 for arbitrary randomness #566

Open
wenkokke opened this issue Feb 7, 2025 · 0 comments
Open

Usage of Double_0_1 for arbitrary randomness #566

wenkokke opened this issue Feb 7, 2025 · 0 comments

Comments

@wenkokke
Copy link
Collaborator

wenkokke commented Feb 7, 2025

The current test suite uses the Double_0_1 type, which has an Arbitrary instance that generates Double values between 0 and 1. This is used whenever some dynamic randomness is needed in QuickCheck tests, e.g., picking an arbitrary file from the filesystem, where the list of files cannot be statically known.

The corresponding implementation of shrink is defined in terms of shrink for Double, which uses shrinkDecimal, which picks numbers with a shorter decimal representation. I think that's probably the wrong behaviour for this use-case. If this were to be biased towards smaller numbers, it would cause us to select files from earlier in the list of files or bits from earlier in the file. Neither of these are really what we want when shrinking. However, it's not even biased to smaller numbers, but to less-precise numbers, which... I can't really predict what that's even doing in this case?

If we want to clean up the Double_0_1 trick, we would have two options:

  • Arbitrary generators. We can add a wrapper around QuickCheck's generators and permit tests to ask for an arbitrary random generator—either by returning the actual generator or by generating a random integer seed for a new generator. In such cases, we should not permit any shrinking, as there is no well-defined notion of shrinking randomness.
  • Embrace index selection. We can embrace that this is only used for index selection and generate a whole number that we interpret dynamically modulo the list length. In this case, we would have more control over the semantics of shrinking, though I would argue that we still don't want to allow any shrinking. (Due to the interpretation modulo the list length, we wouldn't be able to ensure that it causes us to select earlier files.)
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

1 participant