'Test rounding methods with 2 digits.'

def test_rounding_02(self):

    currency = self.env.ref('base.EUR')
    def try_round(amount, expected):
        digits = max(0, (- int(log10(currency.rounding))))
        result = float_repr(currency.round(amount), precision_digits=digits)
        self.assertEqual(result, expected, ('Rounding    error:    got    %s,    expected    %s' % (result, expected)))
    try_round(2.674, '2.67')
    try_round(2.675, '2.68')
    try_round((-2.675), '-2.68')
    try_round(0.001, '0.00')
    try_round((-0.001), '-0.00')
    try_round(0.0049, '0.00')
    try_round(0.005, '0.01')
    try_round((-0.005), '-0.01')
    def try_zero(amount, expected):
        self.assertEqual(currency.is_zero(amount), expected, ('Rounding    error:    %s    should    be    zero!' % amount))
    try_zero(0.01, False)
    try_zero((-0.01), False)
    try_zero(0.001, True)
    try_zero((-0.001), True)
    try_zero(0.0046, True)
    try_zero((-0.0046), True)
    try_zero((2.68 - 2.675), False)
    try_zero((2.68 - 2.676), True)
    try_zero((2.676 - 2.68), True)
    try_zero((2.675 - 2.68), False)
    def try_compare(amount1, amount2, expected):
        self.assertEqual(currency.compare_amounts(amount1, amount2), expected, ('Rounding    error,    compare_amounts(%s,%s)    should    be    %s' % (amount1, amount2, expected)))
    try_compare(0.001, 0.001, 0)
    try_compare((-0.001), (-0.001), 0)
    try_compare(0.001, 0.002, 0)
    try_compare((-0.001), (-0.002), 0)
    try_compare(2.675, 2.68, 0)
    try_compare(2.676, 2.68, 0)
    try_compare((-2.676), (-2.68), 0)
    try_compare(2.674, 2.68, (-1))
    try_compare((-2.674), (-2.68), 1)
    try_compare(3, 2.68, 1)
    try_compare((-3), (-2.68), (-1))
    try_compare(0.01, 0, 1)
    try_compare((-0.01), 0, (-1))
