diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-03-06 16:35:30 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-03-06 16:35:30 +0100 |
commit | 0214e426a6cd2c80671bb55257e3358e737f60d3 (patch) | |
tree | c0acf2e8d730637482c6030647d01b17681a7413 /src/util/test_amount.c | |
parent | 326f3b2a43d9e18938cb2ac902b4cc9c7423f393 (diff) |
add amount division API and test case
Diffstat (limited to 'src/util/test_amount.c')
-rw-r--r-- | src/util/test_amount.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/util/test_amount.c b/src/util/test_amount.c index e176d2131..3854297dd 100644 --- a/src/util/test_amount.c +++ b/src/util/test_amount.c @@ -197,6 +197,43 @@ main(int argc, TALER_amount_subtract (&a3, &a1, &a2)); GNUNET_assert (UINT64_MAX - 1 == a3.value); GNUNET_assert (TALER_AMOUNT_FRAC_BASE - 1 == a3.fraction); + + /* test division */ + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount ("EUR:3.33", + &a1)); + TALER_amount_divide (&a2, + &a1, + 1); + GNUNET_assert (0 == strcasecmp ("EUR", + a2.currency)); + GNUNET_assert (3 == a2.value); + GNUNET_assert (TALER_AMOUNT_FRAC_BASE / 100 * 33 == a2.fraction); + + TALER_amount_divide (&a2, + &a1, + 3); + GNUNET_assert (0 == strcasecmp ("EUR", + a2.currency)); + GNUNET_assert (1 == a2.value); + GNUNET_assert (TALER_AMOUNT_FRAC_BASE / 100 * 11 == a2.fraction); + + TALER_amount_divide (&a2, + &a1, + 2); + GNUNET_assert (0 == strcasecmp ("EUR", + a2.currency)); + GNUNET_assert (1 == a2.value); + GNUNET_assert (TALER_AMOUNT_FRAC_BASE / 1000 * 665 == a2.fraction); + TALER_amount_divide (&a2, + &a1, + TALER_AMOUNT_FRAC_BASE * 2); + GNUNET_assert (0 == strcasecmp ("EUR", + a2.currency)); + GNUNET_assert (0 == a2.value); + GNUNET_assert (1 == a2.fraction); + + return 0; } |