Mercurial > babel > old > babel-test
view babel/tests/numbers.py @ 50:fa8a27b80eb4
Added round-half-even (banker's rounding) support.
Moved a couple of unit-tests from docstrings to a separate file.
author | jonas |
---|---|
date | Thu, 07 Jun 2007 22:00:43 +0000 |
parents | a2c54ef107c2 |
children | 84d400066b71 |
line wrap: on
line source
# -*- coding: utf-8 -*- # # Copyright (C) 2007 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://babel.edgewall.org/wiki/License. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://babel.edgewall.org/log/. import doctest import unittest from babel import numbers class FormatDecimalTestCase(unittest.TestCase): def test_subpatterns(self): self.assertEqual(numbers.format_decimal(-12345, '#,##0.##;-#', locale='en_US'), '-12,345') self.assertEqual(numbers.format_decimal(-12345, '#,##0.##;(#)', locale='en_US'), '(12,345)') def test_default_rounding(self): """Testing Round-Half-Even (Banker's rounding) A '5' is rounded to the closest 'even' number """ self.assertEqual(numbers.format_decimal(5.5, '0', locale='sv'), '6') self.assertEqual(numbers.format_decimal(6.5, '0', locale='sv'), '6') self.assertEqual(numbers.format_decimal(1.2325, locale='sv'), '1,232') self.assertEqual(numbers.format_decimal(1.2325, locale='sv'), '1,232') self.assertEqual(numbers.format_decimal(1.2335, locale='sv'), '1,234') def suite(): suite = unittest.TestSuite() suite.addTest(doctest.DocTestSuite(numbers)) suite.addTest(unittest.makeSuite(FormatDecimalTestCase)) return suite if __name__ == '__main__': unittest.main(defaultTest='suite')