Skip to content

Commit

Permalink
Fix tests the were failing due to rounding errors in amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
sernamar committed Sep 14, 2024
1 parent 3868815 commit 7c8b643
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test/dinero/conversion/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
m1-again (sut/convert-using-db m1 :eur db "exchange_rate" "from_currency" "to_currency" "rate")] ; same currency
(t/is (= 0.80M (core/get-amount converted)))
(t/is (= :gbp (core/get-currency converted)))
(t/is (= 1M (core/get-amount converted-back)))
(t/is (= 1M (BigDecimal/.setScale (core/get-amount converted-back) 15 BigDecimal/ROUND_HALF_UP)))
(t/is (= :eur (core/get-currency converted-back)))
(t/is (= 1M (core/get-amount m1-again)))
(t/is (= :eur (core/get-currency m1-again)))
Expand All @@ -54,7 +54,7 @@
m1-again (sut/convert-using-ecb m1 :eur query-date)] ; same currency
(t/is (> 1M (core/get-amount converted)))
(t/is (= :gbp (core/get-currency converted)))
(t/is (= 1M (core/get-amount converted-back)))
(t/is (= 1M (BigDecimal/.setScale (core/get-amount converted-back) 15 BigDecimal/ROUND_HALF_UP)))
(t/is (= :eur (core/get-currency converted-back)))
(t/is (= 1M (core/get-amount m1-again)))
(t/is (= :eur (core/get-currency m1-again)))
Expand All @@ -70,7 +70,7 @@
m1-again (sut/convert-using-ecb m1 :eur query-date)] ; same currency
(t/is (> 1M (core/get-amount converted)))
(t/is (= :gbp (core/get-currency converted)))
(t/is (= 1M (core/get-amount converted-back)))
(t/is (= 1M (BigDecimal/.setScale (core/get-amount converted-back) 15 BigDecimal/ROUND_HALF_UP)))
(t/is (= :eur (core/get-currency converted-back)))
(t/is (= 1M (core/get-amount m1-again)))
(t/is (= :eur (core/get-currency m1-again)))
Expand All @@ -84,7 +84,7 @@
converted-back (sut/convert-using-coinbase converted :btc)] ; same currency
(t/is (< 1M (core/get-amount converted)))
(t/is (= :eur (core/get-currency converted)))
(t/is (= 1M (core/get-amount converted-back)))
(t/is (= 1M (BigDecimal/.setScale (core/get-amount converted-back) 15 BigDecimal/ROUND_HALF_UP)))
(t/is (= :btc (core/get-currency converted-back)))
(t/is (thrown? ExceptionInfo (sut/convert-using-coinbase (core/money-of 1M :eur) :gbp)))
(t/is (thrown? ExceptionInfo (sut/convert-using-coinbase m1 :invalid)))))

0 comments on commit 7c8b643

Please sign in to comment.