Skip to content

Commit

Permalink
overload airty of max and min for consistency with clojure.core
Browse files Browse the repository at this point in the history
  • Loading branch information
bpoweski committed Apr 7, 2013
1 parent 9099964 commit 6cfbdc1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
18 changes: 12 additions & 6 deletions src/clojure/clojurewerkz/money/amounts.clj
Expand Up @@ -128,14 +128,20 @@
(.abs money))

(defn ^Money max
"Returns the greater of the two money amounts"
[^Money a ^Money b]
(MoneyUtils/max a b))
"Returns the greatest of the given money amounts"
([a] a)
([^Money a ^Money b]
(MoneyUtils/max a b))
([a b & more]
(reduce max (max a b) more)))

(defn ^Money min
"Returns the lesser of the two money amounts"
[^Money a ^Money b]
(MoneyUtils/min a b))
"Returns the least of the given money amounts"
([a] a)
([^Money a ^Money b]
(MoneyUtils/min a b))
([a b & more]
(reduce min (min a b) more)))

(defn ^Money round
"Rounds monetary amount using the given scale and rounding mode.
Expand Down
14 changes: 12 additions & 2 deletions test/clojurewerkz/money/amounts_test.clj
Expand Up @@ -216,14 +216,24 @@


(deftest test-max
(is (= (ams/amount-of cu/USD 10) (ams/max (ams/amount-of cu/USD 10))))
(is (= (ams/amount-of cu/GBP 3) (ams/max (ams/amount-of cu/GBP 3))))
(are [a b c] (is (= c (ams/max a b)))
(ams/amount-of cu/USD 10) (ams/amount-of cu/USD 20) (ams/amount-of cu/USD 20)
(ams/amount-of cu/GBP 30) (ams/amount-of cu/GBP 10) (ams/amount-of cu/GBP 30)))
(ams/amount-of cu/GBP 30) (ams/amount-of cu/GBP 10) (ams/amount-of cu/GBP 30))
(are [a b c d] (is (= d (ams/max a b c)))
(ams/amount-of cu/USD 5) (ams/amount-of cu/USD 20) (ams/amount-of cu/USD 10) (ams/amount-of cu/USD 20)
(ams/amount-of cu/GBP 8) (ams/amount-of cu/GBP 3) (ams/amount-of cu/GBP 6) (ams/amount-of cu/GBP 8)))

(deftest test-min
(is (= (ams/amount-of cu/USD 10) (ams/min (ams/amount-of cu/USD 10))))
(is (= (ams/amount-of cu/GBP 3) (ams/min (ams/amount-of cu/GBP 3))))
(are [a b c] (is (= c (ams/min a b)))
(ams/amount-of cu/USD 10) (ams/amount-of cu/USD 20) (ams/amount-of cu/USD 10)
(ams/amount-of cu/GBP 30) (ams/amount-of cu/GBP 10) (ams/amount-of cu/GBP 10)))
(ams/amount-of cu/GBP 30) (ams/amount-of cu/GBP 10) (ams/amount-of cu/GBP 10))
(are [a b c d] (is (= d (ams/min a b c)))
(ams/amount-of cu/USD 5) (ams/amount-of cu/USD 20) (ams/amount-of cu/USD 10) (ams/amount-of cu/USD 5)
(ams/amount-of cu/GBP 8) (ams/amount-of cu/GBP 10) (ams/amount-of cu/GBP 10) (ams/amount-of cu/GBP 8)))

(deftest test-multiplication
(let [oa (ams/amount-of cu/USD 100)
Expand Down

0 comments on commit 6cfbdc1

Please sign in to comment.