|
87 | 87 | (let [{:gen/keys [infinite? NaN?]} (m/properties schema)]
|
88 | 88 | {:infinite? infinite? :NaN? NaN?}))
|
89 | 89 |
|
90 |
| -(defn- -double-gen [schema options] (gen-double (into (inf-nan schema options) (-min-max schema options)))) |
91 |
| - |
92 | 90 | (defn- gen-fmap [f gen] (or (-unreachable gen) (gen/fmap f gen)))
|
93 | 91 | (defn- gen-fcat [gen] (gen-fmap #(apply concat %) gen))
|
94 | 92 | (defn- gen-tuple [gens] (or (some -unreachable gens) (apply gen/tuple gens)))
|
|
363 | 361 | (gen/return (first es))
|
364 | 362 | (gen/elements es)))
|
365 | 363 |
|
| 364 | +(defn- double-gen [schema options] |
| 365 | + (gen/double* (merge (let [props (m/properties schema options)] |
| 366 | + {:infinite? (get props :gen/infinite? false) |
| 367 | + :NaN? (get props :gen/NaN? false)}) |
| 368 | + (-> (-min-max schema options) |
| 369 | + (update :min #(some-> % double)) |
| 370 | + (update :max #(some-> % double)))))) |
| 371 | + |
366 | 372 | (defmulti -schema-generator (fn [schema options] (m/type schema options)) :default ::default)
|
367 | 373 |
|
368 | 374 | (defmethod -schema-generator ::default [schema options] (ga/gen-for-pred (m/validator schema options)))
|
|
397 | 403 | (defmethod -schema-generator :nil [_ _] nil-gen)
|
398 | 404 | (defmethod -schema-generator :string [schema options] (-string-gen schema options))
|
399 | 405 | (defmethod -schema-generator :int [schema options] (gen/large-integer* (-min-max schema options)))
|
400 |
| -(defmethod -schema-generator :double [schema options] (-double-gen schema options)) |
401 |
| -(defmethod -schema-generator :float [schema options] |
402 |
| - (let [max-float #?(:clj Float/MAX_VALUE :cljs (.-MAX_VALUE js/Number)) |
403 |
| - min-float (- max-float) |
404 |
| - props (m/properties schema options) |
405 |
| - min-max-props (-min-max schema options) |
406 |
| - infinite? #?(:clj false :cljs (get props :gen/infinite? false))] |
407 |
| - (->> (merge {:infinite? infinite? |
408 |
| - :NaN? (get props :gen/NaN? false)} |
409 |
| - (-> min-max-props |
410 |
| - (update :min #(or (some-> % float) |
411 |
| - #?(:clj min-float :cljs nil))) |
412 |
| - (update :max #(or (some-> % float) |
413 |
| - #?(:clj max-float :cljs nil))))) |
414 |
| - (gen/double*) |
415 |
| - (gen/fmap float)))) |
| 406 | +(defmethod -schema-generator :double [schema options] (double-gen schema options)) |
| 407 | +(defmethod -schema-generator :float [schema options] (double-gen schema options)) |
416 | 408 | (defmethod -schema-generator :boolean [_ _] gen/boolean)
|
417 | 409 | (defmethod -schema-generator :keyword [_ _] gen/keyword)
|
418 | 410 | (defmethod -schema-generator :symbol [_ _] gen/symbol)
|
|
0 commit comments