Skip to content

Commit

Permalink
fix min
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Aug 23, 2023
1 parent a1ca226 commit 0c863b1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/money.nim
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ proc `.`*[A: int64, C: Alpha3](unit: A, currency: C): Money =
result = amount(unit, currency)

proc `.`*[A: float64, C: Alpha3](fAmount: A, currency: C): Money =
var a = split($fAmount, ".")
var a = split($fAmount, ".") # todo avoid string conversion
var subunits =
if a[1].len == 1:
parseInt(a[1] & "0")
Expand Down Expand Up @@ -486,7 +486,7 @@ proc min*[M: Money](x: varargs[M]): M =
## Returns the smallest of the given `Money` objects
result = x[0]
for i in 1..high(x):
if x[i].units <= result.units and x[i].subunits > result.subunits:
if x[i].units <= result.units and x[i].subunits <= result.subunits:
result = x[i]

proc avg*[M: Money](x: varargs[M]): M =
Expand Down
2 changes: 1 addition & 1 deletion tests/test1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test "currencies":
assert amount(199, CZK) != amount(100, EUR)

test "amount min":
assert min(50.EUR, 55.EUR, 120.EUR, 5.EUR, 5.02.EUR) == 5.02.EUR
assert min(50.EUR, 55.EUR, 120.EUR, 5.EUR, 5.02.EUR) == 5.EUR

test "amount max":
assert max(50.EUR, 55.EUR, 120.EUR, 5.EUR, 120.50.EUR) == 120.50.EUR

0 comments on commit 0c863b1

Please sign in to comment.