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
2020
2121from 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
24134class 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+ )
0 commit comments