-
Notifications
You must be signed in to change notification settings - Fork 8
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 ability to specify generator size and seed #12
Conversation
@@ -223,3 +224,17 @@ | |||
"Sample a single element of low to moderate size." | |||
[& generator-args] | |||
(generators/generate (apply generator generator-args) 10)) | |||
|
|||
(s/defn generate-alt :- s/Any |
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.
This is a poor name choice. Any suggestions while I'm trying to come up with something better?
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.
I would do perhaps
(s/defn generate-deterministic [size seed & generator-args] (generators/generate (apply generator generator-args) size seed))
Although really I would prefer to just get out of this game entirely (and eventually remove sample
and generate
from this library entirely). This is really a library about making generators, and it was probably a mistake to ever provide wrappers for using them rather than encouraging just using test.check directly.
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.
The rational of only handling generator creation logic in this lib sounds good. I'll implement these generation changes on my side
leaf-generators :- LeafGenerators | ||
wrappers :- GeneratorWrappers] | ||
(let [gen (generator schema leaf-generators wrappers)] | ||
(rose/root (generators/call-gen gen random-seed size))))) |
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 is unfortunate to depend on internal clojure.test
logic (like with (rose/root (generators/call-gen ..))
), but it is pretty contained, so I think it is worth it
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 looks like test.check
exposes these as arguments to generators/generate
, no?
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.
In recent releases, yes.
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.
Thanks for the PR! I left some comments, let me know your thoughts (especially on the high-level point) and we can go from there.
leaf-generators :- LeafGenerators | ||
wrappers :- GeneratorWrappers] | ||
(let [gen (generator schema leaf-generators wrappers)] | ||
(rose/root (generators/call-gen gen random-seed size))))) |
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 looks like test.check
exposes these as arguments to generators/generate
, no?
@@ -223,3 +224,17 @@ | |||
"Sample a single element of low to moderate size." | |||
[& generator-args] | |||
(generators/generate (apply generator generator-args) 10)) | |||
|
|||
(s/defn generate-alt :- s/Any |
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.
I would do perhaps
(s/defn generate-deterministic [size seed & generator-args] (generators/generate (apply generator generator-args) size seed))
Although really I would prefer to just get out of this game entirely (and eventually remove sample
and generate
from this library entirely). This is really a library about making generators, and it was probably a mistake to ever provide wrappers for using them rather than encouraging just using test.check directly.
I think it makes sense to close this given the rational in #12 (comment) |
Every once in a while I'm trying to generate a fairly constrained schema and I get an error that after 10 tries an example couldn't be generated (if I find the error I will paste it here). Extending the user to pass in a sample size will allow them to hand tune this for problematic schemas.
While I was at it I figured I would address #7