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 ability to specify generator size and seed #12

Closed
wants to merge 1 commit into from
Closed

Add ability to specify generator size and seed #12

wants to merge 1 commit into from

Conversation

philomates
Copy link
Contributor

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

@@ -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
Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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)))))
Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In recent releases, yes.

Copy link
Member

@w01fe w01fe left a 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)))))
Copy link
Member

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
Copy link
Member

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.

@philomates
Copy link
Contributor Author

I think it makes sense to close this given the rational in #12 (comment)

@philomates philomates closed this Oct 6, 2017
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

Successfully merging this pull request may close these issues.

3 participants