mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
committed by
GitHub
parent
1e954c909b
commit
9819498a14
@@ -90,31 +90,8 @@ class Num2Word_FR(Num2Word_EU):
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
def to_currency(self, val, longval=True, old=False):
|
def to_currency(self, val, longval=True, old=False):
|
||||||
hightxt = "Euro/s"
|
hightxt = "euro/s"
|
||||||
if old:
|
if old:
|
||||||
hightxt = "franc/s"
|
hightxt = "franc/s"
|
||||||
return self.to_splitnum(val, hightxt=hightxt, lowtxt="centime/s",
|
return self.to_splitnum(val, hightxt=hightxt, lowtxt="centime/s",
|
||||||
jointxt="et", longval=longval)
|
divisor=1, jointxt="et", longval=longval)
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_FR()
|
|
||||||
to_card = n2w.to_cardinal
|
|
||||||
to_ord = n2w.to_ordinal
|
|
||||||
to_ordnum = n2w.to_ordinal_num
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
for val in [1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155,
|
|
||||||
180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000,
|
|
||||||
8280, 8291, 150000, 500000, 1000000, 2000000, 2000001,
|
|
||||||
-21212121211221211111, -2.121212, -1.0000100]:
|
|
||||||
n2w.test(val)
|
|
||||||
|
|
||||||
n2w.test(
|
|
||||||
1325325436067876801768700107601001012212132143210473207540327057320957)
|
|
||||||
print(n2w.to_currency(112121))
|
|
||||||
print(n2w.to_year(1996))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|||||||
@@ -47,26 +47,3 @@ class Num2Word_FR_CH(Num2Word_FR):
|
|||||||
if nnum > cnum:
|
if nnum > cnum:
|
||||||
return ("%s %s" % (ctext, ntext), cnum * nnum)
|
return ("%s %s" % (ctext, ntext), cnum * nnum)
|
||||||
return ("%s %s" % (ctext, ntext), cnum + nnum)
|
return ("%s %s" % (ctext, ntext), cnum + nnum)
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_FR_CH()
|
|
||||||
to_card = n2w.to_cardinal
|
|
||||||
to_ord = n2w.to_ordinal
|
|
||||||
to_ordnum = n2w.to_ordinal_num
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
for val in [1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155,
|
|
||||||
180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000,
|
|
||||||
8280, 8291, 150000, 500000, 1000000, 2000000, 2000001,
|
|
||||||
-21212121211221211111, -2.121212, -1.0000100]:
|
|
||||||
n2w.test(val)
|
|
||||||
|
|
||||||
n2w.test(
|
|
||||||
1325325436067876801768700107601001012212132143210473207540327057320950)
|
|
||||||
print(n2w.to_currency(112121))
|
|
||||||
print(n2w.to_year(1996))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|||||||
@@ -21,31 +21,7 @@ from .lang_FR import Num2Word_FR
|
|||||||
|
|
||||||
class Num2Word_FR_DZ(Num2Word_FR):
|
class Num2Word_FR_DZ(Num2Word_FR):
|
||||||
def to_currency(self, val, longval=True, cents=True, jointxt="virgule"):
|
def to_currency(self, val, longval=True, cents=True, jointxt="virgule"):
|
||||||
return self.to_splitnum(val, hightxt="dinard/s", lowtxt="centime/s",
|
return self.to_splitnum(
|
||||||
jointxt=jointxt, longval=longval, cents=cents)
|
val, hightxt="dinard/s", lowtxt="centime/s", divisor=1,
|
||||||
|
jointxt=jointxt, longval=longval, cents=cents
|
||||||
|
)
|
||||||
n2w = Num2Word_FR_DZ()
|
|
||||||
to_card = n2w.to_cardinal
|
|
||||||
to_ord = n2w.to_ordinal
|
|
||||||
to_ordnum = n2w.to_ordinal_num
|
|
||||||
to_year = n2w.to_year
|
|
||||||
to_currency = n2w.to_currency
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
for val in [1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155,
|
|
||||||
180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000,
|
|
||||||
8280, 8291, 150000, 500000, 1000000, 2000000, 2000001,
|
|
||||||
-21212121211221211111, -2.121212, -1.0000100]:
|
|
||||||
n2w.test(val)
|
|
||||||
|
|
||||||
n2w.test(
|
|
||||||
1325325436067876801768700107601001012212132143210473207540327057320950)
|
|
||||||
for val in [1, 120, 1000, 1120, 1800, 1976, 2000, 2010, 2099, 2171]:
|
|
||||||
print(val, "is", n2w.to_currency(val))
|
|
||||||
print(val, "is", n2w.to_year(val))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|||||||
160
tests/test_fr.py
160
tests/test_fr.py
@@ -1,16 +1,16 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copetright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This libraret is free software; etou can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modifet it under the terms of the GNU Lesser General Public
|
||||||
# License as published by the Free Software Foundation; either
|
# License as published bet the Free Software Foundation; either
|
||||||
# version 2.1 of the License, or (at your option) any later version.
|
# version 2.1 of the License, or (at etour option) anet later version.
|
||||||
# This library is distributed in the hope that it will be useful,
|
# This libraret is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warrantet of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
# Lesser General Public License for more details.
|
# Lesser General Public License for more details.
|
||||||
# You should have received a copy of the GNU Lesser General Public
|
# You should have received a copet of the GNU Lesser General Public
|
||||||
# License along with this library; if not, write to the Free Software
|
# License along with this libraret; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301 USA
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
@@ -20,6 +20,116 @@ from unittest import TestCase
|
|||||||
|
|
||||||
from num2words import num2words
|
from num2words import num2words
|
||||||
|
|
||||||
|
TEST_CASES_CARDINAL = (
|
||||||
|
(1, 'un'),
|
||||||
|
(2, 'deux'),
|
||||||
|
(3, 'trois'),
|
||||||
|
(5.5, 'cinq virgule cinq'),
|
||||||
|
(11, 'onze'),
|
||||||
|
(12, 'douze'),
|
||||||
|
(16, 'seize'),
|
||||||
|
(17.42, 'dix-sept virgule quatre deux'),
|
||||||
|
(19, 'dix-neuf'),
|
||||||
|
(20, 'vingt'),
|
||||||
|
(21, 'vingt et un'),
|
||||||
|
(26, 'vingt-six'),
|
||||||
|
(27.312, 'vingt-sept virgule trois un deux'),
|
||||||
|
(28, 'vingt-huit'),
|
||||||
|
(30, 'trente'),
|
||||||
|
(31, 'trente et un'),
|
||||||
|
(40, 'quarante'),
|
||||||
|
(44, 'quarante-quatre'),
|
||||||
|
(50, 'cinquante'),
|
||||||
|
(53.486, 'cinquante-trois virgule quatre huit six'),
|
||||||
|
(55, 'cinquante-cinq'),
|
||||||
|
(60, 'soixante'),
|
||||||
|
(67, 'soixante-sept'),
|
||||||
|
(70, 'soixante-dix'),
|
||||||
|
(79, 'soixante-dix-neuf'),
|
||||||
|
(89, 'quatre-vingt-neuf'),
|
||||||
|
(95, 'quatre-vingt-quinze'),
|
||||||
|
(100, 'cent'),
|
||||||
|
(101, 'cent un'),
|
||||||
|
(199, 'cent quatre-vingt-dix-neuf'),
|
||||||
|
(203, 'deux cent trois'),
|
||||||
|
(287, 'deux cent quatre-vingt-sept'),
|
||||||
|
(300.42, 'trois cents virgule quatre deux'),
|
||||||
|
(356, 'trois cent cinquante-six'),
|
||||||
|
(400, 'quatre cents'),
|
||||||
|
(434, 'quatre cent trente-quatre'),
|
||||||
|
(578, 'cinq cent soixante-dix-huit'),
|
||||||
|
(689, 'six cent quatre-vingt-neuf'),
|
||||||
|
(729, 'sept cent vingt-neuf'),
|
||||||
|
(894, 'huit cent quatre-vingt-quatorze'),
|
||||||
|
(999, 'neuf cent quatre-vingt-dix-neuf'),
|
||||||
|
(1000, 'mille'),
|
||||||
|
(1001, 'mille un'),
|
||||||
|
(1097, 'mille quatre-vingt-dix-sept'),
|
||||||
|
(1104, 'mille cent quatre'),
|
||||||
|
(1243, 'mille deux cent quarante-trois'),
|
||||||
|
(2385, 'deux mille trois cent quatre-vingt-cinq'),
|
||||||
|
(3766, 'trois mille sept cent soixante-six'),
|
||||||
|
(4196, 'quatre mille cent quatre-vingt-seize'),
|
||||||
|
(4196.42, 'quatre mille cent quatre-vingt-seize virgule quatre deux'),
|
||||||
|
(5846, 'cinq mille huit cent quarante-six'),
|
||||||
|
(6459, 'six mille quatre cent cinquante-neuf'),
|
||||||
|
(7232, 'sept mille deux cent trente-deux'),
|
||||||
|
(8569, 'huit mille cinq cent soixante-neuf'),
|
||||||
|
(9539, 'neuf mille cinq cent trente-neuf'),
|
||||||
|
(1000000, 'un million'),
|
||||||
|
(1000001, 'un million un'),
|
||||||
|
(4000000, 'quatre millions'),
|
||||||
|
(10000000000000, 'dix billions'),
|
||||||
|
(100000000000000, 'cent billions'),
|
||||||
|
(1000000000000000000, 'un trillion'),
|
||||||
|
(1000000000000000000000, 'un trilliard'),
|
||||||
|
(10000000000000000000000000, 'dix quadrillions')
|
||||||
|
)
|
||||||
|
|
||||||
|
TEST_CASES_ORDINAL = (
|
||||||
|
(1, 'premier'),
|
||||||
|
(8, 'huitième'),
|
||||||
|
(12, 'douzième'),
|
||||||
|
(14, 'quatorzième'),
|
||||||
|
(28, 'vingt-huitième'),
|
||||||
|
(100, 'centième'),
|
||||||
|
(1000, 'millième'),
|
||||||
|
(1000000, 'un millionième'),
|
||||||
|
(1000000000000000, 'un billiardième'),
|
||||||
|
(1000000000000000000, 'un trillionième') # over 1e18 is not supported
|
||||||
|
)
|
||||||
|
|
||||||
|
TEST_CASES_ORDINAL_NUM = (
|
||||||
|
(1, '1er'),
|
||||||
|
(8, '8me'),
|
||||||
|
(12, '12me'),
|
||||||
|
(14, '14me'),
|
||||||
|
(28, '28me'),
|
||||||
|
(100, '100me'),
|
||||||
|
(1000, '1000me'),
|
||||||
|
(1000000, '1000000me')
|
||||||
|
)
|
||||||
|
|
||||||
|
TEST_CASES_TO_CURRENCY = (
|
||||||
|
(1, 'un euro'),
|
||||||
|
(2, 'deux euros'),
|
||||||
|
(8, 'huit euros'),
|
||||||
|
(12, 'douze euros'),
|
||||||
|
(21, 'vingt et un euros'),
|
||||||
|
(81.25, 'quatre-vingt-un euros et vingt-cinq centimes'),
|
||||||
|
(100, 'cent euros'),
|
||||||
|
)
|
||||||
|
|
||||||
|
TEST_CASES_TO_CURRENCY_OLD = (
|
||||||
|
(1, 'un franc'),
|
||||||
|
(2, 'deux francs'),
|
||||||
|
(8, 'huit francs'),
|
||||||
|
(12, 'douze francs'),
|
||||||
|
(21, 'vingt et un francs'),
|
||||||
|
(81.25, 'quatre-vingt-un francs et vingt-cinq centimes'),
|
||||||
|
(100, 'cent francs'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Num2WordsENTest(TestCase):
|
class Num2WordsENTest(TestCase):
|
||||||
def test_ordinal_special_joins(self):
|
def test_ordinal_special_joins(self):
|
||||||
@@ -36,3 +146,35 @@ class Num2WordsENTest(TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
num2words(49, ordinal=True, lang='fr'), "quarante-neuvième"
|
num2words(49, ordinal=True, lang='fr'), "quarante-neuvième"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_number(self):
|
||||||
|
for test in TEST_CASES_CARDINAL:
|
||||||
|
self.assertEqual(num2words(test[0], lang='fr'), test[1])
|
||||||
|
|
||||||
|
def test_ordinal(self):
|
||||||
|
for test in TEST_CASES_ORDINAL:
|
||||||
|
self.assertEqual(
|
||||||
|
num2words(test[0], lang='fr', ordinal=True),
|
||||||
|
test[1]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_ordinal_num(self):
|
||||||
|
for test in TEST_CASES_ORDINAL_NUM:
|
||||||
|
self.assertEqual(
|
||||||
|
num2words(test[0], lang='fr', to='ordinal_num'),
|
||||||
|
test[1]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_currency(self):
|
||||||
|
for test in TEST_CASES_TO_CURRENCY:
|
||||||
|
self.assertEqual(
|
||||||
|
num2words(test[0], lang='fr', to='currency'),
|
||||||
|
test[1]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_currency_old(self):
|
||||||
|
for test in TEST_CASES_TO_CURRENCY_OLD:
|
||||||
|
self.assertEqual(
|
||||||
|
num2words(test[0], lang='fr', to='currency', old=True),
|
||||||
|
test[1]
|
||||||
|
)
|
||||||
|
|||||||
@@ -20,6 +20,60 @@ from unittest import TestCase
|
|||||||
|
|
||||||
from num2words import num2words
|
from num2words import num2words
|
||||||
|
|
||||||
|
TEST_CASES_CARDINAL = (
|
||||||
|
(70, 'septante'),
|
||||||
|
(79, 'septante-neuf'),
|
||||||
|
(89, 'huitante-neuf'),
|
||||||
|
(95, 'nonante-cinq'),
|
||||||
|
(729, 'sept cents vingt-neuf'),
|
||||||
|
(894, 'huit cents nonante-quatre'),
|
||||||
|
(999, 'neuf cents nonante-neuf'),
|
||||||
|
(7232, 'sept mille deux cents trente-deux'),
|
||||||
|
(8569, 'huit mille cinq cents soixante-neuf'),
|
||||||
|
(9539, 'neuf mille cinq cents trente-neuf'),
|
||||||
|
(1000000, 'un millions'),
|
||||||
|
(1000001, 'un millions un'),
|
||||||
|
(4000000, 'quatre millions'),
|
||||||
|
(10000000000000, 'dix billions'),
|
||||||
|
(100000000000000, 'cent billions'),
|
||||||
|
(1000000000000000000, 'un trillions'),
|
||||||
|
(1000000000000000000000, 'un trilliards'),
|
||||||
|
(10000000000000000000000000, 'dix quadrillions')
|
||||||
|
)
|
||||||
|
|
||||||
|
TEST_CASES_ORDINAL = (
|
||||||
|
(1, 'premier'),
|
||||||
|
(8, 'huitième'),
|
||||||
|
(12, 'douzième'),
|
||||||
|
(14, 'quatorzième'),
|
||||||
|
(28, 'vingt-huitième'),
|
||||||
|
(100, 'centième'),
|
||||||
|
(1000, 'millième'),
|
||||||
|
(1000000, 'un millionsième'),
|
||||||
|
(1000000000000000, 'un billiardsième'),
|
||||||
|
(1000000000000000000, 'un trillionsième') # over 1e18 is not supported
|
||||||
|
)
|
||||||
|
|
||||||
|
TEST_CASES_TO_CURRENCY = (
|
||||||
|
(1, 'un euro'),
|
||||||
|
(2, 'deux euros'),
|
||||||
|
(8, 'huit euros'),
|
||||||
|
(12, 'douze euros'),
|
||||||
|
(21, 'vingt et un euros'),
|
||||||
|
(81.25, 'huitante et un euros et vingt-cinq centimes'),
|
||||||
|
(100, 'cent euros'),
|
||||||
|
)
|
||||||
|
|
||||||
|
TEST_CASES_TO_CURRENCY_OLD = (
|
||||||
|
(1, 'un franc'),
|
||||||
|
(2, 'deux francs'),
|
||||||
|
(8, 'huit francs'),
|
||||||
|
(12, 'douze francs'),
|
||||||
|
(21, 'vingt et un francs'),
|
||||||
|
(81.25, 'huitante et un francs et vingt-cinq centimes'),
|
||||||
|
(100, 'cent francs'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Num2WordsENTest(TestCase):
|
class Num2WordsENTest(TestCase):
|
||||||
def test_ordinal_special_joins(self):
|
def test_ordinal_special_joins(self):
|
||||||
@@ -44,3 +98,28 @@ class Num2WordsENTest(TestCase):
|
|||||||
num2words(91, ordinal=True, lang='fr_CH'), "nonante et unième"
|
num2words(91, ordinal=True, lang='fr_CH'), "nonante et unième"
|
||||||
)
|
)
|
||||||
self.assertEqual(num2words(53, lang='fr_CH'), "cinquante-trois")
|
self.assertEqual(num2words(53, lang='fr_CH'), "cinquante-trois")
|
||||||
|
|
||||||
|
def test_number(self):
|
||||||
|
for test in TEST_CASES_CARDINAL:
|
||||||
|
self.assertEqual(num2words(test[0], lang='fr_CH'), test[1])
|
||||||
|
|
||||||
|
def test_ordinal(self):
|
||||||
|
for test in TEST_CASES_ORDINAL:
|
||||||
|
self.assertEqual(
|
||||||
|
num2words(test[0], lang='fr_CH', ordinal=True),
|
||||||
|
test[1]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_currency(self):
|
||||||
|
for test in TEST_CASES_TO_CURRENCY:
|
||||||
|
self.assertEqual(
|
||||||
|
num2words(test[0], lang='fr_CH', to='currency'),
|
||||||
|
test[1]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_currency_old(self):
|
||||||
|
for test in TEST_CASES_TO_CURRENCY_OLD:
|
||||||
|
self.assertEqual(
|
||||||
|
num2words(test[0], lang='fr_CH', to='currency', old=True),
|
||||||
|
test[1]
|
||||||
|
)
|
||||||
|
|||||||
@@ -18,17 +18,47 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from num2words.lang_FR_DZ import to_currency
|
from num2words import num2words
|
||||||
|
|
||||||
|
from . import test_fr
|
||||||
|
|
||||||
|
TEST_CASES_TO_CURRENCY = (
|
||||||
|
(1, 'un dinard'),
|
||||||
|
(2, 'deux dinards'),
|
||||||
|
(8, 'huit dinards'),
|
||||||
|
(12, 'douze dinards'),
|
||||||
|
(21, 'vingt et un dinards'),
|
||||||
|
(81.25, 'quatre-vingt-un dinards virgule vingt-cinq centimes'),
|
||||||
|
(100, 'cent dinards'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Num2WordsPLTest(TestCase):
|
class Num2WordsPLTest(TestCase):
|
||||||
def test_currency(self):
|
def test_currency(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
to_currency(1234.12),
|
num2words(1234.12, lang='fr_DZ', to='currency'),
|
||||||
"mille deux cent trente-quatre dinards virgule douze centimes"
|
"mille deux cent trente-quatre dinards virgule douze centimes"
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
to_currency(45689.89),
|
num2words(45689.89, lang='fr_DZ', to='currency'),
|
||||||
"quarante-cinq mille six cent quatre-vingt-neuf dinards virgule "
|
"quarante-cinq mille six cent quatre-vingt-neuf dinards virgule "
|
||||||
"quatre-vingt-neuf centimes"
|
"quatre-vingt-neuf centimes"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_number(self):
|
||||||
|
for test in test_fr.TEST_CASES_CARDINAL:
|
||||||
|
self.assertEqual(num2words(test[0], lang='fr_DZ'), test[1])
|
||||||
|
|
||||||
|
def test_ordinal(self):
|
||||||
|
for test in test_fr.TEST_CASES_ORDINAL:
|
||||||
|
self.assertEqual(
|
||||||
|
num2words(test[0], lang='fr_DZ', ordinal=True),
|
||||||
|
test[1]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_ordinal_num(self):
|
||||||
|
for test in test_fr.TEST_CASES_ORDINAL_NUM:
|
||||||
|
self.assertEqual(
|
||||||
|
num2words(test[0], lang='fr_DZ', to='ordinal_num'),
|
||||||
|
test[1]
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user