From 80cd01b4154eb9daeefdc79c2fef48b3ba0e6ed4 Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Mon, 1 May 2023 11:31:34 -0400 Subject: [PATCH 1/2] [test] Regression-test large number words in English --- tests/test_en.py | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/tests/test_en.py b/tests/test_en.py index e763841c..ad3fba35 100644 --- a/tests/test_en.py +++ b/tests/test_en.py @@ -184,3 +184,106 @@ def test_to_year(self): 'sixty-six m.y.a.') self.assertEqual(num2words(-66000000, lang='en', to='year'), 'sixty-six million BC') + + def test_large_names(self): + self.assertEqual(num2words(10 * 10**3, lang='en'), 'ten thousand') + self.assertEqual(num2words(10 * 10**6, lang='en'), 'ten million') + self.assertEqual(num2words(10 * 10**9, lang='en'), 'ten billion') + self.assertEqual(num2words(10 * 10**12, lang='en'), 'ten trillion') + self.assertEqual(num2words(10 * 10**15, lang='en'), 'ten quadrillion') + self.assertEqual(num2words(10 * 10**18, lang='en'), 'ten quintillion') + self.assertEqual(num2words(10 * 10**21, lang='en'), 'ten sextillion') + self.assertEqual(num2words(10 * 10**24, lang='en'), 'ten septillion') + self.assertEqual(num2words(10 * 10**27, lang='en'), 'ten octillion') + self.assertEqual(num2words(10 * 10**30, lang='en'), 'ten nonillion') + self.assertEqual(num2words(10 * 10**33, lang='en'), 'ten decillion') + self.assertEqual(num2words(10 * 10**36, lang='en'), 'ten undecillion') + self.assertEqual(num2words(10 * 10**39, lang='en'), 'ten duodecillion') + self.assertEqual(num2words(10 * 10**42, lang='en'), 'ten tredecillion') + self.assertEqual(num2words(10 * 10**45, lang='en'), 'ten quattuordecillion') + self.assertEqual(num2words(10 * 10**48, lang='en'), 'ten quindecillion') + self.assertEqual(num2words(10 * 10**51, lang='en'), 'ten sexdecillion') + self.assertEqual(num2words(10 * 10**54, lang='en'), 'ten septdecillion') + self.assertEqual(num2words(10 * 10**57, lang='en'), 'ten octodecillion') + self.assertEqual(num2words(10 * 10**60, lang='en'), 'ten novemdecillion') + self.assertEqual(num2words(10 * 10**63, lang='en'), 'ten vigintillion') + self.assertEqual(num2words(10 * 10**66, lang='en'), 'ten unvigintillion') + self.assertEqual(num2words(10 * 10**69, lang='en'), 'ten duovigintillion') + self.assertEqual(num2words(10 * 10**72, lang='en'), 'ten trevigintillion') + self.assertEqual(num2words(10 * 10**75, lang='en'), 'ten quattuorvigintillion') + self.assertEqual(num2words(10 * 10**78, lang='en'), 'ten quinvigintillion') + self.assertEqual(num2words(10 * 10**81, lang='en'), 'ten sexvigintillion') + self.assertEqual(num2words(10 * 10**84, lang='en'), 'ten septvigintillion') + self.assertEqual(num2words(10 * 10**87, lang='en'), 'ten octovigintillion') + self.assertEqual(num2words(10 * 10**90, lang='en'), 'ten novemvigintillion') + self.assertEqual(num2words(10 * 10**93, lang='en'), 'ten trigintillion') + self.assertEqual(num2words(10 * 10**96, lang='en'), 'ten untrigintillion') + self.assertEqual(num2words(10 * 10**99, lang='en'), 'ten duotrigintillion') + self.assertEqual(num2words(10 * 10**102, lang='en'), 'ten tretrigintillion') + self.assertEqual(num2words(10 * 10**105, lang='en'), 'ten quattuortrigintillion') + self.assertEqual(num2words(10 * 10**108, lang='en'), 'ten quintrigintillion') + self.assertEqual(num2words(10 * 10**111, lang='en'), 'ten sextrigintillion') + self.assertEqual(num2words(10 * 10**114, lang='en'), 'ten septtrigintillion') + self.assertEqual(num2words(10 * 10**117, lang='en'), 'ten octotrigintillion') + self.assertEqual(num2words(10 * 10**120, lang='en'), 'ten novemtrigintillion') + self.assertEqual(num2words(10 * 10**123, lang='en'), 'ten quadragintillion') + self.assertEqual(num2words(10 * 10**126, lang='en'), 'ten unquadragintillion') + self.assertEqual(num2words(10 * 10**129, lang='en'), 'ten duoquadragintillion') + self.assertEqual(num2words(10 * 10**132, lang='en'), 'ten trequadragintillion') + self.assertEqual(num2words(10 * 10**135, lang='en'), 'ten quattuorquadragintillion') + self.assertEqual(num2words(10 * 10**138, lang='en'), 'ten quinquadragintillion') + self.assertEqual(num2words(10 * 10**141, lang='en'), 'ten sexquadragintillion') + self.assertEqual(num2words(10 * 10**144, lang='en'), 'ten septquadragintillion') + self.assertEqual(num2words(10 * 10**147, lang='en'), 'ten octoquadragintillion') + self.assertEqual(num2words(10 * 10**150, lang='en'), 'ten novemquadragintillion') + self.assertEqual(num2words(10 * 10**153, lang='en'), 'ten quinquagintillion') + self.assertEqual(num2words(10 * 10**156, lang='en'), 'ten unquinquagintillion') + self.assertEqual(num2words(10 * 10**159, lang='en'), 'ten duoquinquagintillion') + self.assertEqual(num2words(10 * 10**162, lang='en'), 'ten trequinquagintillion') + self.assertEqual(num2words(10 * 10**165, lang='en'), 'ten quattuorquinquagintillion') + self.assertEqual(num2words(10 * 10**168, lang='en'), 'ten quinquinquagintillion') + self.assertEqual(num2words(10 * 10**171, lang='en'), 'ten sexquinquagintillion') + self.assertEqual(num2words(10 * 10**174, lang='en'), 'ten septquinquagintillion') + self.assertEqual(num2words(10 * 10**177, lang='en'), 'ten octoquinquagintillion') + self.assertEqual(num2words(10 * 10**180, lang='en'), 'ten novemquinquagintillion') + self.assertEqual(num2words(10 * 10**183, lang='en'), 'ten sexagintillion') + self.assertEqual(num2words(10 * 10**186, lang='en'), 'ten unsexagintillion') + self.assertEqual(num2words(10 * 10**189, lang='en'), 'ten duosexagintillion') + self.assertEqual(num2words(10 * 10**192, lang='en'), 'ten tresexagintillion') + self.assertEqual(num2words(10 * 10**195, lang='en'), 'ten quattuorsexagintillion') + self.assertEqual(num2words(10 * 10**198, lang='en'), 'ten quinsexagintillion') + self.assertEqual(num2words(10 * 10**201, lang='en'), 'ten sexsexagintillion') + self.assertEqual(num2words(10 * 10**204, lang='en'), 'ten septsexagintillion') + self.assertEqual(num2words(10 * 10**207, lang='en'), 'ten octosexagintillion') + self.assertEqual(num2words(10 * 10**210, lang='en'), 'ten novemsexagintillion') + self.assertEqual(num2words(10 * 10**213, lang='en'), 'ten septuagintillion') + self.assertEqual(num2words(10 * 10**216, lang='en'), 'ten unseptuagintillion') + self.assertEqual(num2words(10 * 10**219, lang='en'), 'ten duoseptuagintillion') + self.assertEqual(num2words(10 * 10**222, lang='en'), 'ten treseptuagintillion') + self.assertEqual(num2words(10 * 10**225, lang='en'), 'ten quattuorseptuagintillion') + self.assertEqual(num2words(10 * 10**228, lang='en'), 'ten quinseptuagintillion') + self.assertEqual(num2words(10 * 10**231, lang='en'), 'ten sexseptuagintillion') + self.assertEqual(num2words(10 * 10**234, lang='en'), 'ten septseptuagintillion') + self.assertEqual(num2words(10 * 10**237, lang='en'), 'ten octoseptuagintillion') + self.assertEqual(num2words(10 * 10**240, lang='en'), 'ten novemseptuagintillion') + self.assertEqual(num2words(10 * 10**243, lang='en'), 'ten octogintillion') + self.assertEqual(num2words(10 * 10**246, lang='en'), 'ten unoctogintillion') + self.assertEqual(num2words(10 * 10**249, lang='en'), 'ten duooctogintillion') + self.assertEqual(num2words(10 * 10**252, lang='en'), 'ten treoctogintillion') + self.assertEqual(num2words(10 * 10**255, lang='en'), 'ten quattuoroctogintillion') + self.assertEqual(num2words(10 * 10**258, lang='en'), 'ten quinoctogintillion') + self.assertEqual(num2words(10 * 10**261, lang='en'), 'ten sexoctogintillion') + self.assertEqual(num2words(10 * 10**264, lang='en'), 'ten septoctogintillion') + self.assertEqual(num2words(10 * 10**267, lang='en'), 'ten octooctogintillion') + self.assertEqual(num2words(10 * 10**270, lang='en'), 'ten novemoctogintillion') + self.assertEqual(num2words(10 * 10**273, lang='en'), 'ten nonagintillion') + self.assertEqual(num2words(10 * 10**276, lang='en'), 'ten unnonagintillion') + self.assertEqual(num2words(10 * 10**279, lang='en'), 'ten duononagintillion') + self.assertEqual(num2words(10 * 10**282, lang='en'), 'ten trenonagintillion') + self.assertEqual(num2words(10 * 10**285, lang='en'), 'ten quattuornonagintillion') + self.assertEqual(num2words(10 * 10**288, lang='en'), 'ten quinnonagintillion') + self.assertEqual(num2words(10 * 10**291, lang='en'), 'ten sexnonagintillion') + self.assertEqual(num2words(10 * 10**294, lang='en'), 'ten septnonagintillion') + self.assertEqual(num2words(10 * 10**297, lang='en'), 'ten octononagintillion') + self.assertEqual(num2words(10 * 10**300, lang='en'), 'ten novemnonagintillion') + self.assertEqual(num2words(10 * 10**303, lang='en'), 'ten centillion') From c0467340841d31fea6011ac72507122c3cf93948 Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Mon, 1 May 2023 11:27:19 -0400 Subject: [PATCH 2/2] Adjust large number words in English These names reportedly match Mathematica's names. Fixes #514. --- num2words/lang_EU.py | 24 +++++++++++++++++++++++- tests/test_en.py | 44 ++++++++++++++++++++++---------------------- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/num2words/lang_EU.py b/num2words/lang_EU.py index f2336701..88ce4078 100644 --- a/num2words/lang_EU.py +++ b/num2words/lang_EU.py @@ -82,6 +82,28 @@ def set_high_numwords(self, high): def gen_high_numwords(self, units, tens, lows): out = [u + t for t in tens for u in units] out.reverse() + replacements = [ + ("novemn", "noven"), # "novemnonagintillion" becomes "novenonagintillion" + ("novemo", "novo"), # "novemoctogintillion" becomes "novoctogintillion" + ("octoo", "octo"), # "octooctillion" becomes "octoctillion" + ("quintd", "quind"), # "quintdecillion" becomes "quindecillion" + ("quintn", "quin"), # "quintnonagintillion" becomes "quinonagintillion" + ("quintq", "quinq"), # "quintquadragintillion" becomes "quinquadragintillion" + ("quints", "quins"), # "quintsexagintillion" becomes "quinsexagintillion" + ("quintt", "quint"), # "quinttrigintillion" becomes "quintrigintillion" + ("quintv", "quinv"), # "quintvigintillion" becomes "quinvigintillion" + ("septenn", "septen"), # "septennonagintillion" becomes "septenonagintillion" + ("septent", "sept"), # "septtregintillion" becomes "septtregintillion" + ("sexn", "sen"), # "sexnonagintillion" becomes "senonagintillion" + ("sexs", "ses"), # "sexsexagintillion" becomes "sesexagintillion" + ("tresd", "tred"), # "tresdecillion" becomes "tredecillion" + ("tresn", "tren"), # "tresnonagintillion" becomes "trenonagintillion" + ("tress", "tres"), # "tressexagintillion" becomes "tresexagintillion" + ("tresv", "trev"), # "tresvigintillion" becomes "trevigintillion" + ("unno", "uno"), # "unnonagintillion" becomes "unonagintillion" + ] + for k, v in replacements: + out = [o.replace(k, v) for o in out] return out + lows def pluralize(self, n, forms): @@ -90,7 +112,7 @@ def pluralize(self, n, forms): def setup(self): lows = ["non", "oct", "sept", "sext", "quint", "quadr", "tr", "b", "m"] - units = ["", "un", "duo", "tre", "quattuor", "quin", "sex", "sept", + units = ["", "un", "duo", "tres", "quattuor", "quint", "sex", "septen", "octo", "novem"] tens = ["dec", "vigint", "trigint", "quadragint", "quinquagint", "sexagint", "septuagint", "octogint", "nonagint"] diff --git a/tests/test_en.py b/tests/test_en.py index ad3fba35..3d089987 100644 --- a/tests/test_en.py +++ b/tests/test_en.py @@ -203,7 +203,7 @@ def test_large_names(self): self.assertEqual(num2words(10 * 10**45, lang='en'), 'ten quattuordecillion') self.assertEqual(num2words(10 * 10**48, lang='en'), 'ten quindecillion') self.assertEqual(num2words(10 * 10**51, lang='en'), 'ten sexdecillion') - self.assertEqual(num2words(10 * 10**54, lang='en'), 'ten septdecillion') + self.assertEqual(num2words(10 * 10**54, lang='en'), 'ten septendecillion') self.assertEqual(num2words(10 * 10**57, lang='en'), 'ten octodecillion') self.assertEqual(num2words(10 * 10**60, lang='en'), 'ten novemdecillion') self.assertEqual(num2words(10 * 10**63, lang='en'), 'ten vigintillion') @@ -213,37 +213,37 @@ def test_large_names(self): self.assertEqual(num2words(10 * 10**75, lang='en'), 'ten quattuorvigintillion') self.assertEqual(num2words(10 * 10**78, lang='en'), 'ten quinvigintillion') self.assertEqual(num2words(10 * 10**81, lang='en'), 'ten sexvigintillion') - self.assertEqual(num2words(10 * 10**84, lang='en'), 'ten septvigintillion') + self.assertEqual(num2words(10 * 10**84, lang='en'), 'ten septenvigintillion') self.assertEqual(num2words(10 * 10**87, lang='en'), 'ten octovigintillion') self.assertEqual(num2words(10 * 10**90, lang='en'), 'ten novemvigintillion') self.assertEqual(num2words(10 * 10**93, lang='en'), 'ten trigintillion') self.assertEqual(num2words(10 * 10**96, lang='en'), 'ten untrigintillion') self.assertEqual(num2words(10 * 10**99, lang='en'), 'ten duotrigintillion') - self.assertEqual(num2words(10 * 10**102, lang='en'), 'ten tretrigintillion') + self.assertEqual(num2words(10 * 10**102, lang='en'), 'ten trestrigintillion') self.assertEqual(num2words(10 * 10**105, lang='en'), 'ten quattuortrigintillion') self.assertEqual(num2words(10 * 10**108, lang='en'), 'ten quintrigintillion') self.assertEqual(num2words(10 * 10**111, lang='en'), 'ten sextrigintillion') - self.assertEqual(num2words(10 * 10**114, lang='en'), 'ten septtrigintillion') + self.assertEqual(num2words(10 * 10**114, lang='en'), 'ten septrigintillion') self.assertEqual(num2words(10 * 10**117, lang='en'), 'ten octotrigintillion') self.assertEqual(num2words(10 * 10**120, lang='en'), 'ten novemtrigintillion') self.assertEqual(num2words(10 * 10**123, lang='en'), 'ten quadragintillion') self.assertEqual(num2words(10 * 10**126, lang='en'), 'ten unquadragintillion') self.assertEqual(num2words(10 * 10**129, lang='en'), 'ten duoquadragintillion') - self.assertEqual(num2words(10 * 10**132, lang='en'), 'ten trequadragintillion') + self.assertEqual(num2words(10 * 10**132, lang='en'), 'ten tresquadragintillion') self.assertEqual(num2words(10 * 10**135, lang='en'), 'ten quattuorquadragintillion') self.assertEqual(num2words(10 * 10**138, lang='en'), 'ten quinquadragintillion') self.assertEqual(num2words(10 * 10**141, lang='en'), 'ten sexquadragintillion') - self.assertEqual(num2words(10 * 10**144, lang='en'), 'ten septquadragintillion') + self.assertEqual(num2words(10 * 10**144, lang='en'), 'ten septenquadragintillion') self.assertEqual(num2words(10 * 10**147, lang='en'), 'ten octoquadragintillion') self.assertEqual(num2words(10 * 10**150, lang='en'), 'ten novemquadragintillion') self.assertEqual(num2words(10 * 10**153, lang='en'), 'ten quinquagintillion') self.assertEqual(num2words(10 * 10**156, lang='en'), 'ten unquinquagintillion') self.assertEqual(num2words(10 * 10**159, lang='en'), 'ten duoquinquagintillion') - self.assertEqual(num2words(10 * 10**162, lang='en'), 'ten trequinquagintillion') + self.assertEqual(num2words(10 * 10**162, lang='en'), 'ten tresquinquagintillion') self.assertEqual(num2words(10 * 10**165, lang='en'), 'ten quattuorquinquagintillion') self.assertEqual(num2words(10 * 10**168, lang='en'), 'ten quinquinquagintillion') self.assertEqual(num2words(10 * 10**171, lang='en'), 'ten sexquinquagintillion') - self.assertEqual(num2words(10 * 10**174, lang='en'), 'ten septquinquagintillion') + self.assertEqual(num2words(10 * 10**174, lang='en'), 'ten septenquinquagintillion') self.assertEqual(num2words(10 * 10**177, lang='en'), 'ten octoquinquagintillion') self.assertEqual(num2words(10 * 10**180, lang='en'), 'ten novemquinquagintillion') self.assertEqual(num2words(10 * 10**183, lang='en'), 'ten sexagintillion') @@ -252,8 +252,8 @@ def test_large_names(self): self.assertEqual(num2words(10 * 10**192, lang='en'), 'ten tresexagintillion') self.assertEqual(num2words(10 * 10**195, lang='en'), 'ten quattuorsexagintillion') self.assertEqual(num2words(10 * 10**198, lang='en'), 'ten quinsexagintillion') - self.assertEqual(num2words(10 * 10**201, lang='en'), 'ten sexsexagintillion') - self.assertEqual(num2words(10 * 10**204, lang='en'), 'ten septsexagintillion') + self.assertEqual(num2words(10 * 10**201, lang='en'), 'ten sesexagintillion') + self.assertEqual(num2words(10 * 10**204, lang='en'), 'ten septensexagintillion') self.assertEqual(num2words(10 * 10**207, lang='en'), 'ten octosexagintillion') self.assertEqual(num2words(10 * 10**210, lang='en'), 'ten novemsexagintillion') self.assertEqual(num2words(10 * 10**213, lang='en'), 'ten septuagintillion') @@ -262,28 +262,28 @@ def test_large_names(self): self.assertEqual(num2words(10 * 10**222, lang='en'), 'ten treseptuagintillion') self.assertEqual(num2words(10 * 10**225, lang='en'), 'ten quattuorseptuagintillion') self.assertEqual(num2words(10 * 10**228, lang='en'), 'ten quinseptuagintillion') - self.assertEqual(num2words(10 * 10**231, lang='en'), 'ten sexseptuagintillion') - self.assertEqual(num2words(10 * 10**234, lang='en'), 'ten septseptuagintillion') + self.assertEqual(num2words(10 * 10**231, lang='en'), 'ten seseptuagintillion') + self.assertEqual(num2words(10 * 10**234, lang='en'), 'ten septenseptuagintillion') self.assertEqual(num2words(10 * 10**237, lang='en'), 'ten octoseptuagintillion') self.assertEqual(num2words(10 * 10**240, lang='en'), 'ten novemseptuagintillion') self.assertEqual(num2words(10 * 10**243, lang='en'), 'ten octogintillion') self.assertEqual(num2words(10 * 10**246, lang='en'), 'ten unoctogintillion') self.assertEqual(num2words(10 * 10**249, lang='en'), 'ten duooctogintillion') - self.assertEqual(num2words(10 * 10**252, lang='en'), 'ten treoctogintillion') + self.assertEqual(num2words(10 * 10**252, lang='en'), 'ten tresoctogintillion') self.assertEqual(num2words(10 * 10**255, lang='en'), 'ten quattuoroctogintillion') - self.assertEqual(num2words(10 * 10**258, lang='en'), 'ten quinoctogintillion') + self.assertEqual(num2words(10 * 10**258, lang='en'), 'ten quintoctogintillion') self.assertEqual(num2words(10 * 10**261, lang='en'), 'ten sexoctogintillion') - self.assertEqual(num2words(10 * 10**264, lang='en'), 'ten septoctogintillion') - self.assertEqual(num2words(10 * 10**267, lang='en'), 'ten octooctogintillion') - self.assertEqual(num2words(10 * 10**270, lang='en'), 'ten novemoctogintillion') + self.assertEqual(num2words(10 * 10**264, lang='en'), 'ten septenoctogintillion') + self.assertEqual(num2words(10 * 10**267, lang='en'), 'ten octoctogintillion') + self.assertEqual(num2words(10 * 10**270, lang='en'), 'ten novoctogintillion') self.assertEqual(num2words(10 * 10**273, lang='en'), 'ten nonagintillion') - self.assertEqual(num2words(10 * 10**276, lang='en'), 'ten unnonagintillion') + self.assertEqual(num2words(10 * 10**276, lang='en'), 'ten unonagintillion') self.assertEqual(num2words(10 * 10**279, lang='en'), 'ten duononagintillion') self.assertEqual(num2words(10 * 10**282, lang='en'), 'ten trenonagintillion') self.assertEqual(num2words(10 * 10**285, lang='en'), 'ten quattuornonagintillion') - self.assertEqual(num2words(10 * 10**288, lang='en'), 'ten quinnonagintillion') - self.assertEqual(num2words(10 * 10**291, lang='en'), 'ten sexnonagintillion') - self.assertEqual(num2words(10 * 10**294, lang='en'), 'ten septnonagintillion') + self.assertEqual(num2words(10 * 10**288, lang='en'), 'ten quinonagintillion') + self.assertEqual(num2words(10 * 10**291, lang='en'), 'ten senonagintillion') + self.assertEqual(num2words(10 * 10**294, lang='en'), 'ten septenonagintillion') self.assertEqual(num2words(10 * 10**297, lang='en'), 'ten octononagintillion') - self.assertEqual(num2words(10 * 10**300, lang='en'), 'ten novemnonagintillion') + self.assertEqual(num2words(10 * 10**300, lang='en'), 'ten novenonagintillion') self.assertEqual(num2words(10 * 10**303, lang='en'), 'ten centillion')