Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Nov 15, 2024
1 parent 6268143 commit 798dd44
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions test/malli/constraint/number_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,27 @@
(is (= ["should be at least 1"]
(me/humanize (explain [:int {:min 1}] 0))
(me/humanize (explain [:int {:min 1 :max 10}] 0))
(me/humanize (explain [:int {:and [[:min 1]]}] 0))))
(me/humanize (explain [:int {:and [[:min 1]]}] 0))
(me/humanize (explain [:int {:and [[:min 1] [:min -5]]}] 0))))
(is (= ["should be at least 2"]
(me/humanize (explain [:int {:min 2}] 0))
(me/humanize (explain [:int {:min 2 :max 10}] 0))
(me/humanize (explain [:int {:and [[:min 2]]}] 0))))
(me/humanize (explain [:int {:and [[:min 2]]}] 0))
(me/humanize (explain [:int {:and [[:min -2] [:min 2]]}] 0))))
(is (= ["should be at most 1"]
(me/humanize (explain [:int {:max 1}] 2))
(me/humanize (explain [:int {:max 1}] 2))
(me/humanize (explain [:int {:min 0 :max 1}] 2))
(me/humanize (explain [:int {:and [[:max 1]]}] 2))))
(me/humanize (explain [:int {:and [[:max 1] [:max 23]]}] 2))))
(is (= ["should be at most 2"]
(me/humanize (explain [:int {:max 2}] 3))
(me/humanize (explain [:int {:min 1 :max 2}] 3))
(me/humanize (explain [:int {:and [[:max 2]]}] 3))))
(me/humanize (explain [:int {:and [[:max 23] [:max 2]]}] 3))))
(is (= ["should be 1"]
(me/humanize (explain [:int {:min 1 :max 1}] 3))
(me/humanize (explain [:int {:and [[:min 1] [:max 1]]}] 3))))))
(me/humanize (explain [:int {:and [[:min 1] [:max 1]]}] 3))
(me/humanize (explain [:int {:and [[:min 1] [:max 1]
[:min 0] [:max 2]]}] 3))))))

(deftest double+float-constraint-test
(doseq [type [:double :float]]
Expand All @@ -48,20 +52,23 @@
(is (= ["should be at least 1.0"]
(me/humanize (explain [type {:min 1.0}] 0.0))
(me/humanize (explain [type {:min 1.0 :max 10.0}] 0.0))
(me/humanize (explain [type {:and [[:min 1.0]]}] 0.0))))
(me/humanize (explain [type {:and [[:min 1.0]]}] 0.0))
(me/humanize (explain [type {:and [[:min 1.0] [:min -1.0]]}] 0.0))))
(is (= ["should be at least 2.0"]
(me/humanize (explain [type {:min 2.0}] 0.0))
(me/humanize (explain [type {:min 2.0 :max 10.0}] 0.0))
(me/humanize (explain [type {:and [[:min 2.0]]}] 0.0))))
(me/humanize (explain [type {:and [[:min 2.0]]}] 0.0))
(me/humanize (explain [type {:and [[:min 0.0] [:min 2.0]]}] 0.0))))
(is (= ["should be at most 1.0"]
(me/humanize (explain [type {:max 1.0}] 2.0))
(me/humanize (explain [type {:max 1.0}] 2.0))
(me/humanize (explain [type {:min 0.0 :max 1.0}] 2.0))
(me/humanize (explain [type {:and [[:max 1.0]]}] 2.0))))
(me/humanize (explain [type {:and [[:max 1.0] [:max 23.0]]}] 2.0))))
(is (= ["should be at most 2.0"]
(me/humanize (explain [type {:max 2.0}] 3.0))
(me/humanize (explain [type {:min 1.0 :max 2.0}] 3.0))
(me/humanize (explain [type {:and [[:max 2.0]]}] 3.0))))
(me/humanize (explain [type {:and [[:max 23.0] [:max 2.0]]}] 3.0))))
(is (= ["should be 1.0"]
(me/humanize (explain [type {:min 1.0 :max 1.0}] 3.0))
(me/humanize (explain [type {:and [[:min 1.0] [:max 1.0]]}] 3.0)))))))
(me/humanize (explain [type {:and [[:min 1.0] [:max 1.0]
[:min 0.0] [:max 2.0]]}] 3.0)))))))

0 comments on commit 798dd44

Please sign in to comment.