Skip to content

Commit 9819498

Browse files
authored
Increase test coverage for lang fr* (#136)
Ref: issues #116 #121 #127
1 parent 1e954c9 commit 9819498

File tree

6 files changed

+270
-89
lines changed

6 files changed

+270
-89
lines changed

num2words/lang_FR.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,31 +90,8 @@ def to_ordinal_num(self, value):
9090
return out
9191

9292
def to_currency(self, val, longval=True, old=False):
93-
hightxt = "Euro/s"
93+
hightxt = "euro/s"
9494
if old:
9595
hightxt = "franc/s"
9696
return self.to_splitnum(val, hightxt=hightxt, lowtxt="centime/s",
97-
jointxt="et", longval=longval)
98-
99-
100-
n2w = Num2Word_FR()
101-
to_card = n2w.to_cardinal
102-
to_ord = n2w.to_ordinal
103-
to_ordnum = n2w.to_ordinal_num
104-
105-
106-
def main():
107-
for val in [1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155,
108-
180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000,
109-
8280, 8291, 150000, 500000, 1000000, 2000000, 2000001,
110-
-21212121211221211111, -2.121212, -1.0000100]:
111-
n2w.test(val)
112-
113-
n2w.test(
114-
1325325436067876801768700107601001012212132143210473207540327057320957)
115-
print(n2w.to_currency(112121))
116-
print(n2w.to_year(1996))
117-
118-
119-
if __name__ == "__main__":
120-
main()
97+
divisor=1, jointxt="et", longval=longval)

num2words/lang_FR_CH.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,3 @@ def merge(self, curr, next):
4747
if nnum > cnum:
4848
return ("%s %s" % (ctext, ntext), cnum * nnum)
4949
return ("%s %s" % (ctext, ntext), cnum + nnum)
50-
51-
52-
n2w = Num2Word_FR_CH()
53-
to_card = n2w.to_cardinal
54-
to_ord = n2w.to_ordinal
55-
to_ordnum = n2w.to_ordinal_num
56-
57-
58-
def main():
59-
for val in [1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155,
60-
180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000,
61-
8280, 8291, 150000, 500000, 1000000, 2000000, 2000001,
62-
-21212121211221211111, -2.121212, -1.0000100]:
63-
n2w.test(val)
64-
65-
n2w.test(
66-
1325325436067876801768700107601001012212132143210473207540327057320950)
67-
print(n2w.to_currency(112121))
68-
print(n2w.to_year(1996))
69-
70-
71-
if __name__ == "__main__":
72-
main()

num2words/lang_FR_DZ.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,7 @@
2121

2222
class Num2Word_FR_DZ(Num2Word_FR):
2323
def to_currency(self, val, longval=True, cents=True, jointxt="virgule"):
24-
return self.to_splitnum(val, hightxt="dinard/s", lowtxt="centime/s",
25-
jointxt=jointxt, longval=longval, cents=cents)
26-
27-
28-
n2w = Num2Word_FR_DZ()
29-
to_card = n2w.to_cardinal
30-
to_ord = n2w.to_ordinal
31-
to_ordnum = n2w.to_ordinal_num
32-
to_year = n2w.to_year
33-
to_currency = n2w.to_currency
34-
35-
36-
def main():
37-
for val in [1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155,
38-
180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000,
39-
8280, 8291, 150000, 500000, 1000000, 2000000, 2000001,
40-
-21212121211221211111, -2.121212, -1.0000100]:
41-
n2w.test(val)
42-
43-
n2w.test(
44-
1325325436067876801768700107601001012212132143210473207540327057320950)
45-
for val in [1, 120, 1000, 1120, 1800, 1976, 2000, 2010, 2099, 2171]:
46-
print(val, "is", n2w.to_currency(val))
47-
print(val, "is", n2w.to_year(val))
48-
49-
50-
if __name__ == "__main__":
51-
main()
24+
return self.to_splitnum(
25+
val, hightxt="dinard/s", lowtxt="centime/s", divisor=1,
26+
jointxt=jointxt, longval=longval, cents=cents
27+
)

tests/test_fr.py

Lines changed: 152 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# -*- encoding: utf-8 -*-
2-
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
3-
4-
# This library is free software; you can redistribute it and/or
5-
# modify it under the terms of the GNU Lesser General Public
6-
# License as published by the Free Software Foundation; either
7-
# version 2.1 of the License, or (at your option) any later version.
8-
# This library is distributed in the hope that it will be useful,
9-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
2+
# Copetright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
3+
4+
# This libraret is free software; etou can redistribute it and/or
5+
# modifet it under the terms of the GNU Lesser General Public
6+
# License as published bet the Free Software Foundation; either
7+
# version 2.1 of the License, or (at etour option) anet later version.
8+
# This libraret is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warrantet of
1010
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1111
# Lesser General Public License for more details.
12-
# You should have received a copy of the GNU Lesser General Public
13-
# License along with this library; if not, write to the Free Software
12+
# You should have received a copet of the GNU Lesser General Public
13+
# License along with this libraret; if not, write to the Free Software
1414
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
1515
# MA 02110-1301 USA
1616

@@ -20,6 +20,116 @@
2020

2121
from num2words import num2words
2222

23+
TEST_CASES_CARDINAL = (
24+
(1, 'un'),
25+
(2, 'deux'),
26+
(3, 'trois'),
27+
(5.5, 'cinq virgule cinq'),
28+
(11, 'onze'),
29+
(12, 'douze'),
30+
(16, 'seize'),
31+
(17.42, 'dix-sept virgule quatre deux'),
32+
(19, 'dix-neuf'),
33+
(20, 'vingt'),
34+
(21, 'vingt et un'),
35+
(26, 'vingt-six'),
36+
(27.312, 'vingt-sept virgule trois un deux'),
37+
(28, 'vingt-huit'),
38+
(30, 'trente'),
39+
(31, 'trente et un'),
40+
(40, 'quarante'),
41+
(44, 'quarante-quatre'),
42+
(50, 'cinquante'),
43+
(53.486, 'cinquante-trois virgule quatre huit six'),
44+
(55, 'cinquante-cinq'),
45+
(60, 'soixante'),
46+
(67, 'soixante-sept'),
47+
(70, 'soixante-dix'),
48+
(79, 'soixante-dix-neuf'),
49+
(89, 'quatre-vingt-neuf'),
50+
(95, 'quatre-vingt-quinze'),
51+
(100, 'cent'),
52+
(101, 'cent un'),
53+
(199, 'cent quatre-vingt-dix-neuf'),
54+
(203, 'deux cent trois'),
55+
(287, 'deux cent quatre-vingt-sept'),
56+
(300.42, 'trois cents virgule quatre deux'),
57+
(356, 'trois cent cinquante-six'),
58+
(400, 'quatre cents'),
59+
(434, 'quatre cent trente-quatre'),
60+
(578, 'cinq cent soixante-dix-huit'),
61+
(689, 'six cent quatre-vingt-neuf'),
62+
(729, 'sept cent vingt-neuf'),
63+
(894, 'huit cent quatre-vingt-quatorze'),
64+
(999, 'neuf cent quatre-vingt-dix-neuf'),
65+
(1000, 'mille'),
66+
(1001, 'mille un'),
67+
(1097, 'mille quatre-vingt-dix-sept'),
68+
(1104, 'mille cent quatre'),
69+
(1243, 'mille deux cent quarante-trois'),
70+
(2385, 'deux mille trois cent quatre-vingt-cinq'),
71+
(3766, 'trois mille sept cent soixante-six'),
72+
(4196, 'quatre mille cent quatre-vingt-seize'),
73+
(4196.42, 'quatre mille cent quatre-vingt-seize virgule quatre deux'),
74+
(5846, 'cinq mille huit cent quarante-six'),
75+
(6459, 'six mille quatre cent cinquante-neuf'),
76+
(7232, 'sept mille deux cent trente-deux'),
77+
(8569, 'huit mille cinq cent soixante-neuf'),
78+
(9539, 'neuf mille cinq cent trente-neuf'),
79+
(1000000, 'un million'),
80+
(1000001, 'un million un'),
81+
(4000000, 'quatre millions'),
82+
(10000000000000, 'dix billions'),
83+
(100000000000000, 'cent billions'),
84+
(1000000000000000000, 'un trillion'),
85+
(1000000000000000000000, 'un trilliard'),
86+
(10000000000000000000000000, 'dix quadrillions')
87+
)
88+
89+
TEST_CASES_ORDINAL = (
90+
(1, 'premier'),
91+
(8, 'huitième'),
92+
(12, 'douzième'),
93+
(14, 'quatorzième'),
94+
(28, 'vingt-huitième'),
95+
(100, 'centième'),
96+
(1000, 'millième'),
97+
(1000000, 'un millionième'),
98+
(1000000000000000, 'un billiardième'),
99+
(1000000000000000000, 'un trillionième') # over 1e18 is not supported
100+
)
101+
102+
TEST_CASES_ORDINAL_NUM = (
103+
(1, '1er'),
104+
(8, '8me'),
105+
(12, '12me'),
106+
(14, '14me'),
107+
(28, '28me'),
108+
(100, '100me'),
109+
(1000, '1000me'),
110+
(1000000, '1000000me')
111+
)
112+
113+
TEST_CASES_TO_CURRENCY = (
114+
(1, 'un euro'),
115+
(2, 'deux euros'),
116+
(8, 'huit euros'),
117+
(12, 'douze euros'),
118+
(21, 'vingt et un euros'),
119+
(81.25, 'quatre-vingt-un euros et vingt-cinq centimes'),
120+
(100, 'cent euros'),
121+
)
122+
123+
TEST_CASES_TO_CURRENCY_OLD = (
124+
(1, 'un franc'),
125+
(2, 'deux francs'),
126+
(8, 'huit francs'),
127+
(12, 'douze francs'),
128+
(21, 'vingt et un francs'),
129+
(81.25, 'quatre-vingt-un francs et vingt-cinq centimes'),
130+
(100, 'cent francs'),
131+
)
132+
23133

24134
class Num2WordsENTest(TestCase):
25135
def test_ordinal_special_joins(self):
@@ -36,3 +146,35 @@ def test_ordinal_special_joins(self):
36146
self.assertEqual(
37147
num2words(49, ordinal=True, lang='fr'), "quarante-neuvième"
38148
)
149+
150+
def test_number(self):
151+
for test in TEST_CASES_CARDINAL:
152+
self.assertEqual(num2words(test[0], lang='fr'), test[1])
153+
154+
def test_ordinal(self):
155+
for test in TEST_CASES_ORDINAL:
156+
self.assertEqual(
157+
num2words(test[0], lang='fr', ordinal=True),
158+
test[1]
159+
)
160+
161+
def test_ordinal_num(self):
162+
for test in TEST_CASES_ORDINAL_NUM:
163+
self.assertEqual(
164+
num2words(test[0], lang='fr', to='ordinal_num'),
165+
test[1]
166+
)
167+
168+
def test_currency(self):
169+
for test in TEST_CASES_TO_CURRENCY:
170+
self.assertEqual(
171+
num2words(test[0], lang='fr', to='currency'),
172+
test[1]
173+
)
174+
175+
def test_currency_old(self):
176+
for test in TEST_CASES_TO_CURRENCY_OLD:
177+
self.assertEqual(
178+
num2words(test[0], lang='fr', to='currency', old=True),
179+
test[1]
180+
)

tests/test_fr_ch.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,60 @@
2020

2121
from num2words import num2words
2222

23+
TEST_CASES_CARDINAL = (
24+
(70, 'septante'),
25+
(79, 'septante-neuf'),
26+
(89, 'huitante-neuf'),
27+
(95, 'nonante-cinq'),
28+
(729, 'sept cents vingt-neuf'),
29+
(894, 'huit cents nonante-quatre'),
30+
(999, 'neuf cents nonante-neuf'),
31+
(7232, 'sept mille deux cents trente-deux'),
32+
(8569, 'huit mille cinq cents soixante-neuf'),
33+
(9539, 'neuf mille cinq cents trente-neuf'),
34+
(1000000, 'un millions'),
35+
(1000001, 'un millions un'),
36+
(4000000, 'quatre millions'),
37+
(10000000000000, 'dix billions'),
38+
(100000000000000, 'cent billions'),
39+
(1000000000000000000, 'un trillions'),
40+
(1000000000000000000000, 'un trilliards'),
41+
(10000000000000000000000000, 'dix quadrillions')
42+
)
43+
44+
TEST_CASES_ORDINAL = (
45+
(1, 'premier'),
46+
(8, 'huitième'),
47+
(12, 'douzième'),
48+
(14, 'quatorzième'),
49+
(28, 'vingt-huitième'),
50+
(100, 'centième'),
51+
(1000, 'millième'),
52+
(1000000, 'un millionsième'),
53+
(1000000000000000, 'un billiardsième'),
54+
(1000000000000000000, 'un trillionsième') # over 1e18 is not supported
55+
)
56+
57+
TEST_CASES_TO_CURRENCY = (
58+
(1, 'un euro'),
59+
(2, 'deux euros'),
60+
(8, 'huit euros'),
61+
(12, 'douze euros'),
62+
(21, 'vingt et un euros'),
63+
(81.25, 'huitante et un euros et vingt-cinq centimes'),
64+
(100, 'cent euros'),
65+
)
66+
67+
TEST_CASES_TO_CURRENCY_OLD = (
68+
(1, 'un franc'),
69+
(2, 'deux francs'),
70+
(8, 'huit francs'),
71+
(12, 'douze francs'),
72+
(21, 'vingt et un francs'),
73+
(81.25, 'huitante et un francs et vingt-cinq centimes'),
74+
(100, 'cent francs'),
75+
)
76+
2377

2478
class Num2WordsENTest(TestCase):
2579
def test_ordinal_special_joins(self):
@@ -44,3 +98,28 @@ def test_ordinal_special_joins(self):
4498
num2words(91, ordinal=True, lang='fr_CH'), "nonante et unième"
4599
)
46100
self.assertEqual(num2words(53, lang='fr_CH'), "cinquante-trois")
101+
102+
def test_number(self):
103+
for test in TEST_CASES_CARDINAL:
104+
self.assertEqual(num2words(test[0], lang='fr_CH'), test[1])
105+
106+
def test_ordinal(self):
107+
for test in TEST_CASES_ORDINAL:
108+
self.assertEqual(
109+
num2words(test[0], lang='fr_CH', ordinal=True),
110+
test[1]
111+
)
112+
113+
def test_currency(self):
114+
for test in TEST_CASES_TO_CURRENCY:
115+
self.assertEqual(
116+
num2words(test[0], lang='fr_CH', to='currency'),
117+
test[1]
118+
)
119+
120+
def test_currency_old(self):
121+
for test in TEST_CASES_TO_CURRENCY_OLD:
122+
self.assertEqual(
123+
num2words(test[0], lang='fr_CH', to='currency', old=True),
124+
test[1]
125+
)

0 commit comments

Comments
 (0)