Skip to content

Commit

Permalink
Merge pull request #1052 from frenchy64/double-gen-long
Browse files Browse the repository at this point in the history
Coerce :double bounds to double
  • Loading branch information
ikitommi committed Jun 4, 2024
2 parents 64e91d1 + 64ac86e commit 8f60ac7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/malli/generator.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@
(gen/double* (merge (let [props (m/properties schema options)]
{:infinite? (get props :gen/infinite? false)
:NaN? (get props :gen/NaN? false)})
(-min-max schema options))))
(-> (-min-max schema options)
(update :min #(some-> % double))
(update :max #(some-> % double))))))
(defmethod -schema-generator :boolean [_ _] gen/boolean)
(defmethod -schema-generator :keyword [_ _] gen/keyword)
(defmethod -schema-generator :symbol [_ _] gen/symbol)
Expand Down
11 changes: 11 additions & 0 deletions test/malli/generator_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require [clojure.test :refer [are deftest is testing]]
[clojure.test.check.clojure-test :refer [defspec]]
[clojure.test.check.generators :as gen]
[clojure.test.check :refer [quick-check]]
[clojure.test.check.properties :refer [for-all]]
[malli.core :as m]
[malli.generator :as mg]
Expand All @@ -11,6 +12,12 @@
:cljs ["@js-joda/timezone/dist/js-joda-timezone-10-year-range"]))
#?(:cljs (:require-macros [malli.test-macros :refer [when-env]])))

(defn shrink [?schema]
(-> (quick-check 1 (for-all [s (mg/generator ?schema)] false) {:seed 0})
:shrunk
:smallest
first))

(deftest generator-test
(doseq [[?schema _ ?fn] json-schema-test/expectations
;; cljs doesn't have a regex generator :(
Expand Down Expand Up @@ -1034,3 +1041,7 @@
#?(:clj Exception, :cljs js/Error)
#":malli\.generator/and-generator-failure"
(mg/generate [:and pos? neg?]))))

(deftest double-with-long-min-test
(is (m/validate :double (shrink [:double {:min 3}])))
(is (= 3.0 (shrink [:double {:min 3}]))))

0 comments on commit 8f60ac7

Please sign in to comment.