diff --git a/README.rst b/README.rst index 9b1e97f6..c207324d 100644 --- a/README.rst +++ b/README.rst @@ -79,7 +79,7 @@ Besides the numerical argument, there are two main optional arguments, ``to:`` a * ``am`` (Amharic) * ``ar`` (Arabic) * ``az`` (Azerbaijani) -* ``by`` (Belarusian) +* ``be`` (Belarusian) * ``ce`` (Chechen) * ``cy`` (Welsh) * ``cz`` (Czech) @@ -121,6 +121,7 @@ Besides the numerical argument, there are two main optional arguments, ``to:`` a * ``ro`` (Romanian) * ``ru`` (Russian) * ``te`` (Telugu) +* ``tet`` (Tetum) * ``tg`` (Tajik) * ``tr`` (Turkish) * ``th`` (Thai) diff --git a/num2words/__init__.py b/num2words/__init__.py index 95dbcd7a..c513d853 100644 --- a/num2words/__init__.py +++ b/num2words/__init__.py @@ -17,21 +17,22 @@ from __future__ import unicode_literals -from . import (lang_AM, lang_AR, lang_AZ, lang_BY, lang_CE, lang_CY, lang_CZ, - lang_DE, lang_DK, lang_EN, lang_EN_IN, lang_EN_NG, lang_EO, - lang_ES, lang_ES_CO, lang_ES_CR, lang_ES_GT, lang_ES_NI, - lang_ES_VE, lang_FA, lang_FI, lang_FR, lang_FR_BE, lang_FR_CH, - lang_FR_DZ, lang_HE, lang_HU, lang_ID, lang_IS, lang_IT, - lang_JA, lang_KN, lang_KO, lang_KZ, lang_LT, lang_LV, lang_NL, - lang_NO, lang_PL, lang_PT, lang_PT_BR, lang_RO, lang_RU, - lang_SK, lang_SL, lang_SR, lang_SV, lang_TE, lang_TG, lang_TH, - lang_TR, lang_UK, lang_VI) +from . import (lang_AM, lang_AR, lang_AZ, lang_BE, lang_CA, lang_CE, lang_CY, + lang_CZ, lang_DE, lang_DK, lang_EN, lang_EN_IN, lang_EN_NG, + lang_EO, lang_ES, lang_ES_CO, lang_ES_CR, lang_ES_GT, + lang_ES_NI, lang_ES_VE, lang_FA, lang_FI, lang_FR, lang_FR_BE, + lang_FR_CH, lang_FR_DZ, lang_HE, lang_HU, lang_ID, lang_IS, + lang_IT, lang_JA, lang_KN, lang_KO, lang_KZ, lang_LT, lang_LV, + lang_NL, lang_NO, lang_PL, lang_PT, lang_PT_BR, lang_RO, + lang_RU, lang_SK, lang_SL, lang_SR, lang_SV, lang_TE, lang_TET, + lang_TG, lang_TH, lang_TR, lang_UK, lang_VI) CONVERTER_CLASSES = { 'am': lang_AM.Num2Word_AM(), 'ar': lang_AR.Num2Word_AR(), 'az': lang_AZ.Num2Word_AZ(), - 'by': lang_BY.Num2Word_BY(), + 'be': lang_BE.Num2Word_BE(), + 'ca': lang_CA.Num2Word_CA(), 'ce': lang_CE.Num2Word_CE(), 'cy': lang_CY.Num2Word_CY(), 'cz': lang_CZ.Num2Word_CZ(), @@ -79,8 +80,9 @@ 'nl': lang_NL.Num2Word_NL(), 'uk': lang_UK.Num2Word_UK(), 'te': lang_TE.Num2Word_TE(), + 'tet': lang_TET.Num2Word_TET(), 'hu': lang_HU.Num2Word_HU(), - 'is': lang_IS.Num2Word_IS() + 'is': lang_IS.Num2Word_IS(), } CONVERTES_TYPES = ['cardinal', 'ordinal', 'ordinal_num', 'year', 'currency'] diff --git a/num2words/lang_BY.py b/num2words/lang_BE.py similarity index 89% rename from num2words/lang_BY.py rename to num2words/lang_BE.py index ec825fd0..c41d6e4e 100644 --- a/num2words/lang_BY.py +++ b/num2words/lang_BE.py @@ -94,6 +94,17 @@ 9: "дзевяноста", } +TWENTIES_ORD = ( + ("дваццаць", "дваццаці"), + ("трыццаць", "трыццаці"), + ("сорак", "сарака"), + ("пяцьдзясят", "пяцідзясяці"), + ("шэсцьдзясят", "шaсцідзясяці"), + ("семдзесят", "сямідзесяці"), + ("восемдзесят", "васьмідзесяці"), + ("дзевяноста", "дзевяноста"), +) + HUNDREDS = { 1: "сто", 2: "дзвесце", @@ -120,7 +131,7 @@ } -class Num2Word_BY(Num2Word_Base): +class Num2Word_BE(Num2Word_Base): CURRENCY_FORMS = { "RUB": ( ("расійскі рубель", "расійскія рублі", "расійскіх рублёў"), @@ -138,6 +149,7 @@ class Num2Word_BY(Num2Word_Base): ("капейка", "капейкі", "капеек"), ), "UZS": (("сум", "сумы", "сумаў"), ("тыйін", "тыйіны", "тыйінаў")), + "PLN": (("злоты", "злотых", "злотых"), ("грош", "грошы", "грошаў")), } def setup(self): @@ -204,6 +216,8 @@ def pluralize(self, n, forms): def to_ordinal(self, number, gender="m"): self.verify_ordinal(number) + if isinstance(gender, bool) and gender: + gender = "f" outwords = self.to_cardinal(number, gender).split(" ") lastword = outwords[-1].lower() try: @@ -223,8 +237,6 @@ def to_ordinal(self, number, gender="m"): lastword = ( self.ords_adjective.get(lastword[:-3], lastword) + "соты" ) - elif lastword[-5:] == "шэсць": - lastword = "шосты" elif lastword[-7:] == "дзесяць": lastword = "дзясяты" elif lastword[-9:] == "семдзесят": @@ -242,6 +254,8 @@ def to_ordinal(self, number, gender="m"): elif lastword[-1] == "н" or lastword[-2] == "н": lastword = lastword[: lastword.rfind("н") + 1] + "ны" + elif lastword[-3:] == "наў": + lastword = lastword[: lastword.rfind("н") + 1] + "ны" elif lastword[-1] == "д" or lastword[-2] == "д": lastword = lastword[: lastword.rfind("д") + 1] + "ны" @@ -254,9 +268,7 @@ def to_ordinal(self, number, gender="m"): lastword = lastword[:-1] + "ая" if gender == "n": - if lastword[-2:] in [ - "ці", "ца" - ]: + if lastword[-2:] in ["ці", "ца"]: lastword = lastword[:-2] + "цяе" else: lastword = lastword[:-1] + "ае" @@ -266,16 +278,20 @@ def to_ordinal(self, number, gender="m"): outwords[-2] = outwords[-1] del outwords[-1] - if len(outwords) > 2 and "тысяч" in outwords[-1]: - if 'сорак' in outwords[-3]: - outwords[-3] = outwords[-3].replace('сорак', 'сарака') - outwords[-3] = outwords[-3] + outwords[-2] + outwords[-1] - del outwords[-1] - del outwords[-1] + if len(outwords) > 1 and ( + (any(x[0] in outwords[-1] for x in THOUSANDS.values())) + or "тысяч" in outwords[-1] + ): + new_outwords = [] + for _w in outwords: + replacement = next( + (x for x in TWENTIES_ORD if x[0] in _w), None + ) + if replacement: + _w = _w.replace(replacement[0], replacement[1]) + new_outwords.append(_w) + outwords = ["".join(new_outwords)] - elif len(outwords) > 1 and "тысяч" in outwords[-1]: - outwords[-2] = outwords[-2] + outwords[-1] - del outwords[-1] return " ".join(outwords).strip() def _money_verbose(self, number, currency): @@ -294,8 +310,6 @@ def _cents_verbose(self, number, currency): return self._int2word(number, gender) def _int2word(self, n, gender="m"): - if isinstance(gender, bool) and gender: - gender = "f" if n < 0: return " ".join([self.negword, self._int2word(abs(n), gender)]) diff --git a/num2words/lang_CA.py b/num2words/lang_CA.py new file mode 100644 index 00000000..97d0f29e --- /dev/null +++ b/num2words/lang_CA.py @@ -0,0 +1,476 @@ +from __future__ import division, print_function, unicode_literals + +import math + +from .lang_EU import Num2Word_EU + +GENERIC_DOLLARS = ('dòlar', 'dòlars') +GENERIC_CENTS = ('centau', 'centaus') +CURRENCIES_UNA = ( + 'SLL', + 'SEK', + 'NOK', + 'CZK', + 'DKK', + 'ISK', + 'SKK', + 'GBP', + 'CYP', + 'EGP', + 'FKP', + 'GIP', + 'LBP', + 'SDG', + 'SHP', + 'SSP', + 'SYP', + 'INR', + 'IDR', + 'LKR', + 'MUR', + 'NPR', + 'PKR', + 'SCR', + 'ESP', + 'TRY', + 'ITL', +) +CENTS_UNA = ('EGP', 'JOD', 'LBP', 'SDG', 'SSP', 'SYP') + + +class Num2Word_CA(Num2Word_EU): + CURRENCY_FORMS = { + 'EUR': (('euro', 'euros'), ('cèntim', 'cèntims')), + 'ESP': (('pesseta', 'pessetes'), ('cèntim', 'cèntims')), + 'USD': (GENERIC_DOLLARS, ('centau', 'centaus')), + 'PEN': (('sol', 'sols'), ('cèntim', 'cèntims')), + 'CRC': (('colón', 'colons'), GENERIC_CENTS), + 'AUD': (GENERIC_DOLLARS, GENERIC_CENTS), + 'CAD': (GENERIC_DOLLARS, GENERIC_CENTS), + 'GBP': (('lliura', 'lliures'), ('penic', 'penics')), + 'RUB': (('ruble', 'rubles'), ('copec', 'copecs')), + 'SEK': (('corona', 'corones'), ('öre', 'öre')), + 'NOK': (('corona', 'corones'), ('øre', 'øre')), + 'PLN': (('zloty', 'zlotys'), ('grosz', 'groszy')), + 'MXN': (('peso', 'pesos'), GENERIC_CENTS), + 'RON': (('leu', 'lei'), ('ban', 'bani')), + 'INR': (('rupia', 'rupies'), ('paisa', 'paise')), + 'HUF': (('fòrint', 'fòrints'), ('fillér', 'fillérs')), + 'FRF': (('franc', 'francs'), ('cèntim', 'cèntims')), + 'CNY': (('iuan', 'iuans'), ('fen', 'jiao')), + 'CZK': (('corona', 'corones'), ('haléř', 'haléřů')), + 'NIO': (('córdoba', 'córdobas'), GENERIC_CENTS), + 'VES': (('bolívar', 'bolívars'), ('cèntim', 'cèntims')), + 'BRL': (('real', 'reals'), GENERIC_CENTS), + 'CHF': (('franc', 'francs'), ('cèntim', 'cèntims')), + 'JPY': (('ien', 'iens'), ('sen', 'sen')), + 'KRW': (('won', 'wons'), ('jeon', 'jeon')), + 'KPW': (('won', 'wons'), ('chŏn', 'chŏn')), + 'TRY': (('lira', 'lires'), ('kuruş', 'kuruş')), + 'ZAR': (('rand', 'rands'), ('cèntim', 'cèntims')), + 'KZT': (('tenge', 'tenge'), ('tin', 'tin')), + 'UAH': (('hrívnia', 'hrívnies'), ('kopiika', 'kopíok')), + 'THB': (('baht', 'bahts'), ('satang', 'satang')), + 'AED': (('dirham', 'dirhams'), ('fils', 'fulūs')), + 'AFN': (('afgani', 'afganis'), ('puli', 'puls')), + 'ALL': (('lek', 'lekë'), ('qqindarka', 'qindarkë')), + 'AMD': (('dram', 'drams'), ('luma', 'lumas')), + 'ANG': (('florí', 'florins'), ('cèntim', 'cèntims')), + 'AOA': (('kwanza', 'kwanzes'), ('cèntim', 'cèntims')), + 'ARS': (('peso', 'pesos'), GENERIC_CENTS), + 'AWG': (('florí', 'florins'), GENERIC_CENTS), + 'AZN': (('manat', 'manats'), ('qəpik', 'qəpik')), + 'BBD': (GENERIC_DOLLARS, GENERIC_CENTS), + 'BDT': (('taka', 'taka'), ('poisha', 'poisha')), + 'BGN': (('lev', 'leva'), ('stotinka', 'stotinki')), + 'BHD': (('dinar', 'dinars'), ('fils', 'fulūs')), + 'BIF': (('franc', 'francs'), ('cèntim', 'cèntims')), + 'BMD': (GENERIC_DOLLARS, GENERIC_CENTS), + 'BND': (GENERIC_DOLLARS, GENERIC_CENTS), + 'BOB': (('boliviano', 'bolivianos'), GENERIC_CENTS), + 'BSD': (GENERIC_DOLLARS, GENERIC_CENTS), + 'BTN': (('ngultrum', 'ngultrums'), ('chetrum', 'chetrums')), + 'BWP': (('pula', 'pula'), ('thebe', 'thebe')), + 'BYN': (('ruble', 'rubles'), ('copec', 'copecs')), + 'BYR': (('ruble', 'rubles'), ('copec', 'copecs')), + 'BZD': (GENERIC_DOLLARS, ('cèntim', 'cèntims')), + 'CDF': (('franc', 'francs'), ('cèntim', 'cèntims')), + 'CLP': (('peso', 'pesos'), GENERIC_CENTS), + 'COP': (('peso', 'pesos'), GENERIC_CENTS), + 'CUP': (('peso', 'pesos'), GENERIC_CENTS), + 'CVE': (('escut', 'escuts'), GENERIC_CENTS), + 'CYP': (('lliura', 'lliures'), ('cèntim', 'cèntims')), + 'DJF': (('franc', 'francs'), ('cèntim', 'cèntims')), + 'DKK': (('corona', 'corones'), ('øre', 'øre')), + 'DOP': (('peso', 'pesos'), GENERIC_CENTS), + 'DZD': (('dinar', 'dinars'), ('cèntim', 'cèntims')), + 'ECS': (('sucre', 'sucres'), GENERIC_CENTS), + 'EGP': (('lliura', 'lliures'), ('piastre', 'piastres')), + 'ERN': (('nakfa', 'nakfes'), ('cèntim', 'cèntims')), + 'ETB': (('birr', 'birr'), ('cèntim', 'cèntims')), + 'FJD': (GENERIC_DOLLARS, GENERIC_CENTS), + 'FKP': (('lliura', 'lliures'), ('penic', 'penics')), + 'GEL': (('lari', 'laris'), ('tetri', 'tetri')), + 'GHS': (('cedi', 'cedis'), ('pesewa', 'pesewas')), + 'GIP': (('lliura', 'lliures'), ('penic', 'penics')), + 'GMD': (('dalasi', 'dalasis'), ('butut', 'bututs')), + 'GNF': (('franc', 'francs'), ('cèntim', 'cèntims')), + 'GTQ': (('quetzal', 'quetzals'), GENERIC_CENTS), + 'GYD': (GENERIC_DOLLARS, GENERIC_CENTS), + 'HKD': (GENERIC_DOLLARS, GENERIC_CENTS), + 'HNL': (('lempira', 'lempires'), GENERIC_CENTS), + 'HRK': (('kuna', 'kuna'), ('lipa', 'lipa')), + 'HTG': (('gourde', 'gourdes'), ('cèntim', 'cèntims')), + 'IDR': (('rúpia', 'rúpies'), ('cèntim', 'cèntims')), + 'ILS': (('xéquel', 'xéquels'), ('agorà', 'agorot')), + 'IQD': (('dinar', 'dinars'), ('fils', 'fils')), + 'IRR': (('rial', 'rials'), ('dinar', 'dinars')), + 'ISK': (('corona', 'corones'), ('eyrir', 'aurar')), + 'ITL': (('lira', 'lires'), ('cèntim', 'cèntims')), + 'JMD': (GENERIC_DOLLARS, ('cèntim', 'cèntims')), + 'JOD': (('dinar', 'dinars'), ('piastra', 'piastres')), + 'KES': (('xiling', 'xílings'), ('cèntim', 'cèntims')), + 'KGS': (('som', 'som'), ('tyiyn', 'tyiyn')), + 'KHR': (('riel', 'riels'), ('cèntim', 'cèntims')), + 'KMF': (('franc', 'francs'), ('cèntim', 'cèntims')), + 'KWD': (('dinar', 'dinars'), ('fils', 'fils')), + 'KYD': (GENERIC_DOLLARS, ('cèntim', 'cèntims')), + 'LAK': (('kip', 'kips'), ('at', 'at')), + 'LBP': (('lliura', 'lliures'), ('piastra', 'piastres')), + 'LKR': (('rúpia', 'rúpies'), ('cèntim', 'cèntims')), + 'LRD': (GENERIC_DOLLARS, ('cèntim', 'cèntims')), + 'LSL': (('loti', 'maloti'), ('sente', 'lisente')), + 'LTL': (('lita', 'litai'), ('cèntim', 'cèntims')), + 'LYD': (('dinar', 'dinars'), ('dírham', 'dírhams')), + 'MAD': (('dírham', 'dirhams'), ('cèntim', 'cèntims')), + 'MDL': (('leu', 'lei'), ('ban', 'bani')), + 'MGA': (('ariary', 'ariary'), ('iraimbilanja', 'iraimbilanja')), + 'MKD': (('denar', 'denari'), ('deni', 'deni')), + 'MMK': (('kyat', 'kyats'), ('pya', 'pyas')), + 'MNT': (('tögrög', 'tögrög'), ('möngö', 'möngö')), + 'MOP': (('pataca', 'pataques'), ('avo', 'avos')), + 'MRO': (('ouguiya', 'ouguiya'), ('khoums', 'khoums')), + 'MRU': (('ouguiya', 'ouguiya'), ('khoums', 'khoums')), + 'MUR': (('rupia', 'rúpies'), ('cèntim', 'cèntims')), + 'MVR': (('rufiyaa', 'rufiyaa'), ('laari', 'laari')), + 'MWK': (('kwacha', 'kwacha'), ('tambala', 'tambala')), + 'MYR': (('ringgit', 'ringgits'), ('sen', 'sens')), + 'MZN': (('metical', 'meticals'), GENERIC_CENTS), + 'NAD': (GENERIC_DOLLARS, ('cèntim', 'cèntims')), + 'NGN': (('naira', 'naires'), ('kobo', 'kobos')), + 'NPR': (('rupia', 'rupies'), ('paisa', 'paises')), + 'NZD': (GENERIC_DOLLARS, GENERIC_CENTS), + 'OMR': (('rial', 'rials'), ('baisa', 'baisa')), + 'PAB': (GENERIC_DOLLARS, ('centésimo', 'centésimos')), + 'PGK': (('kina', 'kina'), ('toea', 'toea')), + 'PHP': (('peso', 'pesos'), GENERIC_CENTS), + 'PKR': (('rupia', 'rupies'), ('paisa', 'paise')), + 'PLZ': (('zloty', 'zlotys'), ('grosz', 'groszy')), + 'PYG': (('guaraní', 'guaranís'), ('cèntim', 'cèntims')), + 'QAR': (('rial', 'rials'), ('dírham', 'dírhams')), + 'QTQ': (('quetzal', 'quetzals'), GENERIC_CENTS), + 'RSD': (('dinar', 'dinars'), ('para', 'para')), + 'RUR': (('ruble', 'rubles'), ('copec', 'copecs')), + 'RWF': (('franc', 'francs'), ('cèntim', 'cèntims')), + 'SAR': (('riyal', 'riyals'), ('hàl·lala', 'hàl·lalat')), + 'SBD': (GENERIC_DOLLARS, ('cèntim', 'cèntims')), + 'SCR': (('rupia', 'rupies'), ('cèntim', 'cèntims')), + 'SDG': (('lliura', 'lliures'), ('piastre', 'piastres')), + 'SGD': (GENERIC_DOLLARS, ('cèntim', 'cèntims')), + 'SHP': (('lliura', 'lliures'), ('penic', 'penics')), + 'SLL': (('leonE', 'leones'), ('cèntim', 'cèntims')), + 'SRD': (GENERIC_DOLLARS, ('cèntim', 'cèntims')), + 'SSP': (('lliura', 'lliures'), ('piastre', 'piastres')), + 'STD': (('dobra', 'dobrAs'), ('cèntim', 'cèntims')), + 'SVC': (('colón', 'colons'), GENERIC_CENTS), + 'SYP': (('lliura', 'lliures'), ('piastre', 'piastres')), + 'SZL': (('lilangeni', 'emalangeni'), ('cèntim', 'cèntims')), + 'TJS': (('somoni', 'somoni'), ('diram', 'diram')), + 'TMT': (('manat', 'manats'), ('teňňesi', 'teňňesi')), + 'TND': (('dinar', 'dinars'), ('mil·lim', 'mil·limat')), + 'TOP': (('paanga', 'paangas'), ('seniti', 'seniti')), + 'TTD': (GENERIC_DOLLARS, ('cèntim', 'cèntims')), + 'TWD': (('nou dòlar', 'nous dòlars'), ('fen', 'fen')), + 'TZS': (('xíling', 'xílings'), ('cèntim', 'cèntims')), + 'UGX': (('xíling', 'xílings'), ('cèntim', 'cèntims')), + 'UYU': (('peso', 'pesos'), ('centèsim', 'centèsims')), + 'UZS': (('som', 'som'), ('tiyin', 'tiyin')), + 'VND': (('dong', 'dongs'), ('xu', 'xu')), + 'VUV': (('vatu', 'vatus'), ('cèntim', 'cèntims')), + 'WST': (('tala', 'tala'), ('sene', 'sene')), + 'XAF': (('franc CFA', 'francs CFA'), ('cèntim', 'cèntims')), + 'XCD': (GENERIC_DOLLARS, ('cèntim', 'cèntims')), + 'XOF': (('franc CFA', 'francs CFA'), ('cèntim', 'cèntims')), + 'XPF': (('franc CFP', 'francs CFP'), ('cèntim', 'cèntims')), + 'YER': (('rial', 'rials'), ('fils', 'fils')), + 'YUM': (('dinar', 'dinars'), ('para', 'para')), + 'ZMW': (('kwacha', 'kwacha'), ('ngwee', 'ngwee')), + 'ZWL': (GENERIC_DOLLARS, ('cèntim', 'cèntims')), + 'ZWL': (GENERIC_DOLLARS, ('cèntim', 'cèntims')), + } + + GIGA_SUFFIX = None + MEGA_SUFFIX = "ilió" + + def setup(self): + lows = ["quadr", "tr", "b", "m"] + self.high_numwords = self.gen_high_numwords([], [], lows) + self.negword = "menys " + self.pointword = "punt" + self.errmsg_nonnum = "type(%s) no és [long, int, float]" + self.errmsg_floatord = "El float %s no pot ser tractat com un" \ + " ordinal." + self.errmsg_negord = "El número negatiu %s no pot ser tractat" \ + " com un ordinal." + self.errmsg_toobig = "abs(%s) ha de ser inferior a %s." + self.gender_stem = "è" + self.exclude_title = ["i", "menys", "punt"] + + self.mid_numwords = [ + (1000, "mil"), + (100, "cent"), + (90, "noranta"), + (80, "vuitanta"), + (70, "setanta"), + (60, "seixanta"), + (50, "cinquanta"), + (40, "quaranta"), + (30, "trenta"), + ] + self.low_numwords = [ + "vint-i-nou", + "vint-i-vuit", + "vint-i-set", + "vint-i-sis", + "vint-i-cinc", + "vint-i-quatre", + "vint-i-tres", + "vint-i-dos", + "vint-i-un", + "vint", + "dinou", + "divuit", + "disset", + "setze", + "quinze", + "catorze", + "tretze", + "dotze", + "onze", + "deu", + "nou", + "vuit", + "set", + "sis", + "cinc", + "quatre", + "tres", + "dos", + "un", + "zero", + ] + self.mid_num = { + 1000: "mil", + 100: "cent", + 90: "noranta", + 80: "vuitanta", + 70: "setanta", + 60: "seixanta", + 50: "cinquanta", + 40: "quaranta", + 30: "trenta", + 20: "vint", + 10: "deu", + } + self.low_num = { + 0: "zero", + 1: "un", + 2: "dos", + 3: "tres", + 4: "quatre", + 5: "cinc", + 6: "sis", + 7: "set", + 8: "vuit", + 9: "nou", + 10: "deu", + 11: "onze", + 12: "dotze", + 13: "tretze", + 14: "catorze", + 15: "quinze", + 16: "setze", + 17: "disset", + 18: "divuit", + 19: "dinou", + 20: "vint", + 21: "vint-i-un", + 22: "vint-i-dos", + 23: "vint-i-tres", + 24: "vint-i-quatre", + 25: "vint-i-cinc", + 26: "vint-i-sis", + 27: "vint-i-set", + 28: "vint-i-vuit", + 29: "vint-i-nou", + } + self.ords = { + 1: "primer", + 2: "segon", + 3: "tercer", + 4: "quart", + 5: "cinqu", + 6: "sis", + 7: "set", + 8: "vuit", + 9: "nov", + 10: "des", + 11: "onz", + 12: "dotz", + 13: "tretz", + 14: "catorz", + 15: "quinz", + 16: "setz", + 17: "disset", + 18: "divuit", + 19: "dinov", + 20: "vint", + 30: "trent", + 40: "quarant", + 50: "cinquant", + 60: "seixant", + 70: "setant", + 80: "vuitant", + 90: "norant", + 100: "cent", + 200: "dos-cent", + 300: "tres-cent", + 400: "quatre-cent", + 500: "cinc-cent", + 600: "sis-cent", + 700: "set-cent", + 800: "vuit-cent", + 900: "nou-cent", + 1e3: "mil", + 1e6: "milion", + 1e9: "mil milion", + 1e12: "bilion", + 1e15: "mil bilion", + } + + self.ords_2 = {1: "1r", 2: "2n", 3: "3r", 4: "4t"} + self.ords_3 = { + 1: "unè", + 2: "dosè", + 3: "tresè", + 4: "quatrè", + 5: "cinquè", + 6: "sisè", + 7: "setè", + 8: "vuitè", + 9: "novè", + } + + def merge(self, curr, next): + ctext, cnum, ntext, nnum = curr + next + if cnum == 1: + if nnum < 1000000: + return next + ctext = "un" + + if nnum < cnum: + if cnum < 100: + return "%s-%s" % (ctext, ntext), cnum + nnum + elif nnum == 1: + return "%s %s" % (ctext, ntext), cnum + nnum + elif cnum == 100: + return "%s %s" % (ctext, ntext), cnum + nnum + else: + return "%s %s" % (ctext, ntext), cnum + nnum + elif (not nnum % 1000000) and cnum > 1: + ntext = ntext[:-3] + "lions" + if nnum == 100: + ntext += "s" + ctext += "-" + else: + ntext = " " + ntext + return (ctext + ntext, cnum * nnum) + + def to_ordinal(self, value): + self.verify_ordinal(value) + if value == 0: + text = "" + elif value < 5: + text = self.ords[value] + elif value <= 20: + text = "%s%s" % (self.ords[value], self.gender_stem) + elif value <= 30: + frac = value % 10 + text = "%s%s%s" % (self.ords[20], "-i-", self.ords_3[frac]) + elif value < 100: + dec = (value // 10) * 10 + text = "%s%s%s%s" % (self.ords[dec], "a", + "-", self.ords_3[value - dec]) + elif value == 1e2: + text = "%s%s" % (self.ords[value], self.gender_stem) + elif value < 2e2: + cen = (value // 100) * 100 + text = "%s %s" % (self.ords[cen], self.to_ordinal(value - cen)) + elif value < 1e3: + cen = (value // 100) * 100 + text = "%s%s %s" % (self.ords[cen], "s", + self.to_ordinal(value - cen)) + elif value == 1e3: + text = "%s%s" % (self.ords[value], self.gender_stem) + elif value < 1e6: + dec = 1000 ** int(math.log(int(value), 1000)) + high_part, low_part = divmod(value, dec) + cardinal = self.to_cardinal(high_part) if high_part != 1 else "" + text = "%s %s %s" % (cardinal, self.ords[dec], + self.to_ordinal(low_part)) + elif value < 1e18: + dec = 1000 ** int(math.log(int(value), 1000)) + high_part, low_part = divmod(value, dec) + cardinal = self.to_cardinal(high_part) if high_part != 1 else "" + text = "%s%s%s %s" % (cardinal, self.ords[dec], + self.gender_stem, self.to_ordinal(low_part)) + else: + part1 = self.to_cardinal(value) + text = "%s%s" % (part1[:-1], "onè") + return text.strip() + + def to_ordinal_num(self, value): + self.verify_ordinal(value) + if value not in self.ords_2: + return "%s%s" % (value, "è" if self.gender_stem == "è" else "a") + else: + return self.ords_2[value] + + def to_currency(self, val, currency="EUR", cents=True, + separator=" amb", adjective=False): + result = super(Num2Word_CA, self).to_currency( + val, currency=currency, cents=cents, + separator=separator, adjective=adjective + ) + list_result = result.split(separator + " ") + + if currency in CURRENCIES_UNA: + list_result[0] = list_result[0].replace("un", "una") + list_result[0] = list_result[0].replace("dos", "dues") + list_result[0] = list_result[0].replace("cents", "centes") + + list_result[0] = list_result[0].replace("vint-i-un", "vint-i-un") + list_result[0] = list_result[0].replace(" i un", "-un") + list_result[0] = list_result[0].replace("un", "un") + + if currency in CENTS_UNA: + list_result[1] = list_result[1].replace("un", "una") + list_result[1] = list_result[1].replace("dos", "dues") + + list_result[1] = list_result[1].replace("vint-i-un", "vint-i-una") + + list_result[1] = list_result[1].replace("un", "un") + + result = (separator + " ").join(list_result) + + return result diff --git a/num2words/lang_EU.py b/num2words/lang_EU.py index 7c07bb56..0ff74ab2 100644 --- a/num2words/lang_EU.py +++ b/num2words/lang_EU.py @@ -53,7 +53,7 @@ class Num2Word_EU(Num2Word_Base): CURRENCY_ADJECTIVES = { 'AUD': 'Australian', - 'BYN': 'Belarussian', + 'BYN': 'Belarusian', 'CAD': 'Canadian', 'EEK': 'Estonian', 'USD': 'US', diff --git a/num2words/lang_TET.py b/num2words/lang_TET.py new file mode 100644 index 00000000..141a8c66 --- /dev/null +++ b/num2words/lang_TET.py @@ -0,0 +1,251 @@ +# -*- coding: utf-8 -*-Num2Word_TET +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. + +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA + + +from num2words.currency import parse_currency_parts + +from .lang_EU import Num2Word_EU + +DOLLAR = ('dolar', 'dolar') +CENTS = ('sentavu', 'sentavu') + + +class Num2Word_TET(Num2Word_EU): + + CURRENCY_FORMS = { + 'AUD': (DOLLAR, CENTS), + 'CAD': (DOLLAR, CENTS), + 'EUR': (('euro', 'euros'), CENTS), + 'GBP': (('pound sterling', 'pound sterling'), ('pence', 'pence')), + 'USD': (DOLLAR, CENTS), + } + + GIGA_SUFFIX = None + MEGA_SUFFIX = "iliaun" + + def setup(self): + super().setup() + lows = ["kuatr", "tr", "b", "m"] + self.high_numwords = self.gen_high_numwords([], [], lows) + self.negword = "menus " + self.pointword = "vírgula" + self.exclude_title = ["resin", "vírgula", "menus"] + self.count = 0 + + self.mid_numwords = [ + (1000, "rihun"), (100, "atus"), (90, "sianulu"), + (80, "ualunulu"), (70, "hitunulu"), (60, "neenulu"), + (50, "limanulu"), (40, "haatnulu"), (30, "tolunulu"), + (20, "ruanulu") + ] + self.low_numwords = [ + "sanulu", + "sia", "ualu", "hitu", "neen", "lima", "haat", "tolu", "rua", + "ida", "mamuk" + ] + self.hundreds = { + 1: "atus", + 2: "atus rua", + 3: "atus tolu", + 4: "atus haat", + 5: "atus lima", + 6: "atus neen", + 7: "atus hitu", + 8: "atus ualu", + 9: "atus sia", + } + + def merge(self, curr, next): + ctext, cnum, ntext, nnum = curr + next + + if cnum == 1 and nnum < 100: + return next + + if nnum < cnum: + if nnum < 10: + value_str = str(cnum + nnum) + if int(value_str) > 100: + zero_list = value_str[1:-1] + all_zero = all(element == '0' for element in zero_list) + if all_zero: + if self.count >= 1: + self.count += 0 + return ( + "ho %s %s" % (ctext, ntext), + cnum + nnum + ) + self.count += 1 + return ("%s %s" % (ctext, ntext), cnum + nnum) + + return ("%s resin %s" % (ctext, ntext), cnum + nnum) + else: + return ("%s %s" % (ctext, ntext), cnum + nnum) + + return (ntext + " " + ctext, cnum * nnum) + + def ho_result(self, result, value): + index = result.find('ho') + count_ho = result.count('ho') + + if index != -1 and count_ho >= 1: + index_rihun = result.find('rihun') + value_str = len(str(value)) + if index_rihun != -1 and value_str > 7: + result = result.replace("rihun ho", "ho rihun") + lows = ["kuatr", "tr", "b", "m"] + MEGA_SUFFIX = "iliaun" + for low in lows: + result = result.replace( + low + MEGA_SUFFIX + " ho", "ho " + low + MEGA_SUFFIX) + remove_first_ho = result.startswith('ho') + if remove_first_ho: + result = result[3:] + return result + + def remove_ho(self, result, value): + value_str = str(value) + result = self.ho_result(result, value) + end_value = value_str[:-4] + end_true = end_value.endswith('0') + if end_true is False: + if value > 100: + if value_str[-1] != '0' and value_str[-2] == '0': + result = result.replace("ho", "") + result = result.replace(" ", " ") + + return result + + def to_cardinal(self, value): + result = super().to_cardinal(value) + + results = self.remove_ho(result, value) + return results + + def to_ordinal(self, value): + self.verify_ordinal(value) + out = "" + val = self.splitnum(value) + outs = val + while len(val) != 1: + outs = [] + left, right = val[:2] + if isinstance(left, tuple) and isinstance(right, tuple): + outs.append(self.merge(left, right)) + if val[2:]: + outs.append(val[2:]) + else: + for elem in val: + if isinstance(elem, list): + if len(elem) == 1: + outs.append(elem[0]) + else: + outs.append(self.clean(elem)) + else: + outs.append(elem) + val = outs + + words, num = outs[0] + + words = self.remove_ho(words, value) + + if num in [90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 5, 3, 2]: + words = 'da'+words+'k' + if num in [6, 4]: + words = 'da'+words + if num == 1: + words = 'dahuluk' + if num in [900, 800, 700, 500, 300, 200, 100]: + words = 'dah'+words+'k' + if num in [600, 400]: + words = 'dah'+words + + words_split = words.split() + if len(words_split) >= 3 and num < 100: + first_word = 'da'+words_split[0] + second_word = " ".join(words_split[1:]) + if 'haat' in second_word or 'neen' in second_word: + words = first_word+" "+second_word + else: + words = first_word+" "+second_word+'k' + + word_first = 'dah'+words_split[0] + if word_first == 'dahatus' and len(words_split) >= 3: + word_second = " ".join(words_split[1:]) + if 'haat' in word_second or 'neen' in word_second: + words = word_first+" "+word_second + else: + words = word_first+" "+word_second+'k' + + if len(str(num)) > 3: + if 'haat' in words_split[-1:] or 'neen' in words_split[-1:]: + words = 'da'+words + else: + words = 'da'+words+'k' + + result = self.title(out + words) + + return result + + def to_ordinal_num(self, value): + self.verify_ordinal(value) + return "%sº" % (value) + + def to_year(self, val, longval=True): + if val < 0: + return self.to_cardinal(abs(val)) + ' antes Kristu' + return self.to_cardinal(val) + + def to_currency(self, val, currency='USD', cents=True): + """ + Args: + val: Numeric value + currency (str): Currency code + cents (bool): Verbose cents + adjective (bool): Prefix currency name with adjective + Returns: + str: Formatted string + + """ + left, right, is_negative = parse_currency_parts(val) + + try: + cr1, cr2 = self.CURRENCY_FORMS[currency] + + except KeyError: + raise NotImplementedError( + 'Currency code "%s" not implemented for "%s"' % + (currency, self.__class__.__name__)) + + minus_str = "%s " % self.negword.strip() if is_negative else "" + money_str = self._money_verbose(left, currency) + cents_str = self._cents_verbose(right, currency) \ + if cents else self._cents_terse(right, currency) + + if right == 0: + return u'%s%s %s' % ( + minus_str, + self.pluralize(left, cr1), + money_str + ) + else: + return u'%s%s %s %s %s' % ( + minus_str, + self.pluralize(left, cr1), + money_str, + self.pluralize(right, cr2), + cents_str + ) diff --git a/tests/test_by.py b/tests/test_be.py similarity index 61% rename from tests/test_by.py rename to tests/test_be.py index 087c0c11..c674e98b 100644 --- a/tests/test_by.py +++ b/tests/test_be.py @@ -25,25 +25,25 @@ class Num2WordsBYTest(TestCase): def test_cardinal(self): - self.assertEqual(num2words(100, lang="by"), "сто") - self.assertEqual(num2words(101, lang="by"), "сто адзін") - self.assertEqual(num2words(110, lang="by"), "сто дзесяць") - self.assertEqual(num2words(115, lang="by"), "сто пятнаццаць") - self.assertEqual(num2words(123, lang="by"), "сто дваццаць тры") - self.assertEqual(num2words(1000, lang="by"), "адна тысяча") - self.assertEqual(num2words(1001, lang="by"), "адна тысяча адзін") - self.assertEqual(num2words(2012, lang="by"), "дзве тысячы дванаццаць") - self.assertEqual( - num2words(12519.85, lang="by"), + self.assertEqual(num2words(100, lang="be"), "сто") + self.assertEqual(num2words(101, lang="be"), "сто адзін") + self.assertEqual(num2words(110, lang="be"), "сто дзесяць") + self.assertEqual(num2words(115, lang="be"), "сто пятнаццаць") + self.assertEqual(num2words(123, lang="be"), "сто дваццаць тры") + self.assertEqual(num2words(1000, lang="be"), "адна тысяча") + self.assertEqual(num2words(1001, lang="be"), "адна тысяча адзін") + self.assertEqual(num2words(2012, lang="be"), "дзве тысячы дванаццаць") + self.assertEqual( + num2words(12519.85, lang="be"), "дванаццаць тысяч пяцьсот дзевятнаццаць коска восемдзесят пяць", ) self.assertEqual( - num2words(1234567890, lang="by"), + num2words(1234567890, lang="be"), "адзін мільярд дзвесце трыццаць чатыры мільёны пяцьсот " "шэсцьдзясят сем тысяч восемсот дзевяноста", ) self.assertEqual( - num2words(461407892039002157189883901676, lang="by"), + num2words(461407892039002157189883901676, lang="be"), "чатырыста шэсцьдзясят адзін " "актыльён чатырыста сем сэптыльёнаў восемсот дзевяноста " "два секстыльёны трыццаць дзевяць квінтыльёнаў два квадрыльёны " @@ -52,7 +52,7 @@ def test_cardinal(self): "шэсцьсот семдзесят шэсць", ) self.assertEqual( - num2words(94234693663034822824384220291, lang="by"), + num2words(94234693663034822824384220291, lang="be"), "дзевяноста чатыры актыльёны " "дзвесце трыццаць чатыры сэптыльёны шэсцьсот дзевяноста тры " "секстыльёны шэсцьсот шэсцьдзясят тры квінтыльёны трыццаць " @@ -60,250 +60,280 @@ def test_cardinal(self): "дваццаць чатыры мільярды трыста восемдзесят чатыры мільёны " "дзвесце дваццаць тысяч дзвесце дзевяноста адзін", ) - self.assertEqual(num2words(5, lang="by"), "пяць") - self.assertEqual(num2words(15, lang="by"), "пятнаццаць") - self.assertEqual(num2words(154, lang="by"), "сто пяцьдзясят чатыры") + self.assertEqual(num2words(5, lang="be"), "пяць") + self.assertEqual(num2words(15, lang="be"), "пятнаццаць") + self.assertEqual(num2words(154, lang="be"), "сто пяцьдзясят чатыры") self.assertEqual( - num2words(1135, lang="by"), "адна тысяча сто трыццаць пяць" + num2words(1135, lang="be"), "адна тысяча сто трыццаць пяць" ) self.assertEqual( - num2words(418531, lang="by"), + num2words(418531, lang="be"), "чатырыста васямнаццаць тысяч пяцьсот трыццаць адзін", ) self.assertEqual( - num2words(1000139, lang="by"), "адзін мільён сто трыццаць дзевяць" + num2words(1000139, lang="be"), "адзін мільён сто трыццаць дзевяць" ) - self.assertEqual(num2words(-1, lang="by"), "мінус адзін") - self.assertEqual(num2words(-15, lang="by"), "мінус пятнаццаць") - self.assertEqual(num2words(-100, lang="by"), "мінус сто") + self.assertEqual(num2words(-1, lang="be"), "мінус адзін") + self.assertEqual(num2words(-15, lang="be"), "мінус пятнаццаць") + self.assertEqual(num2words(-100, lang="be"), "мінус сто") def test_floating_point(self): - self.assertEqual(num2words(5.2, lang="by"), "пяць коска два") - self.assertEqual(num2words(10.02, lang="by"), "дзесяць коска нуль два") + self.assertEqual(num2words(5.2, lang="be"), "пяць коска два") + self.assertEqual(num2words(10.02, lang="be"), "дзесяць коска нуль два") self.assertEqual( - num2words(15.007, lang="by"), "пятнаццаць коска нуль нуль сем" + num2words(15.007, lang="be"), "пятнаццаць коска нуль нуль сем" ) self.assertEqual( - num2words(561.42, lang="by"), + num2words(561.42, lang="be"), "пяцьсот шэсцьдзясят адзін коска сорак два", ) self.assertEqual( - num2words(561.0, lang="by"), "пяцьсот шэсцьдзясят адзін коска нуль" + num2words(561.0, lang="be"), "пяцьсот шэсцьдзясят адзін коска нуль" ) def test_to_ordinal(self): - self.assertEqual(num2words(1, lang="by", to="ordinal"), "першы") - self.assertEqual(num2words(5, lang="by", to="ordinal"), "пяты") - self.assertEqual(num2words(6, lang="by", to="ordinal"), "шосты") - self.assertEqual(num2words(10, lang="by", to="ordinal"), "дзясяты") + self.assertEqual(num2words(1, lang="be", to="ordinal"), "першы") + self.assertEqual(num2words(5, lang="be", to="ordinal"), "пяты") + self.assertEqual(num2words(6, lang="be", to="ordinal"), "шосты") + self.assertEqual(num2words(10, lang="be", to="ordinal"), "дзясяты") - self.assertEqual(num2words(13, lang="by", to="ordinal"), "трынаццаты") - self.assertEqual(num2words(20, lang="by", to="ordinal"), "дваццаты") + self.assertEqual(num2words(13, lang="be", to="ordinal"), "трынаццаты") + self.assertEqual(num2words(20, lang="be", to="ordinal"), "дваццаты") self.assertEqual( - num2words(23, lang="by", to="ordinal"), "дваццаць трэці" + num2words(23, lang="be", to="ordinal"), "дваццаць трэці" ) self.assertEqual( - num2words(23, lang="by", to="ordinal", gender="f"), + num2words(23, lang="be", to="ordinal", gender="f"), "дваццаць трэцяя", ) self.assertEqual( - num2words(23, lang="by", to="ordinal", gender="n"), + num2words(23, lang="be", to="ordinal", gender=True), + "дваццаць трэцяя", + ) + self.assertEqual( + num2words(23, lang="be", to="ordinal", gender="n"), "дваццаць трэцяе", ) - self.assertEqual(num2words(40, lang="by", to="ordinal"), "саракавы") self.assertEqual( - num2words(61, lang="by", to="ordinal"), "шэсцьдзясят першы" + num2words(46, lang="be", to="ordinal", gender="m"), + "сорак шосты", + ) + self.assertEqual(num2words(40, lang="be", to="ordinal"), "саракавы") + self.assertEqual( + num2words(61, lang="be", to="ordinal"), "шэсцьдзясят першы" + ) + self.assertEqual(num2words(70, lang="be", to="ordinal"), "сямідзясяты") + self.assertEqual(num2words(100, lang="be", to="ordinal"), "соты") + self.assertEqual( + num2words(136, lang="be", to="ordinal"), "сто трыццаць шосты" ) - self.assertEqual(num2words(70, lang="by", to="ordinal"), "сямідзясяты") - self.assertEqual(num2words(100, lang="by", to="ordinal"), "соты") + self.assertEqual(num2words(500, lang="be", to="ordinal"), "пяцісоты") + self.assertEqual( - num2words(136, lang="by", to="ordinal"), "сто трыццаць шосты" + num2words(500, lang="be", to="ordinal", gender="f"), "пяцісотая" ) - self.assertEqual(num2words(500, lang="by", to="ordinal"), "пяцісоты") self.assertEqual( - num2words(500, lang="by", to="ordinal", gender="f"), "пяцісотая" + num2words(500, lang="be", to="ordinal", gender="n"), "пяцісотае" ) + self.assertEqual(num2words(1000, lang="be", to="ordinal"), "тысячны") + self.assertEqual( - num2words(500, lang="by", to="ordinal", gender="n"), "пяцісотае" + num2words(1000, lang="be", to="ordinal", gender="f"), "тысячная" ) - self.assertEqual(num2words(1000, lang="by", to="ordinal"), "тысячны") + self.assertEqual( + num2words(1000, lang="be", to="ordinal", gender="n"), "тысячнае" + ) self.assertEqual( - num2words(1000, lang="by", to="ordinal", gender="f"), "тысячная" + num2words(1001, lang="be", to="ordinal"), "тысяча першы" + ) + self.assertEqual( + num2words(3000, lang="be", to="ordinal"), "трохтысячны" + ) + self.assertEqual( + num2words(10000, lang="be", to="ordinal"), "дзесяцітысячны" + ) + self.assertEqual( + num2words(30000, lang="be", to="ordinal"), "трыццацітысячны" + ) + self.assertEqual( + num2words(42000, lang="be", to="ordinal"), "саракадвухтысячны" ) self.assertEqual( - num2words(1000, lang="by", to="ordinal", gender="n"), "тысячнае" + num2words(75000, lang="be", to="ordinal"), "сямідзесяціпяцітысячны" ) self.assertEqual( - num2words(1001, lang="by", to="ordinal"), "тысяча першы" + num2words(1000000, lang="be", to="ordinal"), "мільённы" ) self.assertEqual( - num2words(2000, lang="by", to="ordinal"), "двухтысячны" + num2words(30000000, lang="be", to="ordinal"), "трыццацімільённы" ) self.assertEqual( - num2words(10000, lang="by", to="ordinal"), "дзесяцітысячны" + num2words(1000000000, lang="be", to="ordinal"), "мільярдны" ) self.assertEqual( - num2words(42000, lang="by", to="ordinal"), "саракадвухтысячны" + num2words(3000000000, lang="be", to="ordinal"), "трохмільярдны" ) self.assertEqual( - num2words(1000000, lang="by", to="ordinal"), "мільённы" + num2words(43000000000, lang="be", to="ordinal"), + "саракатрохмільярдны", ) self.assertEqual( - num2words(1000000000, lang="by", to="ordinal"), "мільярдны" + num2words(333000000000, lang="be", to="ordinal"), + "трыстатрыццацітрохмільярдны", ) def test_to_currency(self): self.assertEqual( - num2words(1.0, lang="by", to="currency", currency="EUR"), + num2words(1.0, lang="be", to="currency", currency="EUR"), "адзін еўра, нуль цэнтаў", ) self.assertEqual( - num2words(1.0, lang="by", to="currency", currency="RUB"), + num2words(1.0, lang="be", to="currency", currency="RUB"), "адзін расійскі рубель, нуль капеек", ) self.assertEqual( - num2words(1.0, lang="by", to="currency", currency="BYN"), + num2words(1.0, lang="be", to="currency", currency="BYN"), "адзін беларускі рубель, нуль капеек", ) self.assertEqual( - num2words(1.0, lang="by", to="currency", currency="UAH"), + num2words(1.0, lang="be", to="currency", currency="UAH"), "адна грыўна, нуль капеек", ) self.assertEqual( - num2words(1234.56, lang="by", to="currency", currency="EUR"), + num2words(1234.56, lang="be", to="currency", currency="EUR"), "адна тысяча дзвесце трыццаць чатыры еўра, " "пяцьдзясят шэсць цэнтаў", ) self.assertEqual( - num2words(1234.56, lang="by", to="currency", currency="RUB"), + num2words(1234.56, lang="be", to="currency", currency="RUB"), "адна тысяча дзвесце трыццаць чатыры расійскія рублі, " "пяцьдзясят шэсць капеек", ) self.assertEqual( - num2words(1234.56, lang="by", to="currency", currency="BYN"), + num2words(1234.56, lang="be", to="currency", currency="BYN"), "адна тысяча дзвесце трыццаць чатыры беларускія рублі, " "пяцьдзясят шэсць капеек", ) self.assertEqual( - num2words(1234.56, lang="by", to="currency", currency="UAH"), + num2words(1234.56, lang="be", to="currency", currency="UAH"), "адна тысяча дзвесце трыццаць чатыры грыўны, " "пяцьдзясят шэсць капеек", ) self.assertEqual( num2words( - 10111, lang="by", to="currency", currency="EUR", separator=" і" + 10111, lang="be", to="currency", currency="EUR", separator=" і" ), "сто адзін еўра і адзінаццаць цэнтаў", ) self.assertEqual( num2words( - 10111, lang="by", to="currency", currency="RUB", separator=" і" + 10111, lang="be", to="currency", currency="RUB", separator=" і" ), "сто адзін расійскі рубель і адзінаццаць капеек", ) self.assertEqual( num2words( - 10111, lang="by", to="currency", currency="BYN", separator=" і" + 10111, lang="be", to="currency", currency="BYN", separator=" і" ), "сто адзін беларускі рубель і адзінаццаць капеек", ) self.assertEqual( num2words( - 10111, lang="by", to="currency", currency="UAH", separator=" і" + 10111, lang="be", to="currency", currency="UAH", separator=" і" ), "сто адна грыўна і адзінаццаць капеек", ) self.assertEqual( num2words( - 10121, lang="by", to="currency", currency="EUR", separator=" і" + 10121, lang="be", to="currency", currency="EUR", separator=" і" ), "сто адзін еўра і дваццаць адзін цэнт", ) self.assertEqual( num2words( - 10121, lang="by", to="currency", currency="RUB", separator=" і" + 10121, lang="be", to="currency", currency="RUB", separator=" і" ), "сто адзін расійскі рубель і дваццаць адна капейка", ) self.assertEqual( num2words( - 10121, lang="by", to="currency", currency="BYN", separator=" і" + 10121, lang="be", to="currency", currency="BYN", separator=" і" ), "сто адзін беларускі рубель і дваццаць адна капейка", ) self.assertEqual( num2words( - 10121, lang="by", to="currency", currency="UAH", separator=" і" + 10121, lang="be", to="currency", currency="UAH", separator=" і" ), "сто адна грыўна і дваццаць адна капейка", ) self.assertEqual( num2words( - 10122, lang="by", to="currency", currency="EUR", separator=" і" + 10122, lang="be", to="currency", currency="EUR", separator=" і" ), "сто адзін еўра і дваццаць два цэнты", ) self.assertEqual( num2words( - 10122, lang="by", to="currency", currency="RUB", separator=" і" + 10122, lang="be", to="currency", currency="RUB", separator=" і" ), "сто адзін расійскі рубель і дваццаць дзве капейкі", ) self.assertEqual( num2words( - 10122, lang="by", to="currency", currency="BYN", separator=" і" + 10122, lang="be", to="currency", currency="BYN", separator=" і" ), "сто адзін беларускі рубель і дваццаць дзве капейкі", ) self.assertEqual( num2words( - 10122, lang="by", to="currency", currency="UAH", separator=" і" + 10122, lang="be", to="currency", currency="UAH", separator=" і" ), "сто адна грыўна і дваццаць дзве капейкі", ) self.assertEqual( num2words( - 10122, lang="by", to="currency", currency="KZT", separator=" і" + 10122, lang="be", to="currency", currency="KZT", separator=" і" ), "сто адзін тэнге і дваццаць два тыйіны", ) self.assertEqual( num2words( - -1251985, lang="by", to="currency", currency="EUR", cents=False + -1251985, lang="be", to="currency", currency="EUR", cents=False ), "мінус дванаццаць тысяч пяцьсот дзевятнаццаць еўра, 85 цэнтаў", ) self.assertEqual( num2words( - -1251985, lang="by", to="currency", currency="RUB", cents=False + -1251985, lang="be", to="currency", currency="RUB", cents=False ), "мінус дванаццаць тысяч пяцьсот дзевятнаццаць " "расійскіх рублёў, 85 капеек", ) self.assertEqual( num2words( - -1251985, lang="by", to="currency", currency="BYN", cents=False + -1251985, lang="be", to="currency", currency="BYN", cents=False ), "мінус дванаццаць тысяч пяцьсот дзевятнаццаць " "беларускіх рублёў, 85 капеек", ) self.assertEqual( num2words( - -1251985, lang="by", to="currency", currency="UAH", cents=False + -1251985, lang="be", to="currency", currency="UAH", cents=False ), "мінус дванаццаць тысяч пяцьсот дзевятнаццаць грыўнаў, 85 капеек", ) self.assertEqual( num2words( "38.4", - lang="by", + lang="be", to="currency", separator=" і", cents=False, @@ -314,7 +344,7 @@ def test_to_currency(self): self.assertEqual( num2words( "38.4", - lang="by", + lang="be", to="currency", separator=" і", cents=False, @@ -325,7 +355,7 @@ def test_to_currency(self): self.assertEqual( num2words( "38.4", - lang="by", + lang="be", to="currency", separator=" і", cents=False, @@ -334,22 +364,38 @@ def test_to_currency(self): "трыццаць восем грыўнаў і 40 капеек", ) self.assertEqual( - num2words("1230.56", lang="by", to="currency", currency="USD"), + num2words("1230.56", lang="be", to="currency", currency="USD"), "адна тысяча дзвесце трыццаць долараў, пяцьдзясят шэсць цэнтаў", ) self.assertEqual( - num2words("1231.56", lang="by", to="currency", currency="USD"), + num2words("1231.56", lang="be", to="currency", currency="USD"), "адна тысяча дзвесце трыццаць адзін долар, " "пяцьдзясят шэсць цэнтаў", ) self.assertEqual( - num2words("1234.56", lang="by", to="currency", currency="USD"), + num2words("1234.56", lang="be", to="currency", currency="USD"), "адна тысяча дзвесце трыццаць чатыры долары, пяцьдзясят шэсць " "цэнтаў", ) self.assertEqual( num2words( - 10122, lang="by", to="currency", currency="UZS", separator=" і" + 10122, lang="be", to="currency", currency="UZS", separator=" і" ), "сто адзін сум і дваццаць два тыйіны", ) + + self.assertEqual( + num2words(1.0, lang="be", to="currency", currency="PLN"), + "адзін злоты, нуль грошаў", + ) + + self.assertEqual( + num2words(23.40, lang="be", to="currency", currency="PLN"), + "дваццаць тры злотых, сорак грошаў", + ) + + self.assertEqual( + num2words(9999.39, lang="be", to="currency", currency="PLN"), + "дзевяць тысяч дзевяцьсот дзевяноста дзевяць злотых, " + "трыццаць дзевяць грошаў", + ) diff --git a/tests/test_ca.py b/tests/test_ca.py new file mode 100644 index 00000000..ab5be158 --- /dev/null +++ b/tests/test_ca.py @@ -0,0 +1,186 @@ +from __future__ import unicode_literals + +from unittest import TestCase + +from num2words import num2words + +TEST_CASES_CARDINAL = ( + (1, "un"), + (2, "dos"), + (3, "tres"), + (5.5, "cinc punt cinc"), + (11, "onze"), + (12, "dotze"), + (16, "setze"), + (17.42, "disset punt quatre dos"), + (19, "dinou"), + (20, "vint"), + (21, "vint-i-un"), + (26, "vint-i-sis"), + (27.312, "vint-i-set punt tres un dos"), + (28, "vint-i-vuit"), + (30, "trenta"), + (31, "trenta-un"), + (40, "quaranta"), + (44, "quaranta-quatre"), + (50, "cinquanta"), + (53.486, "cinquanta-tres punt quatre vuit sis"), + (55, "cinquanta-cinc"), + (60, "seixanta"), + (67, "seixanta-set"), + (70, "setanta"), + (79, "setanta-nou"), + (89, "vuitanta-nou"), + (95, "noranta-cinc"), + (100, "cent"), + (101, "cent un"), + (199, "cent noranta-nou"), + (203, "dos-cents tres"), + (287, "dos-cents vuitanta-set"), + (300.42, "tres-cents punt quatre dos"), + (356, "tres-cents cinquanta-sis"), + (400, "quatre-cents"), + (434, "quatre-cents trenta-quatre"), + (555, "cinc-cents cinquanta-cinc"), + (578, "cinc-cents setanta-vuit"), + (666, "sis-cents seixanta-sis"), + (689, "sis-cents vuitanta-nou"), + (729, "set-cents vint-i-nou"), + (777, "set-cents setanta-set"), + (888, "vuit-cents vuitanta-vuit"), + (894, "vuit-cents noranta-quatre"), + (999, "nou-cents noranta-nou"), + (1000, "mil"), + (1001, "mil un"), + (1097, "mil noranta-set"), + (1104, "mil cent quatre"), + (1243, "mil dos-cents quaranta-tres"), + (2385, "dos mil tres-cents vuitanta-cinc"), + (3766, "tres mil set-cents seixanta-sis"), + (4196, "quatre mil cent noranta-sis"), + (4196.42, "quatre mil cent noranta-sis punt quatre dos"), + (5846, "cinc mil vuit-cents quaranta-sis"), + (6459, "sis mil quatre-cents cinquanta-nou"), + (7232, "set mil dos-cents trenta-dos"), + (8569, "vuit mil cinc-cents seixanta-nou"), + (9539, "nou mil cinc-cents trenta-nou"), + (1000000, "un milió"), + (1000001, "un milió un"), + (4000000, "quatre milions"), + (10000000000000, "deu bilions"), + (100000000000000, "cent bilions"), + (1000000000000000000, "un trilió"), + (1000000000000000000000, "mil trilions"), + (10000000000000000000000000, "deu quadrilions"), +) + +TEST_CASES_ORDINAL = ( + (1, "primer"), + (2, "segon"), + (8, "vuitè"), + (12, "dotzè"), + (14, "catorzè"), + (28, "vint-i-vuitè"), + (33, "trenta-tresè"), + (88, "vuitanta-vuitè"), + (100, "centè"), + (128, "cent vint-i-vuitè"), + (199, "cent noranta-novè"), + (1000, "milè"), + (1827, "mil vuit-cents vint-i-setè"), + (12345, "dotze mil tres-cents quaranta-cinquè"), + (1000000, "milionè"), + (1000000000000000, "mil bilionè"), + (1000000000000000, "mil bilionè"), + (1000000000000000000, "un trilionè"), # over 1e18 is not supported +) + +TEST_CASES_ORDINAL_NUM = ( + (1, "1r"), + (8, "8è"), + (12, "12è"), + (14, "14è"), + (28, "28è"), + (100, "100è"), + (1000, "1000è"), + (1000000, "1000000è"), +) + +TEST_CASES_TO_CURRENCY = ( + (1.00, "un euro amb zero cèntims"), + (1.01, "un euro amb un cèntim"), + (2.00, "dos euros amb zero cèntims"), + (8.00, "vuit euros amb zero cèntims"), + (12.00, "dotze euros amb zero cèntims"), + (21.00, "vint-i-un euros amb zero cèntims"), + (81.25, "vuitanta-un euros amb vint-i-cinc cèntims"), + (350.90, "tres-cents cinquanta euros amb noranta cèntims"), + (100.00, "cent euros amb zero cèntims"), +) + +TEST_CASES_TO_CURRENCY_ESP = ( + (1.00, "una pesseta amb zero cèntims"), + (1.01, "una pesseta amb un cèntim"), + (2.00, "dues pessetes amb zero cèntims"), + (8.00, "vuit pessetes amb zero cèntims"), + (12.00, "dotze pessetes amb zero cèntims"), + (21.00, "vint-i-una pessetes amb zero cèntims"), + (81.25, "vuitanta-una pessetes amb vint-i-cinc cèntims"), + (350.90, "tres-centes cinquanta pessetes amb noranta cèntims"), + (100.00, "cent pessetes amb zero cèntims"), +) + +TEST_CASES_TO_CURRENCY_USD = ( + (1.00, "un dòlar amb zero centaus"), + (2.00, "dos dòlars amb zero centaus"), + (8.00, "vuit dòlars amb zero centaus"), + (12.00, "dotze dòlars amb zero centaus"), + (21.00, "vint-i-un dòlars amb zero centaus"), + (81.25, "vuitanta-un dòlars amb vint-i-cinc centaus"), + (350.90, "tres-cents cinquanta dòlars amb noranta centaus"), + (100.00, "cent dòlars amb zero centaus"), +) + + +TEST_CASES_TO_CURRENCY_GBP = ( + (1.00, "una lliura amb zero penics"), + (1.01, "una lliura amb un penic"), + (2.00, "dues lliures amb zero penics"), + (8.00, "vuit lliures amb zero penics"), + (12.00, "dotze lliures amb zero penics"), + (21.00, "vint-i-una lliures amb zero penics"), + (81.25, "vuitanta-una lliures amb vint-i-cinc penics"), + (350.90, "tres-centes cinquanta lliures amb noranta penics"), + (100.00, "cent lliures amb zero penics"), +) + + +class TestNum2WordsCA(TestCase): + def _test_cases(self, cases, lang="ca", to="cardinal", **kwargs): + for case in cases: + self.assertEqual(num2words(case[0], lang=lang, + to=to, **kwargs), case[1]) + + def test_cardinal(self): + self._test_cases(TEST_CASES_CARDINAL) + + def test_ordinal(self): + self._test_cases(TEST_CASES_ORDINAL, to="ordinal") + + def test_ordinal_num(self): + self._test_cases(TEST_CASES_ORDINAL_NUM, to="ordinal_num") + + def test_currency(self): + self._test_cases(TEST_CASES_TO_CURRENCY, to="currency", currency="EUR") + + def test_currency_esp(self): + self._test_cases(TEST_CASES_TO_CURRENCY_ESP, + to="currency", currency="ESP") + + def test_currency_usd(self): + self._test_cases(TEST_CASES_TO_CURRENCY_USD, + to="currency", currency="USD") + + def test_currency_gbp(self): + self._test_cases(TEST_CASES_TO_CURRENCY_GBP, + to="currency", currency="GBP") diff --git a/tests/test_ja.py b/tests/test_ja.py index 42da1445..18c3482f 100644 --- a/tests/test_ja.py +++ b/tests/test_ja.py @@ -20,6 +20,7 @@ from unittest import TestCase from num2words import num2words +from num2words.lang_JA import rendaku_merge_pairs def n2j(*args, **kwargs): @@ -196,3 +197,20 @@ def test_year(self): "きげんぜんきゅうじゅうくねん") self.assertEqual(n2j(1375, to="year"), "天授元年") self.assertEqual(n2j(1375, to="year", prefer=["えいわ"]), "永和元年") + + def test_rendaku_merge_pairs(self): + self.assertEqual(rendaku_merge_pairs(("はち", 8), ("ちょう", 10**12)), + ("はっちょう", 8 * 10**12)) + self.assertEqual(rendaku_merge_pairs(("じゅう", 10), ("ちょう", 10**12)), + ("じゅっちょう", 10 * 10**12)) + + self.assertEqual(rendaku_merge_pairs(("いち", 1), ("けい", 10**16)), + ("いっけい", 1 * 10**16)) + self.assertEqual(rendaku_merge_pairs(("ろく", 6), ("けい", 10**16)), + ("ろっけい", 6 * 10**16)) + self.assertEqual(rendaku_merge_pairs(("はち", 8), ("けい", 10**16)), + ("はっけい", 8 * 10**16)) + self.assertEqual(rendaku_merge_pairs(("じゅう", 10), ("けい", 10**16)), + ("じゅっけい", 10 * 10**16)) + self.assertEqual(rendaku_merge_pairs(("ひゃく", 100), ("けい", 10**16)), + ("ひゃっけい", 100 * 10**16)) diff --git a/tests/test_tet.py b/tests/test_tet.py new file mode 100644 index 00000000..7f005fd5 --- /dev/null +++ b/tests/test_tet.py @@ -0,0 +1,541 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. + +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA + +import decimal +from decimal import Decimal +from unittest import TestCase + +from num2words import num2words +from num2words.lang_TET import Num2Word_TET + + +class Num2WordsTETTest(TestCase): + def setUp(self): + super().setUp() + self.n2w = Num2Word_TET() + + def test_cardinal_integer(self): + self.assertEqual(num2words(1, lang='tet'), 'ida') + self.assertEqual(num2words(2, lang='tet'), 'rua') + self.assertEqual(num2words(3, lang='tet'), 'tolu') + self.assertEqual(num2words(4, lang='tet'), 'haat') + self.assertEqual(num2words(5, lang='tet'), 'lima') + self.assertEqual(num2words(6, lang='tet'), 'neen') + self.assertEqual(num2words(7, lang='tet'), 'hitu') + self.assertEqual(num2words(8, lang='tet'), 'ualu') + self.assertEqual(num2words(9, lang='tet'), 'sia') + self.assertEqual(num2words(10, lang='tet'), 'sanulu') + self.assertEqual(num2words(11, lang='tet'), 'sanulu resin ida') + self.assertEqual(num2words(12, lang='tet'), 'sanulu resin rua') + self.assertEqual(num2words(13, lang='tet'), 'sanulu resin tolu') + self.assertEqual(num2words(14, lang='tet'), 'sanulu resin haat') + self.assertEqual(num2words(15, lang='tet'), 'sanulu resin lima') + self.assertEqual(num2words(16, lang='tet'), 'sanulu resin neen') + self.assertEqual(num2words(17, lang='tet'), 'sanulu resin hitu') + self.assertEqual(num2words(18, lang='tet'), 'sanulu resin ualu') + self.assertEqual(num2words(19, lang='tet'), 'sanulu resin sia') + self.assertEqual(num2words(20, lang='tet'), 'ruanulu') + + self.assertEqual(num2words(21, lang='tet'), 'ruanulu resin ida') + self.assertEqual(num2words(22, lang='tet'), 'ruanulu resin rua') + self.assertEqual(num2words(35, lang='tet'), 'tolunulu resin lima') + self.assertEqual(num2words(99, lang='tet'), 'sianulu resin sia') + + self.assertEqual(num2words(100, lang='tet'), 'atus ida') + self.assertEqual(num2words(101, lang='tet'), 'atus ida ida') + self.assertEqual(num2words(107, lang='tet'), 'atus ida hitu') + self.assertEqual(num2words(110, lang='tet'), 'atus ida sanulu') + self.assertEqual( + num2words(114, lang='tet'), + 'atus ida sanulu resin haat' + ) + self.assertEqual( + num2words(128, lang='tet'), + 'atus ida ruanulu resin ualu' + ) + self.assertEqual( + num2words(151, lang='tet'), + 'atus ida limanulu resin ida' + ) + self.assertEqual( + num2words(713, lang='tet'), + 'atus hitu sanulu resin tolu' + ) + self.assertEqual( + num2words(999, lang='tet'), + 'atus sia sianulu resin sia' + ) + + self.assertEqual(num2words(1000, lang='tet'), 'rihun ida') + self.assertEqual(num2words(1001, lang='tet'), 'rihun ida ida') + self.assertEqual( + num2words(1011, lang='tet'), + 'rihun ida sanulu resin ida' + ) + self.assertEqual( + num2words(1111, lang='tet'), + 'rihun ida atus ida sanulu resin ida' + ) + self.assertEqual( + num2words(2357, lang='tet'), + 'rihun rua atus tolu limanulu resin hitu' + ) + self.assertEqual( + num2words(2200, lang='tet'), + 'rihun rua atus rua' + ) + self.assertEqual( + num2words(2230, lang='tet'), + 'rihun rua atus rua tolunulu' + ) + self.assertEqual( + num2words(73400, lang='tet'), + 'rihun hitunulu resin tolu atus haat' + ) + self.assertEqual( + num2words(73421, lang='tet'), + 'rihun hitunulu resin tolu atus haat ruanulu resin ida' + ) + self.assertEqual(num2words(100000, lang='tet'), 'rihun atus ida') + self.assertEqual( + num2words(250050, lang='tet'), + 'rihun atus rua limanulu limanulu' + ) + self.assertEqual( + num2words(6000000, lang='tet'), 'miliaun neen' + ) + self.assertEqual( + num2words(100000000, lang='tet'), 'miliaun atus ida' + ) + self.assertEqual( + num2words(19000000000, lang='tet'), + 'miliaun rihun sanulu resin sia' + ) + self.assertEqual( + num2words(145000000002, lang='tet'), + 'miliaun rihun atus ida haatnulu resin lima resin rua' + ) + self.assertEqual( + num2words(4635102, lang='tet'), + 'miliaun haat rihun atus neen tolunulu resin lima atus ida rua' + ) + self.assertEqual( + num2words(145254635102, lang='tet'), + "miliaun rihun atus ida haatnulu resin lima atus rua limanulu \ +resin haat rihun atus neen tolunulu resin lima atus ida rua" + ) + self.assertEqual( + num2words(1000000000000, lang='tet'), + 'biliaun ida' + ) + self.assertEqual( + num2words(2000000000000, lang='tet'), + 'biliaun rua' + ) + self.assertEqual( + num2words(1000000000000000, lang='tet'), + 'biliaun rihun ida' + ) + self.assertEqual( + num2words(2000000000000000, lang='tet'), + 'biliaun rihun rua' + ) + self.assertEqual( + num2words(1000000000000000000, lang='tet'), + 'triliaun ida' + ) + self.assertEqual( + num2words(2000000000000000000, lang='tet'), + 'triliaun rua' + ) + + def test_cardinal_integer_negative(self): + self.assertEqual(num2words(-1, lang='tet'), 'menus ida') + self.assertEqual( + num2words(-256, lang='tet'), 'menus atus rua limanulu resin neen' + ) + self.assertEqual(num2words(-1000, lang='tet'), 'menus rihun ida') + self.assertEqual(num2words(-1000000, lang='tet'), 'menus miliaun ida') + self.assertEqual( + num2words(-1234567, lang='tet'), + 'menus miliaun ida rihun atus rua tolunulu resin \ +haat atus lima neenulu resin hitu' + ) + + def test_cardinal_float(self): + self.assertEqual(num2words(Decimal('1.00'), lang='tet'), 'ida') + self.assertEqual(num2words( + Decimal('1.01'), lang='tet'), 'ida vírgula mamuk ida') + self.assertEqual(num2words( + Decimal('1.035'), lang='tet'), 'ida vírgula mamuk tolu lima' + ) + self.assertEqual(num2words( + Decimal('1.35'), lang='tet'), 'ida vírgula tolu lima' + ) + self.assertEqual( + num2words(Decimal('3.14159'), lang='tet'), + 'tolu vírgula ida haat ida lima sia' + ) + self.assertEqual( + num2words(Decimal('101.22'), lang='tet'), + 'atus ida ida vírgula rua rua' + ) + self.assertEqual( + num2words(Decimal('2345.75'), lang='tet'), + 'rihun rua atus tolu haatnulu resin lima vírgula hitu lima' + ) + + def test_cardinal_float_negative(self): + self.assertEqual( + num2words(Decimal('-2.34'), lang='tet'), + 'menus rua vírgula tolu haat' + ) + self.assertEqual( + num2words(Decimal('-9.99'), lang='tet'), + 'menus sia vírgula sia sia' + ) + self.assertEqual( + num2words(Decimal('-7.01'), lang='tet'), + 'menus hitu vírgula mamuk ida' + ) + self.assertEqual( + num2words(Decimal('-222.22'), lang='tet'), + 'menus atus rua ruanulu resin rua vírgula rua rua' + ) + + def test_ordinal(self): + with self.assertRaises(decimal.InvalidOperation): + num2words("hello", lang='tet', ordinal=True) + with self.assertRaises(TypeError): + num2words(5.1, lang='tet', ordinal=True) + self.assertEqual(num2words(1, lang='tet', ordinal=True), 'dahuluk') + self.assertEqual(num2words(2, lang='tet', ordinal=True), 'daruak') + self.assertEqual(num2words(3, lang='tet', ordinal=True), 'datoluk') + self.assertEqual(num2words(4, lang='tet', ordinal=True), 'dahaat') + self.assertEqual(num2words(5, lang='tet', ordinal=True), 'dalimak') + self.assertEqual(num2words(6, lang='tet', ordinal=True), 'daneen') + self.assertEqual(num2words(7, lang='tet', ordinal=True), 'dahituk') + self.assertEqual(num2words(8, lang='tet', ordinal=True), 'daualuk') + self.assertEqual(num2words(9, lang='tet', ordinal=True), 'dasiak') + self.assertEqual(num2words(10, lang='tet', ordinal=True), 'dasanuluk') + self.assertEqual( + num2words(11, lang='tet', ordinal=True), 'dasanulu resin idak' + ) + self.assertEqual( + num2words(12, lang='tet', ordinal=True), 'dasanulu resin ruak' + ) + self.assertEqual( + num2words(13, lang='tet', ordinal=True), 'dasanulu resin toluk' + ) + self.assertEqual( + num2words(14, lang='tet', ordinal=True), 'dasanulu resin haat' + ) + self.assertEqual( + num2words(15, lang='tet', ordinal=True), 'dasanulu resin limak' + ) + self.assertEqual( + num2words(16, lang='tet', ordinal=True), 'dasanulu resin neen' + ) + self.assertEqual( + num2words(17, lang='tet', ordinal=True), 'dasanulu resin hituk' + ) + self.assertEqual( + num2words(18, lang='tet', ordinal=True), 'dasanulu resin ualuk' + ) + self.assertEqual( + num2words(19, lang='tet', ordinal=True), 'dasanulu resin siak' + ) + self.assertEqual( + num2words(20, lang='tet', ordinal=True), 'daruanuluk' + ) + + self.assertEqual( + num2words(21, lang='tet', ordinal=True), 'daruanulu resin idak' + ) + self.assertEqual( + num2words(22, lang='tet', ordinal=True), 'daruanulu resin ruak' + ) + self.assertEqual( + num2words(35, lang='tet', ordinal=True), 'datolunulu resin limak' + ) + self.assertEqual( + num2words(99, lang='tet', ordinal=True), 'dasianulu resin siak' + ) + + self.assertEqual( + num2words(100, lang='tet', ordinal=True), 'dahatus idak' + ) + self.assertEqual( + num2words(101, lang='tet', ordinal=True), 'dahatus ida idak' + ) + self.assertEqual( + num2words(106, lang='tet', ordinal=True), 'dahatus ida neen' + ) + self.assertEqual( + num2words(128, lang='tet', ordinal=True), + 'dahatus ida ruanulu resin ualuk' + ) + self.assertEqual( + num2words(600, lang='tet', ordinal=True), + 'dahatus neen' + ) + self.assertEqual( + num2words(713, lang='tet', ordinal=True), + 'dahatus hitu sanulu resin toluk' + ) + + self.assertEqual( + num2words(1000, lang='tet', ordinal=True), 'darihun idak' + ) + self.assertEqual( + num2words(1001, lang='tet', ordinal=True), 'darihun ida idak' + ) + self.assertEqual( + num2words(1111, lang='tet', ordinal=True), + 'darihun ida atus ida sanulu resin idak' + ) + self.assertEqual( + num2words(2114, lang='tet', ordinal=True), + 'darihun rua atus ida sanulu resin haat' + ) + self.assertEqual( + num2words(73421, lang='tet', ordinal=True), + 'darihun hitunulu resin tolu atus haat ruanulu resin idak' + ) + + self.assertEqual( + num2words(100000, lang='tet', ordinal=True), + 'darihun atus idak' + ) + self.assertEqual( + num2words(250050, lang='tet', ordinal=True), + 'darihun atus rua limanulu limanuluk' + ) + self.assertEqual( + num2words(6000000, lang='tet', ordinal=True), 'damiliaun neen' + ) + self.assertEqual( + num2words(19000000000, lang='tet', ordinal=True), + 'damiliaun rihun sanulu resin siak' + ) + self.assertEqual( + num2words(145000000002, lang='tet', ordinal=True), + 'damiliaun rihun atus ida haatnulu resin lima resin ruak' + ) + + def test_currency_integer(self): + self.assertEqual(self.n2w.to_currency(1.00), 'dolar ida') + self.assertEqual(self.n2w.to_currency(2.00), 'dolar rua') + self.assertEqual(self.n2w.to_currency(3.00), 'dolar tolu') + self.assertEqual(self.n2w.to_currency(4.00), 'dolar haat') + self.assertEqual(self.n2w.to_currency(5.00), 'dolar lima') + self.assertEqual(self.n2w.to_currency(6.00), 'dolar neen') + self.assertEqual(self.n2w.to_currency(7.00), 'dolar hitu') + self.assertEqual(self.n2w.to_currency(8.00), 'dolar ualu') + self.assertEqual(self.n2w.to_currency(9.00), 'dolar sia') + self.assertEqual(self.n2w.to_currency(10.00), 'dolar sanulu') + self.assertEqual(self.n2w.to_currency(11.00), 'dolar sanulu resin ida') + self.assertEqual(self.n2w.to_currency(12.00), 'dolar sanulu resin rua') + self.assertEqual( + self.n2w.to_currency(13.00), + 'dolar sanulu resin tolu' + ) + self.assertEqual( + self.n2w.to_currency(14.00), + 'dolar sanulu resin haat' + ) + self.assertEqual( + self.n2w.to_currency(15.00), + 'dolar sanulu resin lima' + ) + self.assertEqual( + self.n2w.to_currency(16.00), + 'dolar sanulu resin neen' + ) + self.assertEqual( + self.n2w.to_currency(17.00), + 'dolar sanulu resin hitu' + ) + self.assertEqual( + self.n2w.to_currency(18.00), + 'dolar sanulu resin ualu' + ) + self.assertEqual( + self.n2w.to_currency(19.00), + 'dolar sanulu resin sia' + ) + self.assertEqual(self.n2w.to_currency(20.00), 'dolar ruanulu') + + self.assertEqual( + self.n2w.to_currency(21.00), + 'dolar ruanulu resin ida' + ) + self.assertEqual( + self.n2w.to_currency(22.00), + 'dolar ruanulu resin rua' + ) + self.assertEqual( + self.n2w.to_currency(35.00), + 'dolar tolunulu resin lima' + ) + self.assertEqual( + self.n2w.to_currency(99.00), + 'dolar sianulu resin sia' + ) + + self.assertEqual(self.n2w.to_currency(100.00), 'dolar atus ida') + self.assertEqual(self.n2w.to_currency(101.00), 'dolar atus ida ida') + self.assertEqual( + self.n2w.to_currency(128.00), 'dolar atus ida ruanulu resin ualu' + ) + self.assertEqual( + self.n2w.to_currency(713.00), 'dolar atus hitu sanulu resin tolu') + + self.assertEqual(self.n2w.to_currency(1000.00), 'dolar rihun ida') + self.assertEqual(self.n2w.to_currency(1001.00), 'dolar rihun ida ida') + self.assertEqual( + self.n2w.to_currency(1111.00), + 'dolar rihun ida atus ida sanulu resin ida' + ) + self.assertEqual( + self.n2w.to_currency(2114.00), + 'dolar rihun rua atus ida sanulu resin haat' + ) + self.assertEqual( + self.n2w.to_currency(73421.00), + 'dolar rihun hitunulu resin tolu atus haat ruanulu resin ida' + ) + + self.assertEqual( + self.n2w.to_currency(100000.00), + 'dolar rihun atus ida' + ) + self.assertEqual( + self.n2w.to_currency(250050.00), + 'dolar rihun atus rua limanulu limanulu' + ) + self.assertEqual( + self.n2w.to_currency(6000000.00), + 'dolar miliaun neen' + ) + self.assertEqual( + self.n2w.to_currency(19000000000.00), + 'dolar miliaun rihun sanulu resin sia' + ) + self.assertEqual( + self.n2w.to_currency(145000000002.00), + 'dolar miliaun rihun atus ida haatnulu resin lima resin rua' + ) + self.assertEqual(self.n2w.to_currency(1.00, currency='USD'), + 'dolar ida') + self.assertEqual(self.n2w.to_currency(1.50, currency='USD'), + 'dolar ida sentavu limanulu') + with self.assertRaises(NotImplementedError): + self.n2w.to_currency(1.00, currency='CHF') + + def test_currency_integer_negative(self): + self.assertEqual(self.n2w.to_currency(-1.00), 'menus dolar ida') + self.assertEqual( + self.n2w.to_currency(-256.00), + 'menus dolar atus rua limanulu resin neen' + ) + self.assertEqual( + self.n2w.to_currency(-1000.00), + 'menus dolar rihun ida' + ) + self.assertEqual( + self.n2w.to_currency(-1000000.00), 'menus dolar miliaun ida' + ) + self.assertEqual( + self.n2w.to_currency(-1234567.00), + 'menus dolar miliaun ida rihun atus rua tolunulu \ +resin haat atus lima neenulu resin hitu' + ) + + def test_currency_float(self): + self.assertEqual(self.n2w.to_currency(Decimal('1.00')), 'dolar ida') + self.assertEqual( + self.n2w.to_currency(Decimal('1.01')), 'dolar ida sentavu ida' + ) + self.assertEqual( + self.n2w.to_currency(Decimal('1.03')), 'dolar ida sentavu tolu' + ) + self.assertEqual( + self.n2w.to_currency(Decimal('1.35')), + 'dolar ida sentavu tolunulu resin lima' + ) + self.assertEqual( + self.n2w.to_currency(Decimal('3.14')), + 'dolar tolu sentavu sanulu resin haat' + ) + self.assertEqual( + self.n2w.to_currency(Decimal('101.22')), + 'dolar atus ida ida sentavu ruanulu resin rua' + ) + self.assertEqual( + self.n2w.to_currency(Decimal('2345.75')), + 'dolar rihun rua atus tolu haatnulu resin \ +lima sentavu hitunulu resin lima' + ) + + def test_currency_float_negative(self): + self.assertEqual( + self.n2w.to_currency(Decimal('-2.34')), + 'menus dolar rua sentavu tolunulu resin haat' + ) + self.assertEqual( + self.n2w.to_currency(Decimal('-9.99')), + 'menus dolar sia sentavu sianulu resin sia' + ) + self.assertEqual( + self.n2w.to_currency(Decimal('-7.01')), + 'menus dolar hitu sentavu ida' + ) + self.assertEqual( + self.n2w.to_currency(Decimal('-222.22')), + 'menus dolar atus rua ruanulu resin rua sentavu ruanulu resin rua' + ) + + def test_year(self): + self.assertEqual(self.n2w.to_year(1001), 'rihun ida ida') + self.assertEqual( + self.n2w.to_year(1789), 'rihun ida atus hitu ualunulu resin sia' + ) + self.assertEqual( + self.n2w.to_year(1942), 'rihun ida atus sia haatnulu resin rua' + ) + self.assertEqual( + self.n2w.to_year(1984), 'rihun ida atus sia ualunulu resin haat' + ) + self.assertEqual(self.n2w.to_year(2000), 'rihun rua') + self.assertEqual(self.n2w.to_year(2001), 'rihun rua ida') + self.assertEqual(self.n2w.to_year(2016), 'rihun rua sanulu resin neen') + + def test_year_negative(self): + self.assertEqual(self.n2w.to_year(-30), 'tolunulu antes Kristu') + self.assertEqual( + self.n2w.to_year(-744), + 'atus hitu haatnulu resin haat antes Kristu' + ) + self.assertEqual( + self.n2w.to_year(-10000), + 'rihun sanulu antes Kristu' + ) + + def test_to_ordinal_num(self): + self.assertEqual(self.n2w.to_ordinal_num(1), '1º') + self.assertEqual(self.n2w.to_ordinal_num(100), '100º')