-
Notifications
You must be signed in to change notification settings - Fork 237
Add :decimal schema #1285
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: master
Are you sure you want to change the base?
Add :decimal schema #1285
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -418,6 +418,7 @@ | |
| (defmethod -schema-generator :int [schema options] (gen/large-integer* (-min-max schema options))) | ||
| (defmethod -schema-generator :double [schema options] (double-gen schema options)) | ||
| (defmethod -schema-generator :float [schema options] (double-gen schema options)) | ||
| #?(:clj (defmethod -schema-generator :decimal [schema options] (gen-fmap bigdec (double-gen schema options)))) | ||
|
Collaborator
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. I don't think the current implementation works with It might make sense to never generate those values as in spec's generator: |
||
| (defmethod -schema-generator :boolean [_ _] gen/boolean) | ||
| (defmethod -schema-generator :keyword [_ _] gen/keyword) | ||
| (defmethod -schema-generator :symbol [_ _] gen/symbol) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -345,6 +345,11 @@ | |
| [:set {:min 1, :gen/min 10, :max 100, :gen/max 200} int?] | ||
| [:string {:min 1, :gen/min 10, :max 100, :gen/max 200}]))) | ||
|
|
||
| #?(:clj | ||
| (deftest decimal-generator-test | ||
| (is (every? decimal? (mg/sample [:decimal {:min 0.0M, :max 1.0M}] {:size 100}))) | ||
| (is (every? #(<= 0.0M % 1.0M) (mg/sample [:decimal {:min 0.0M, :max 1.0M}] {:size 100}))))) | ||
|
Collaborator
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. Please add some tests for Also tests that provide bounds outside the range of Double, for example
Collaborator
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. Actually I'm not sure if anyone has released a BigDecimal generator that supports arbitrary bounds. This is the closest I could find: I think at minimum we need a test to show that it throws rather than violating the expected bounds. |
||
|
|
||
| (deftest protocol-test | ||
| (let [values #{1 2 3 5 8 13} | ||
| schema (reify | ||
|
|
||
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.
If the schema is meaningless in cljs then I propose
:decimalnot exist on that platform.