From da5b3ba8aeb9d47e4f99cd22847c9b539ff8ee2b Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 15 Jan 2020 15:17:02 +0100 Subject: round amounts based on config, do unit test for rounding --- src/util/test_amount.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/util/test_amount.c') diff --git a/src/util/test_amount.c b/src/util/test_amount.c index d9110eaf8..4eeccd7e0 100644 --- a/src/util/test_amount.c +++ b/src/util/test_amount.c @@ -234,6 +234,29 @@ main (int argc, GNUNET_assert (0 == a2.value); GNUNET_assert (1 == a2.fraction); + /* test rounding #1 */ + + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount ("EUR:4.001", + &a1)); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount ("EUR:4", + &a2)); + + GNUNET_assert (GNUNET_OK == TALER_amount_round_down (&a1, 2)); + GNUNET_assert (GNUNET_NO == TALER_amount_round_down (&a1, 2)); + GNUNET_assert (0 == TALER_amount_cmp (&a1, &a2)); + + /* test rounding #2 */ + + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount ("EUR:4.001", + &a1)); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount ("EUR:4.001", + &a2)); + GNUNET_assert (GNUNET_NO == TALER_amount_round_down (&a1, 3)); + GNUNET_assert (0 == TALER_amount_cmp (&a1, &a2)); return 0; } -- cgit v1.2.3