diff options
author | Max Nikulin <manikulin@gmail.com> | 2024-08-07 18:12:07 +0700 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2024-08-07 09:46:28 -1000 |
commit | 4cbd4ebbc071793c13e7b1baf33fb521a7e880ad (patch) | |
tree | a57163786648919e493d3ef8c64f98fba5b52768 /test/unit/t_amount.cc | |
parent | 093190e72eb7b7637085dc19b938014bfd0485cb (diff) | |
download | fork-ledger-4cbd4ebbc071793c13e7b1baf33fb521a7e880ad.tar.gz fork-ledger-4cbd4ebbc071793c13e7b1baf33fb521a7e880ad.tar.bz2 fork-ledger-4cbd4ebbc071793c13e7b1baf33fb521a7e880ad.zip |
More unit tests for amount_t::roundto
- Add some tests from comments to pull request #2361.
- Fix decimal separator in earlier added tests.
Diffstat (limited to 'test/unit/t_amount.cc')
-rw-r--r-- | test/unit/t_amount.cc | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/test/unit/t_amount.cc b/test/unit/t_amount.cc index f0fdd73e..9e815a8d 100644 --- a/test/unit/t_amount.cc +++ b/test/unit/t_amount.cc @@ -1163,7 +1163,7 @@ BOOST_AUTO_TEST_CASE(testCommodityCeiling) BOOST_CHECK(x2.valid()); } -BOOST_AUTO_TEST_CASE(testRound) +BOOST_AUTO_TEST_CASE(testRoundto) { amount_t a1("$ 123.123"); amount_t a2(a1); @@ -1172,6 +1172,18 @@ BOOST_AUTO_TEST_CASE(testRound) // Should it be "$ 123.12"? BOOST_CHECK_EQUAL(amount_t("$ 123.120"), a2); BOOST_CHECK_EQUAL(amount_t("$ 123.120"), a1.roundto(2)); + + // `in_place_roundto` code based on conversion to double + // had an issue with values close to halves + // due to 0.49999999 constant. + BOOST_CHECK_EQUAL(amount_t("1.1499999999").roundto(1), amount_t("1.1")); + BOOST_CHECK_EQUAL(amount_t("1.1499000").roundto(1), amount_t("1.1")); + BOOST_CHECK_EQUAL(amount_t("2.2499999999").roundto(1), amount_t("2.2")); + BOOST_CHECK_EQUAL(amount_t("2.2499000").roundto(1), amount_t("2.2")); + BOOST_CHECK_EQUAL(amount_t("-2.1500000001").roundto(1), amount_t("-2.2")); + BOOST_CHECK_EQUAL(amount_t("-2.15001").roundto(1), amount_t("-2.2")); + BOOST_CHECK_EQUAL(amount_t("-3.2500000001").roundto(1), amount_t("-3.3")); + BOOST_CHECK_EQUAL(amount_t("-3.25001").roundto(1), amount_t("-3.3")); } #ifndef NOT_FOR_PYTHON |