Skip to content

Commit

Permalink
Italian: add more currencies and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bryananderson committed Jan 16, 2025
1 parent 7df3db9 commit 102edbb
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 0 deletions.
9 changes: 9 additions & 0 deletions num2words/lang_IT.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,17 @@ class Num2Word_IT(Num2Word_EU):
CURRENCY_FORMS = {
'EUR': (('euro', 'euro'), GENERIC_CENTS),
'USD': (GENERIC_DOLLARS, GENERIC_CENTS),
'CAD': (GENERIC_DOLLARS, GENERIC_CENTS),
'AUD': (GENERIC_DOLLARS, GENERIC_CENTS),
'NZD': (GENERIC_DOLLARS, GENERIC_CENTS),
'HKD': (GENERIC_DOLLARS, GENERIC_CENTS),
'GBP': (('sterlina', 'sterline'), ('penny', 'penny')),
'CNY': (('yuan', 'yuan'), ('fen', 'fen')),
'JPY': (('yen', 'yen'), ('sen', 'sen')),
'INR': (('rupia', 'rupie'), ('paisa', 'paise')),
'RUB': (('rublo', 'rubli'), ('copeco', 'copechi')),
'KRW': (('won', 'won'), ('jeon', 'jeon')),
'MXN': (('peso', 'pesos'), GENERIC_CENTS),
}
MINUS_PREFIX_WORD = "meno "
FLOAT_INFIX_WORD = " virgola "
Expand Down
170 changes: 170 additions & 0 deletions tests/test_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,46 @@
(100.00, 'cento dollari e zero centesimi'),
)

TEST_CASES_TO_CURRENCY_CAD = (
(1.00, 'un dollaro e zero centesimi'),
(2.01, 'due dollari e un centesimo'),
(8.10, 'otto dollari e dieci centesimi'),
(12.26, 'dodici dollari e ventisei centesimi'),
(21.29, 'ventun dollari e ventinove centesimi'),
(81.25, 'ottantun dollari e venticinque centesimi'),
(100.00, 'cento dollari e zero centesimi'),
)

TEST_CASES_TO_CURRENCY_AUD = (
(1.00, 'un dollaro e zero centesimi'),
(2.01, 'due dollari e un centesimo'),
(8.10, 'otto dollari e dieci centesimi'),
(12.26, 'dodici dollari e ventisei centesimi'),
(21.29, 'ventun dollari e ventinove centesimi'),
(81.25, 'ottantun dollari e venticinque centesimi'),
(100.00, 'cento dollari e zero centesimi'),
)

TEST_CASES_TO_CURRENCY_NZD = (
(1.00, 'un dollaro e zero centesimi'),
(2.01, 'due dollari e un centesimo'),
(8.10, 'otto dollari e dieci centesimi'),
(12.26, 'dodici dollari e ventisei centesimi'),
(21.29, 'ventun dollari e ventinove centesimi'),
(81.25, 'ottantun dollari e venticinque centesimi'),
(100.00, 'cento dollari e zero centesimi'),
)

TEST_CASES_TO_CURRENCY_HKD = (
(1.00, 'un dollaro e zero centesimi'),
(2.01, 'due dollari e un centesimo'),
(8.10, 'otto dollari e dieci centesimi'),
(12.26, 'dodici dollari e ventisei centesimi'),
(21.29, 'ventun dollari e ventinove centesimi'),
(81.25, 'ottantun dollari e venticinque centesimi'),
(100.00, 'cento dollari e zero centesimi'),
)

TEST_CASES_TO_CURRENCY_GBP = (
(1.00, 'una sterlina e zero penny'),
(2.01, 'due sterline e un penny'),
Expand All @@ -51,6 +91,66 @@
(100.00, 'cento sterline e zero penny'),
)

TEST_CASES_TO_CURRENCY_CNY = (
(1.00, 'un yuan e zero fen'),
(2.01, 'due yuan e un fen'),
(8.10, 'otto yuan e dieci fen'),
(12.26, 'dodici yuan e ventisei fen'),
(21.29, 'ventun yuan e ventinove fen'),
(81.25, 'ottantun yuan e venticinque fen'),
(100.00, 'cento yuan e zero fen'),
)

TEST_CASES_TO_CURRENCY_JPY = (
(1.00, 'un yen e zero sen'),
(2.01, 'due yen e un sen'),
(8.10, 'otto yen e dieci sen'),
(12.26, 'dodici yen e ventisei sen'),
(21.29, 'ventun yen e ventinove sen'),
(81.25, 'ottantun yen e venticinque sen'),
(100.00, 'cento yen e zero sen'),
)

TEST_CASES_TO_CURRENCY_INR = (
(1.00, 'un rupia e zero paise'),
(2.01, 'due rupie e un paisa'),
(8.10, 'otto rupie e dieci paise'),
(12.26, 'dodici rupie e ventisei paise'),
(21.29, 'ventun rupie e ventinove paise'),
(81.25, 'ottantun rupie e venticinque paise'),
(100.00, 'cento rupie e zero paise'),
)

TEST_CASES_TO_CURRENCY_RUB = (
(1.00, 'un rublo e zero copechi'),
(2.01, 'due rubli e un copeco'),
(8.10, 'otto rubli e dieci copechi'),
(12.26, 'dodici rubli e ventisei copechi'),
(21.29, 'ventun rubli e ventinove copechi'),
(81.25, 'ottantun rubli e venticinque copechi'),
(100.00, 'cento rubli e zero copechi'),
)

TEST_CASES_TO_CURRENCY_KRW = (
(1.00, 'un won e zero jeon'),
(2.01, 'due won e un jeon'),
(8.10, 'otto won e dieci jeon'),
(12.26, 'dodici won e ventisei jeon'),
(21.29, 'ventun won e ventinove jeon'),
(81.25, 'ottantun won e venticinque jeon'),
(100.00, 'cento won e zero jeon'),
)

TEST_CASES_TO_CURRENCY_MXN = (
(1.00, 'un peso e zero centesimi'),
(2.01, 'due pesos e un centesimo'),
(8.10, 'otto pesos e dieci centesimi'),
(12.26, 'dodici pesos e ventisei centesimi'),
(21.29, 'ventun pesos e ventinove centesimi'),
(81.25, 'ottantun pesos e venticinque centesimi'),
(100.00, 'cento pesos e zero centesimi'),
)


class Num2WordsITTest(TestCase):
maxDiff = None
Expand Down Expand Up @@ -312,9 +412,79 @@ def test_currency_usd(self):
test[1]
)

def test_currency_cad(self):
for test in TEST_CASES_TO_CURRENCY_CAD:
self.assertEqual(
num2words(test[0], lang='it', to='currency', currency='CAD'),
test[1]
)

def test_currency_aud(self):
for test in TEST_CASES_TO_CURRENCY_AUD:
self.assertEqual(
num2words(test[0], lang='it', to='currency', currency='AUD'),
test[1]
)

def test_currency_nzd(self):
for test in TEST_CASES_TO_CURRENCY_NZD:
self.assertEqual(
num2words(test[0], lang='it', to='currency', currency='NZD'),
test[1]
)

def test_currency_hkd(self):
for test in TEST_CASES_TO_CURRENCY_HKD:
self.assertEqual(
num2words(test[0], lang='it', to='currency', currency='HKD'),
test[1]
)

def test_currency_gbp(self):
for test in TEST_CASES_TO_CURRENCY_GBP:
self.assertEqual(
num2words(test[0], lang='it', to='currency', currency='GBP'),
test[1]
)

def test_currency_cny(self):
for test in TEST_CASES_TO_CURRENCY_CNY:
self.assertEqual(
num2words(test[0], lang='it', to='currency', currency='CNY'),
test[1]
)

def test_currency_jpy(self):
for test in TEST_CASES_TO_CURRENCY_JPY:
self.assertEqual(
num2words(test[0], lang='it', to='currency', currency='JPY'),
test[1]
)

def test_currency_inr(self):
for test in TEST_CASES_TO_CURRENCY_INR:
self.assertEqual(
num2words(test[0], lang='it', to='currency', currency='INR'),
test[1]
)

def test_currency_rub(self):
for test in TEST_CASES_TO_CURRENCY_RUB:
self.assertEqual(
num2words(test[0], lang='it', to='currency', currency='RUB'),
test[1]
)

def test_currency_krw(self):
for test in TEST_CASES_TO_CURRENCY_KRW:
self.assertEqual(
num2words(test[0], lang='it', to='currency', currency='KRW'),
test[1]
)

def test_currency_mxn(self):
for test in TEST_CASES_TO_CURRENCY_MXN:
self.assertEqual(
num2words(test[0], lang='it', to='currency', currency='MXN'),
test[1]
)

0 comments on commit 102edbb

Please sign in to comment.