mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
Refactor and fix some issues with to_currency. Reduce code duplication. (#129)
* Refactor and fix some issues with to_currency. Reduce code duplication. * Use unicode literals in uk testcase.
This commit is contained in:
committed by
Ernesto Rodriguez Ortiz
parent
abae0b56a2
commit
f9d8868794
28
tests/test_currency.py
Normal file
28
tests/test_currency.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from decimal import Decimal
|
||||
from unittest import TestCase
|
||||
|
||||
from num2words.currency import parse_currency_parts
|
||||
|
||||
|
||||
class CurrencyTestCase(TestCase):
|
||||
def test_parse_currency_parts(self):
|
||||
# integer cents
|
||||
self.assertEqual(parse_currency_parts(101), (1, 1, False))
|
||||
self.assertEqual(parse_currency_parts(-123), (1, 23, True))
|
||||
|
||||
# decimal
|
||||
self.assertEqual(parse_currency_parts(Decimal("1.01")), (1, 1, False))
|
||||
self.assertEqual(parse_currency_parts(Decimal("-1.23")), (1, 23, True))
|
||||
self.assertEqual(parse_currency_parts(Decimal("-1.233")),
|
||||
(1, 23, True))
|
||||
|
||||
# string
|
||||
self.assertEqual(parse_currency_parts("1.01"), (1, 1, False))
|
||||
self.assertEqual(parse_currency_parts("-1.23"), (1, 23, True))
|
||||
self.assertEqual(parse_currency_parts("-1.2"), (1, 20, True))
|
||||
self.assertEqual(parse_currency_parts("1"), (1, 0, False))
|
||||
|
||||
# float
|
||||
self.assertEqual(parse_currency_parts(1.01), (1, 1, False))
|
||||
self.assertEqual(parse_currency_parts(-1.23), (1, 23, True))
|
||||
self.assertEqual(parse_currency_parts(-1.2), (1, 20, True))
|
||||
Reference in New Issue
Block a user