File: test_numwords.py

package info (click to toggle)
python-inflect 0.2.5-1.1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 568 kB
  • sloc: python: 4,899; makefile: 14
file content (476 lines) | stat: -rw-r--r-- 17,379 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476

from nose.tools import eq_

import inflect


def test_loop():

    p = inflect.engine()

    for thresh in range(21):
        for n in range(21):
            threshed = p.number_to_words(n, threshold=thresh)
            numwords = p.number_to_words(n)

            if (n <= thresh):
                eq_(numwords, threshed, msg="Wordified %s (<= %s)" % (n, thresh))
            else:
                # $threshed =~ s/\D//gxms;
                eq_(threshed, str(n), msg="p.number_to_words(%s, thresold=%s) == %s != %s" % (
                    n, thresh, threshed, str(n)))


def test_lines():
    p = inflect.engine()
    eq_(p.number_to_words(999, threshold=500), '999', msg=' 999 -> 999')
    eq_(p.number_to_words(1000, threshold=500), '1,000', msg='1000 -> 1,000')
    eq_(p.number_to_words(10000, threshold=500), '10,000', msg='10000 -> 10,000')
    eq_(p.number_to_words(100000, threshold=500), '100,000', msg='100000 -> 100,000')
    eq_(p.number_to_words(1000000, threshold=500), '1,000,000', msg='1000000 -> 1,000,000')

    eq_(p.number_to_words(999.3, threshold=500), '999.3', msg=' 999.3 -> 999.3')
    eq_(p.number_to_words(1000.3, threshold=500), '1,000.3', msg='1000.3 -> 1,000.3')
    eq_(p.number_to_words(10000.3, threshold=500), '10,000.3', msg='10000.3 -> 10,000.3')
    eq_(p.number_to_words(100000.3, threshold=500), '100,000.3', msg='100000.3 -> 100,000.3')
    eq_(p.number_to_words(1000000.3, threshold=500), '1,000,000.3', msg='1000000.3 -> 1,000,000.3')

    eq_(p.number_to_words(999, threshold=500, comma=0), '999', msg=' 999 -> 999')
    eq_(p.number_to_words(1000, threshold=500, comma=0), '1000', msg='1000 -> 1000')
    eq_(p.number_to_words(10000, threshold=500, comma=0), '10000', msg='10000 -> 10000')
    eq_(p.number_to_words(100000, threshold=500, comma=0), '100000', msg='100000 -> 100000')
    eq_(p.number_to_words(1000000, threshold=500, comma=0), '1000000', msg='1000000 -> 1000000')

    eq_(p.number_to_words(999.3, threshold=500, comma=0), '999.3', msg=' 999.3 -> 999.3')
    eq_(p.number_to_words(1000.3, threshold=500, comma=0), '1000.3', msg='1000.3 -> 1000.3')
    eq_(p.number_to_words(10000.3, threshold=500, comma=0), '10000.3', msg='10000.3 -> 10000.3')
    eq_(p.number_to_words(100000.3, threshold=500, comma=0), '100000.3', msg='100000.3 -> 100000.3')
    eq_(p.number_to_words(1000000.3, threshold=500, comma=0), '1000000.3', msg='1000000.3 -> 1000000.3')


def test_array():
    nw = [
        [
            "0",
            "zero",
            "zero",
            "zero",
            "zero",
            "zeroth",
        ], [
            "1",
            "one",
            "one",
            "one",
            "one",
            "first",
        ], [
            "2",
            "two",
            "two",
            "two",
            "two",
            "second",
        ], [
            "3",
            "three",
            "three",
            "three",
            "three",
            "third",
        ], [
            "4",
            "four",
            "four",
            "four",
            "four",
            "fourth",
        ], [
            "5",
            "five",
            "five",
            "five",
            "five",
            "fifth",
        ], [
            "6",
            "six",
            "six",
            "six",
            "six",
            "sixth",
        ], [
            "7",
            "seven",
            "seven",
            "seven",
            "seven",
            "seventh",
        ], [
            "8",
            "eight",
            "eight",
            "eight",
            "eight",
            "eighth",
        ], [
            "9",
            "nine",
            "nine",
            "nine",
            "nine",
            "ninth",
        ], [
            "10",
            "ten",
            "one, zero",
            "ten",
            "ten",
            "tenth",
        ], [
            "11",
            "eleven",
            "one, one",
            "eleven",
            "eleven",
            "eleventh",
        ], [
            "12",
            "twelve",
            "one, two",
            "twelve",
            "twelve",
            "twelfth",
        ], [
            "13",
            "thirteen",
            "one, three",
            "thirteen",
            "thirteen",
            "thirteenth",
        ], [
            "14",
            "fourteen",
            "one, four",
            "fourteen",
            "fourteen",
            "fourteenth",
        ], [
            "15",
            "fifteen",
            "one, five",
            "fifteen",
            "fifteen",
            "fifteenth",
        ], [
            "16",
            "sixteen",
            "one, six",
            "sixteen",
            "sixteen",
            "sixteenth",
        ], [
            "17",
            "seventeen",
            "one, seven",
            "seventeen",
            "seventeen",
            "seventeenth",
        ], [
            "18",
            "eighteen",
            "one, eight",
            "eighteen",
            "eighteen",
            "eighteenth",
        ], [
            "19",
            "nineteen",
            "one, nine",
            "nineteen",
            "nineteen",
            "nineteenth",
        ], [
            "20",
            "twenty",
            "two, zero",
            "twenty",
            "twenty",
            "twentieth",
        ], [
            "21",
            "twenty-one",
            "two, one",
            "twenty-one",
            "twenty-one",
            "twenty-first",
        ], [
            "29",
            "twenty-nine",
            "two, nine",
            "twenty-nine",
            "twenty-nine",
            "twenty-ninth",
        ], [
            "99",
            "ninety-nine",
            "nine, nine",
            "ninety-nine",
            "ninety-nine",
            "ninety-ninth",
        ], [
            "100",
            "one hundred",
            "one, zero, zero",
            "ten, zero",
            "one zero zero",
            "one hundredth"
        ], [
            "101",
            "one hundred and one",
            "one, zero, one",
            "ten, one",
            "one zero one",
            "one hundred and first"
        ], [
            "110",
            "one hundred and ten",
            "one, one, zero",
            "eleven, zero",
            "one ten",
            "one hundred and tenth",
        ], [
            "111",
            "one hundred and eleven",
            "one, one, one",
            "eleven, one",
            "one eleven",
            "one hundred and eleventh",
        ], [
            "900",
            "nine hundred",
            "nine, zero, zero",
            "ninety, zero",
            "nine zero zero",
            "nine hundredth",
        ], [
            "999",
            "nine hundred and ninety-nine",
            "nine, nine, nine",
            "ninety-nine, nine",
            "nine ninety-nine",
            "nine hundred and ninety-ninth",
        ], [
            "1000",
            "one thousand",
            "one, zero, zero, zero",
            "ten, zero zero",
            "one zero zero, zero",
            "one thousandth",
        ], [
            "1001",
            "one thousand and one",
            "one, zero, zero, one",
            "ten, zero one",
            "one zero zero, one",
            "one thousand and first",
        ], [
            "1010",
            "one thousand and ten",
            "one, zero, one, zero",
            "ten, ten",
            "one zero one, zero",
            "one thousand and tenth",
        ], [
            "1100",
            "one thousand, one hundred",
            "one, one, zero, zero",
            "eleven, zero zero",
            "one ten, zero",
            "one thousand, one hundredth",
        ], [
            "2000",
            "two thousand",
            "two, zero, zero, zero",
            "twenty, zero zero",
            "two zero zero, zero",
            "two thousandth",
        ], [
            "10000",
            "ten thousand",
            "one, zero, zero, zero, zero",
            "ten, zero zero, zero",
            "one zero zero, zero zero",
            "ten thousandth",
        ], [
            "100000",
            "one hundred thousand",
            "one, zero, zero, zero, zero, zero",
            "ten, zero zero, zero zero",
            "one zero zero, zero zero zero",
            "one hundred thousandth",
        ], [
            "100001",
            "one hundred thousand and one",
            "one, zero, zero, zero, zero, one",
            "ten, zero zero, zero one",
            "one zero zero, zero zero one",
            "one hundred thousand and first",
        ], [
            "123456",
            "one hundred and twenty-three thousand, four hundred and fifty-six",
            "one, two, three, four, five, six",
            "twelve, thirty-four, fifty-six",
            "one twenty-three, four fifty-six",
            "one hundred and twenty-three thousand, four hundred and fifty-sixth",
        ], [
            "0123456",
            "one hundred and twenty-three thousand, four hundred and fifty-six",
            "zero, one, two, three, four, five, six",
            "zero one, twenty-three, forty-five, six",
            "zero twelve, three forty-five, six",
            "one hundred and twenty-three thousand, four hundred and fifty-sixth",
        ], [
            "1234567",
            "one million, two hundred and thirty-four thousand, five hundred and sixty-seven",
            "one, two, three, four, five, six, seven",
            "twelve, thirty-four, fifty-six, seven",
            "one twenty-three, four fifty-six, seven",
            "one million, two hundred and thirty-four thousand, five hundred and sixty-seventh",
        ], [
            "12345678",
            "twelve million, three hundred and forty-five thousand, six hundred and seventy-eight",
            "one, two, three, four, five, six, seven, eight",
            "twelve, thirty-four, fifty-six, seventy-eight",
            "one twenty-three, four fifty-six, seventy-eight",
            "twelve million, three hundred and forty-five thousand, six hundred and seventy-eighth",
        ], [
            "12_345_678",
            "twelve million, three hundred and forty-five thousand, six hundred and seventy-eight",
            "one, two, three, four, five, six, seven, eight",
            "twelve, thirty-four, fifty-six, seventy-eight",
            "one twenty-three, four fifty-six, seventy-eight",
        ], [
            "1234,5678",
            "twelve million, three hundred and forty-five thousand, six hundred and seventy-eight",
            "one, two, three, four, five, six, seven, eight",
            "twelve, thirty-four, fifty-six, seventy-eight",
            "one twenty-three, four fifty-six, seventy-eight",
        ], [
            "1234567890",
            "one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninety",
            "one, two, three, four, five, six, seven, eight, nine, zero",
            "twelve, thirty-four, fifty-six, seventy-eight, ninety",
            "one twenty-three, four fifty-six, seven eighty-nine, zero",
            "one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninetieth",
        ], [
            "123456789012345",
            "one hundred and twenty-three trillion, four hundred and fifty-six billion, seven hundred and eighty-nine million, twelve thousand, three hundred and forty-five",
            "one, two, three, four, five, six, seven, eight, nine, zero, one, two, three, four, five",
            "twelve, thirty-four, fifty-six, seventy-eight, ninety, twelve, thirty-four, five",
            "one twenty-three, four fifty-six, seven eighty-nine, zero twelve, three forty-five",
            "one hundred and twenty-three trillion, four hundred and fifty-six billion, seven hundred and eighty-nine million, twelve thousand, three hundred and forty-fifth",
        ], [
            "12345678901234567890",
            "twelve quintillion, three hundred and forty-five quadrillion, six hundred and seventy-eight trillion, nine hundred and one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninety",
            "one, two, three, four, five, six, seven, eight, nine, zero, one, two, three, four, five, six, seven, eight, nine, zero",
            "twelve, thirty-four, fifty-six, seventy-eight, ninety, twelve, thirty-four, fifty-six, seventy-eight, ninety",
            "one twenty-three, four fifty-six, seven eighty-nine, zero twelve, three forty-five, six seventy-eight, ninety",
            "twelve quintillion, three hundred and forty-five quadrillion, six hundred and seventy-eight trillion, nine hundred and one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninetieth",
        ], [
            "0.987654",
            "zero point nine eight seven six five four",
            "zero, point, nine, eight, seven, six, five, four",
            "zero, point, ninety-eight, seventy-six, fifty-four",
            "zero, point, nine eighty-seven, six fifty-four",
            "zeroth point nine eight seven six five four",
            "zero point nine eight seven six five fourth",
        ], [
            ".987654",
            "point nine eight seven six five four",
            "point, nine, eight, seven, six, five, four",
            "point, ninety-eight, seventy-six, fifty-four",
            "point, nine eighty-seven, six fifty-four",
            "point nine eight seven six five four",
            "point nine eight seven six five fourth",
        ], [
            "9.87654",
            "nine point eight seven six five four",
            "nine, point, eight, seven, six, five, four",
            "nine, point, eighty-seven, sixty-five, four",
            "nine, point, eight seventy-six, fifty-four",
            "ninth point eight seven six five four",
            "nine point eight seven six five fourth",
        ], [
            "98.7654",
            "ninety-eight point seven six five four",
            "nine, eight, point, seven, six, five, four",
            "ninety-eight, point, seventy-six, fifty-four",
            "ninety-eight, point, seven sixty-five, four",
            "ninety-eighth point seven six five four",
            "ninety-eight point seven six five fourth",
        ], [
            "987.654",
            "nine hundred and eighty-seven point six five four",
            "nine, eight, seven, point, six, five, four",
            "ninety-eight, seven, point, sixty-five, four",
            "nine eighty-seven, point, six fifty-four",
            "nine hundred and eighty-seventh point six five four",
            "nine hundred and eighty-seven point six five fourth",
        ], [
            "9876.54",
            "nine thousand, eight hundred and seventy-six point five four",
            "nine, eight, seven, six, point, five, four",
            "ninety-eight, seventy-six, point, fifty-four",
            "nine eighty-seven, six, point, fifty-four",
            "nine thousand, eight hundred and seventy-sixth point five four",
            "nine thousand, eight hundred and seventy-six point five fourth",
        ], [
            "98765.4",
            "ninety-eight thousand, seven hundred and sixty-five point four",
            "nine, eight, seven, six, five, point, four",
            "ninety-eight, seventy-six, five, point, four",
            "nine eighty-seven, sixty-five, point, four",
            "ninety-eight thousand, seven hundred and sixty-fifth point four",
            "ninety-eight thousand, seven hundred and sixty-five point fourth",
        ], [
            "101.202.303",
            "one hundred and one point two zero two three zero three",
            "one, zero, one, point, two, zero, two, point, three, zero, three",
            "ten, one, point, twenty, two, point, thirty, three",
            "one zero one, point, two zero two, point, three zero three",
        ], [
            "98765.",
            "ninety-eight thousand, seven hundred and sixty-five point",
            "nine, eight, seven, six, five, point",
            "ninety-eight, seventy-six, five, point",
            "nine eighty-seven, sixty-five, point",
        ]
    ]

    p = inflect.engine()

    for i in nw:
        yield go, p, i


def go(p, i):
        eq_(p.number_to_words(i[0]), i[1], msg="number_to_words(%s) == %s != %s" % (
            i[0],
            p.number_to_words(i[0]),
            i[1]))
        eq_(p.number_to_words(i[0], group=1), i[2])
        eq_(p.number_to_words(i[0], group=2), i[3])
        eq_(p.number_to_words(i[0], group=3), i[4])
        if len(i) > 5:
            eq_(p.number_to_words(p.ordinal(i[0])), i[5], msg="number_to_words(ordinal(%s)) == %s != %s" % (
                i[0], p.number_to_words(p.ordinal(i[0])),
                i[5]))
        if len(i) > 6:
            eq_(p.ordinal(p.number_to_words(i[0])), i[6])
        else:
            if len(i) > 5:
                eq_(p.ordinal(p.number_to_words(i[0])), i[5])

        # eq_ !eval { p.number_to_words(42, and=>); 1; };
        # eq_ $@ =~ 'odd number of';