summaryrefslogtreecommitdiff
path: root/odoo/addons/base/tests/test_float.py
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-02-01 18:15:21 +0100
committerChristophe Simonis <chs@odoo.com>2018-02-01 18:15:21 +0100
commit7e469eb77aae1f7e05a3ce0f6575b5149fed3ca1 (patch)
tree25023238fd6ccde1f3b8e805b03fcf228798a7b0 /odoo/addons/base/tests/test_float.py
parentc4895c2f2ba0fcd8fc5aef210003c20ba2154979 (diff)
parentf5e7b866860436782ade53308da1ff725be1f124 (diff)
[MERGE] forward port branch 11.0 up to f5e7b866860
Diffstat (limited to 'odoo/addons/base/tests/test_float.py')
-rw-r--r--odoo/addons/base/tests/test_float.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/odoo/addons/base/tests/test_float.py b/odoo/addons/base/tests/test_float.py
index 1c2fcc3e91f..6e42f8adf1d 100644
--- a/odoo/addons/base/tests/test_float.py
+++ b/odoo/addons/base/tests/test_float.py
@@ -92,6 +92,18 @@ class TestFloatPrecision(TransactionCase):
try_round(1.8, '2', 0, method='UP')
try_round(-1.8, '-2', 0, method='UP')
+ # Try some rounding value with rounding method DOWN instead of HALF-UP
+ # We use 2.425 because when normalizing 2.425 with precision_digits=3 it gives
+ # us 2424.9999999999995 as value, and if not handle correctly the rounding DOWN
+ # value will be incorrect (should be 2.425 and not 2.424)
+ try_round(2.425, '2.425', method='DOWN')
+ try_round(2.4249, '2.424', method='DOWN')
+ try_round(-2.425, '-2.425', method='DOWN')
+ try_round(-2.4249, '-2.424', method='DOWN')
+ try_round(-2.500, '-2.500', method='DOWN')
+ try_round(1.8, '1', 0, method='DOWN')
+ try_round(-1.8, '-1', 0, method='DOWN')
+
# Extended float range test, inspired by Cloves Almeida's test on bug #882036.
fractions = [.0, .015, .01499, .675, .67499, .4555, .4555, .45555]
expecteds = ['.00', '.02', '.01', '.68', '.67', '.46', '.456', '.4556']
@@ -135,8 +147,8 @@ class TestFloatPrecision(TransactionCase):
try_compare(-657.4444, -657.445, 1)
# Rounding to unusual rounding units (e.g. coin values)
- def try_round(amount, expected, precision_rounding=None):
- value = float_round(amount, precision_rounding=precision_rounding)
+ def try_round(amount, expected, precision_rounding=None, method='HALF-UP'):
+ value = float_round(amount, precision_rounding=precision_rounding, rounding_method=method)
result = float_repr(value, precision_digits=2)
self.assertEqual(result, expected, 'Rounding error: got %s, expected %s' % (result, expected))
@@ -145,6 +157,8 @@ class TestFloatPrecision(TransactionCase):
try_round(457.3, '455.00', precision_rounding=5)
try_round(457.5, '460.00', precision_rounding=5)
try_round(457.1, '456.00', precision_rounding=3)
+ try_round(2.5, '2.50', precision_rounding=0.05, method='DOWN')
+ try_round(-2.5, '-2.50', precision_rounding=0.05, method='DOWN')
def test_rounding_04(self):
""" check that proper rounding is performed for float persistence """