-
Notifications
You must be signed in to change notification settings - Fork 36
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
QCheck2.Gen: enforce naming consistency for type int #243
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_bound
becomes heavy to read and write which I noticed while reading the code changes. I propose to include the shorthandnat_bound
and use that internally. - there's a challenge with the signature
val int_pos : ?origin : int -> int t
as the optional parameter is actually required (recall other examples in FixQCheck2.Gen.small_string
impl to match interface and documentation #161 andQCheck2.Gen
design considerations #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
unit
parameter to signal "end-of-args". Another option is to avoid the optional parameter and instead haveint_pos
take no argument and use the default0
origin (after all the library code uses~origin:0
throughout) and have anotherint_pos_origin
that 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?
@@ -1256,26 +1256,26 @@ random seed: 153870556 | |||
+++ 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 t
generators 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_pos
has?origin
butint_neg
does not, makes it weird.Question
Now that we have this smaller PR, we can question the existence of
nat
and/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_pos
would be removed and underlying generators for naturals will become uniform over OCaml positive integers rather than "non-uniform and at most 10.000"