From 3fc2fe08199a4641baa2b6595aadb893100a6849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 7 Aug 2019 19:19:25 +0200 Subject: [PATCH] Add rounding tests review255701002 --- tests/test_currency.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_currency.py b/tests/test_currency.py index 23abb5fa32..10cc6c88fc 100644 --- a/tests/test_currency.py +++ b/tests/test_currency.py @@ -86,6 +86,39 @@ class CurrencyTestCase(ModuleTestCase): 'date': today, }) + @with_transaction() + def test_round(self): + "Test simple round" + cu = create_currency('cu') + cu.rounding = Decimal('0.001') + cu.digits = 3 + cu.save() + + rounded = cu.round(Decimal('1.2345678')) + + self.assertEqual(rounded, Decimal('1.235')) + + @with_transaction() + def test_round_non_unity(self): + "Test round with non unity" + cu = create_currency('cu') + cu.rounding = Decimal('0.02') + cu.digits = 2 + cu.save() + + rounded = cu.round(Decimal('1.2345')) + + self.assertEqual(rounded, Decimal('1.24')) + + @with_transaction() + def test_round_big_number(self): + "Test rounding big number" + cu = create_currency('cu') + + rounded = cu.round(Decimal('1E50')) + + self.assertEqual(rounded, Decimal('1E50')) + @with_transaction() def test_compute_simple(self): 'Simple conversion'