Skip to content

Commit

Permalink
Type hinting and assertion tests improved in money/compare and money/…
Browse files Browse the repository at this point in the history
…compare-amounts.
  • Loading branch information
siefca committed Jul 18, 2021
1 parent 1ff2dc6 commit 48c23fb
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/io/randomseed/bankster/money.clj
Original file line number Diff line number Diff line change
Expand Up @@ -724,15 +724,12 @@
"Compares two monetary amounts of the same currency, regardless of their
scales. Returns -1 if the second one is less than, 0 if equal to, and 1 if it is
greater than the first. Nil values are always considered lower when comparing."
{:added "1.0.0" :tag 'int}
(^Boolean [^Money a] (int 0))
(^Boolean [^Money a ^Money b]
{:added "1.0.0"}
([^Money a] (int 0))
([^Money a ^Money b]
(let [nila (nil? a)
nilb (nil? b)]
(assert (or (and nila (instance? Money b))
(and nilb (instance? Money a))
(and nila nilb)
(same-currencies? a b))
(assert (or nila nilb (same-currencies? ^Money a ^Money b))
(str "Can only compare amounts of the same currency and/or nil values: "
a ", " b))
(if nila
Expand All @@ -747,17 +744,14 @@
"Compares two monetary amounts of the same currency and scale. Returns -1 if the
second one is less than, 0 if equal to, and 1 if it is greater than the first. Nil
values are always considered lower when comparing."
{:added "1.0.0" :tag 'int}
(^Boolean [^Money a] (int 0))
(^Boolean [^Money a ^Money b]
{:added "1.0.0"}
([^Money a] (int 0))
([^Money a ^Money b]
(let [nila (nil? a)
nilb (nil? b)]
(assert (or (and nila (instance? Money b))
(and nilb (instance? Money a))
(and nila nilb)
(same-currencies? a b))
(assert (or nila nilb (same-currencies? ^Money a ^Money b))
(str "Can only compare amounts of the same currency and/or nil values: "
a ", " b "."))
a ", " b))
(if nila
(if nilb
(int 0)
Expand Down

0 comments on commit 48c23fb

Please sign in to comment.