-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"Experimental support for compiling schemas to test.check generators." | ||
(:require | ||
[clojure.test.check.generators :as generators] | ||
[clojure.test.check.rose-tree :as rose] | ||
[schema.spec.core :as spec :include-macros true] | ||
schema.spec.collection | ||
schema.spec.leaf | ||
|
@@ -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 | ||
"Sample a single element | ||
|
||
Providing the same random seed will give the same result" | ||
([schema random-seed] (generate-alt schema random-seed 10)) | ||
([schema random-seed size] (generate-alt schema random-seed size {} {})) | ||
([schema :- Schema | ||
random-seed | ||
size :- s/Int | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. It is unfortunate to depend on internal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
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
andgenerate
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