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

Add edge cases to Gen.choose[BigInt] #993

Open
DirkToewe opened this issue Jul 29, 2023 · 0 comments
Open

Add edge cases to Gen.choose[BigInt] #993

DirkToewe opened this issue Jul 29, 2023 · 0 comments

Comments

@DirkToewe
Copy link

The following property test should clearly fail:

object ScalaCheckCheck extends Properties("Gen.choose[BigInt]"):

  override def overrideParameters( params: Parameters ): Parameters
    = params.withMinSuccessfulTests(1_000_000)

  property("covers all bit lengths") = forAll(
    Gen.choose[BigInt](0, BigInt(1) << 64)
  )( _.bitLength > 32 )

end ScalaCheckCheck

But since Gen.choose[BigInt] samples uniformly, the chances of the test above (correctly) failing are less than 3 in 10_000.
The documentation does not mandate that Gen.choose[BigInt] samples uniformly, so I propose adding the following edge cases and sampling methods to Choose[BigInt]:

  1. {0, ±1, ±2, ± Byte.MaxValue ± 1, ± Short.MaxValue ± 1, ...} (provided they are in range)
  2. Randomly chosen small primes or probable primes
  3. Products of 2 or 3 small/probable primes
  4. Random Powers of 2
  5. "Sparse" BigInt values with uniformly random bitLength and uniformly random number of 1-bits

If these additions are acceptable, I would be willing to work on an according PR.

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