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

Deprecated Gen.small_int changed distribution #184

Open
jmid opened this issue Sep 22, 2021 · 0 comments
Open

Deprecated Gen.small_int changed distribution #184

jmid opened this issue Sep 22, 2021 · 0 comments

Comments

@jmid
Copy link
Collaborator

jmid commented Sep 22, 2021

I just noticed something about the deprecated Gen.small_int...

First of all:

  • It is aliased to Gen.small_nat
  • It is marked with a note concerning backwards compatibility:

    qcheck/src/core/QCheck.ml

    Lines 184 to 186 in b065a81

    (* NOTE: we keep this alias to not break code that uses [small_int]
    for sizes of strings, arrays, etc. *)
    let small_int = small_nat

Unfortunately Gen.small_nat changed distribution from the interval [0;10000[ to the interval [0;100[ with QCheck version 0.10. Since version 0.5.2 Gen.small_int and Gen.small_nat's distributions were caused by a chain of aliases: Gen.small_int = Gen.small_nat = Gen.nat:

qcheck/src/core/QCheck.ml

Lines 97 to 105 in 52e4193

(* natural number generator *)
let nat st =
let p = RS.float st 1. in
if p < 0.5 then RS.int st 10
else if p < 0.75 then RS.int st 100
else if p < 0.95 then RS.int st 1_000
else RS.int st 10_000
let small_nat = nat

QCheck version 0.10, introduced the Gen.small_nat / Gen.nat / Gen.big_nat distinction and broke the last alias, thus

  • changing Gen.small_nats distribution explicitly
  • changing Gen.small_ints distribution as a side-effect:
    let small_nat st =
    let p = RS.float st 1. in
    if p < 0.75 then RS.int st 10 else RS.int st 100

A bit of digging tells me Gen.small_int had the distribution in the interval [0;10000[ since version 0.5, it was briefly changed in 0.5.1 to output negative ints (#10), and then restored in 0.5.2 which also introduced the deprecation.

I found out, because rerunning some of my pre-0.10 code using Gen.small_int didn't find the expected counterexamples anymore.

With QCheck tests depending on distributions, a narrower distribution imply that test inputs are confined to a smaller subset.
Potentially this could mean bugs flying under the radar...
If someone is indeed using Gen.small_int for sizes of strings, lists, etc. as the compatibility note says, an upgrade from pre-0.10 means they silently started confining their tests to, e.g., strings of size [0;100[ compared to the earlier [0;10000[.

I see a couple of possibilities from here:

  • do nothing - after all, this change in distribution was introduced with 0.10 in 2019, keeping this issue for documentation
  • make Gen.small_int an alias to Gen.nat: let small_int = nat
    thus restoring the old distribution in the interest of backwards compatibility
  • remove Gen.small_int: it is unclear whether anyone else noticed. Also: it has been deprecated since January 2017.
    Removing it would force users to notice and act accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant