-
Notifications
You must be signed in to change notification settings - Fork 44
QCheck2.Gen: enforce naming consistency for type int #243
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I like the direction of this!
I understand that this first PR is focused on int*/nat*-generator names for QCheck2 which is fine IMO. As to distribution, I still think having int be uniform over its full range and nat not being so should be addressed (probably separately). We'll also need to have a separate look at
float*,string*, ... generators in QCheck2- a potential similar pass over QCheck(1) generators (it would be nice to align them, e.g., for a 0.2.0 release)
Overall, in #223 and elsewhere we started to converge on a set of design principles.
Here's a summary for convenience:
- generator names should align with type names (
bool,char, ...list,option) - to be as predictable as possible - we should have short, unparameterized generators (
int,string, ...) to lower the barrier to entry - consistent suffixes are used for more specialized generators (
_pos,_neg,_small,_big,_of, ...) - we include a few shorthand names for convenience (
int_pos->nat,option->opt, ...) - overall we aim to be as consistent as possible
A few remarks:
- IMO
int_pos_boundbecomes heavy to read and write which I noticed while reading the code changes. I propose to include the shorthandnat_boundand use that internally. - there's a challenge with the signature
val int_pos : ?origin : int -> int tas the optional parameter is actually required (recall other examples in #161 and #162):One way to address this is by adding an extra# QCheck2.(Test.make Gen.pint (fun i -> i>0));; Error: This expression has type ?origin:int -> int QCheck2.Gen.t but an expression was expected of type 'a QCheck2.Gen.t
unitparameter to signal "end-of-args". Another option is to avoid the optional parameter and instead haveint_postake no argument and use the default0origin (after all the library code uses~origin:0throughout) and have anotherint_pos_originthat lets users configure the shrinking destination.
| @since NEXT_RELEASE *) | ||
|
|
||
| val int_big : int t | ||
| (** Big SIGNED integers, based on {!nat_small} substraced to [Int.max_int] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
substraced?
| if b | ||
| then pint ~origin:0 >|= (fun n -> - n - 1) | ||
| else pint ~origin:0 | ||
| let int_corners () : int t = graft_corners nat int_corners_list () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems inconsistent that int_corners uses nat once it has gotten through the list of corner cases?
|
|
||
| +++ Stats for int_dist_empty_bucket ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
|
||
| stats dist: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change of distribution?
First PR of attempting to tackle #223 in multiple smaller mrs. It should facilitate reviews.
Notice that I move code around so
int tgenerators are close to each other both in the implementation and interface.Naturals
Generators becomes:
Deprecated natural generators are:
Classic generators
Generators becomes:
Deprecated generators are:
I then ran
On each deprecated generator to see if all occurrences (expected the deprecation cycle) were removed.
TODO
int_poshas?originbutint_negdoes not, makes it weird.Question
Now that we have this smaller PR, we can question the existence of
natand/orint_pos@jmid you said in the last PR
I think we could change
nat*to become kind of an alias toint_pos*. That'd mean thatint_poswould be removed and underlying generators for naturals will become uniform over OCaml positive integers rather than "non-uniform and at most 10.000"