| 1 |
import inflect |
| 2 |
|
| 3 |
|
| 4 |
def test_loop(): |
| 5 |
p = inflect.engine() |
| 6 |
|
| 7 |
for thresh in range(21): |
| 8 |
for n in range(21): |
| 9 |
threshed = p.number_to_words(n, threshold=thresh) |
| 10 |
numwords = p.number_to_words(n) |
| 11 |
|
| 12 |
if n <= thresh: |
| 13 |
assert numwords == threshed |
| 14 |
else: |
| 15 |
|
| 16 |
assert threshed == str(n) |
| 17 |
|
| 18 |
|
| 19 |
def test_lines(): |
| 20 |
p = inflect.engine() |
| 21 |
assert p.number_to_words(999, threshold=500) == "999" |
| 22 |
assert p.number_to_words(1000, threshold=500) == "1,000" |
| 23 |
assert p.number_to_words(10000, threshold=500) == "10,000" |
| 24 |
assert p.number_to_words(100000, threshold=500) == "100,000" |
| 25 |
assert p.number_to_words(1000000, threshold=500) == "1,000,000" |
| 26 |
|
| 27 |
assert p.number_to_words(999.3, threshold=500) == "999.3" |
| 28 |
assert p.number_to_words(1000.3, threshold=500) == "1,000.3" |
| 29 |
assert p.number_to_words(10000.3, threshold=500) == "10,000.3" |
| 30 |
|
| 31 |
assert p.number_to_words(100000.3, threshold=500) == "100,000.3" |
| 32 |
assert p.number_to_words(1000000.3, threshold=500) == "1,000,000.3" |
| 33 |
|
| 34 |
assert p.number_to_words(999, threshold=500, comma=0) == "999" |
| 35 |
assert p.number_to_words(1000, threshold=500, comma=0) == "1000" |
| 36 |
assert p.number_to_words(10000, threshold=500, comma=0) == "10000" |
| 37 |
assert p.number_to_words(100000, threshold=500, comma=0) == "100000" |
| 38 |
assert p.number_to_words(1000000, threshold=500, comma=0) == "1000000" |
| 39 |
|
| 40 |
assert p.number_to_words(999.3, threshold=500, comma=0) == "999.3" |
| 41 |
assert p.number_to_words(1000.3, threshold=500, comma=0) == "1000.3" |
| 42 |
assert p.number_to_words(10000.3, threshold=500, comma=0) == "10000.3" |
| 43 |
assert p.number_to_words(100000.3, threshold=500, comma=0) == "100000.3" |
| 44 |
assert p.number_to_words(1000000.3, threshold=500, comma=0) == "1000000.3" |
| 45 |
|
| 46 |
|
| 47 |
def test_array(): |
| 48 |
nw = [ |
| 49 |
["0", "zero", "zero", "zero", "zero", "zeroth"], |
| 50 |
["1", "one", "one", "one", "one", "first"], |
| 51 |
["2", "two", "two", "two", "two", "second"], |
| 52 |
["3", "three", "three", "three", "three", "third"], |
| 53 |
["4", "four", "four", "four", "four", "fourth"], |
| 54 |
["5", "five", "five", "five", "five", "fifth"], |
| 55 |
["6", "six", "six", "six", "six", "sixth"], |
| 56 |
["7", "seven", "seven", "seven", "seven", "seventh"], |
| 57 |
["8", "eight", "eight", "eight", "eight", "eighth"], |
| 58 |
["9", "nine", "nine", "nine", "nine", "ninth"], |
| 59 |
["10", "ten", "one, zero", "ten", "ten", "tenth"], |
| 60 |
["11", "eleven", "one, one", "eleven", "eleven", "eleventh"], |
| 61 |
["12", "twelve", "one, two", "twelve", "twelve", "twelfth"], |
| 62 |
["13", "thirteen", "one, three", "thirteen", "thirteen", "thirteenth"], |
| 63 |
["14", "fourteen", "one, four", "fourteen", "fourteen", "fourteenth"], |
| 64 |
["15", "fifteen", "one, five", "fifteen", "fifteen", "fifteenth"], |
| 65 |
["16", "sixteen", "one, six", "sixteen", "sixteen", "sixteenth"], |
| 66 |
["17", "seventeen", "one, seven", "seventeen", "seventeen", "seventeenth"], |
| 67 |
["18", "eighteen", "one, eight", "eighteen", "eighteen", "eighteenth"], |
| 68 |
["19", "nineteen", "one, nine", "nineteen", "nineteen", "nineteenth"], |
| 69 |
["20", "twenty", "two, zero", "twenty", "twenty", "twentieth"], |
| 70 |
["21", "twenty-one", "two, one", "twenty-one", "twenty-one", "twenty-first"], |
| 71 |
[ |
| 72 |
"29", |
| 73 |
"twenty-nine", |
| 74 |
"two, nine", |
| 75 |
"twenty-nine", |
| 76 |
"twenty-nine", |
| 77 |
"twenty-ninth", |
| 78 |
], |
| 79 |
[ |
| 80 |
"99", |
| 81 |
"ninety-nine", |
| 82 |
"nine, nine", |
| 83 |
"ninety-nine", |
| 84 |
"ninety-nine", |
| 85 |
"ninety-ninth", |
| 86 |
], |
| 87 |
[ |
| 88 |
"100", |
| 89 |
"one hundred", |
| 90 |
"one, zero, zero", |
| 91 |
"ten, zero", |
| 92 |
"one zero zero", |
| 93 |
"one hundredth", |
| 94 |
], |
| 95 |
[ |
| 96 |
"101", |
| 97 |
"one hundred and one", |
| 98 |
"one, zero, one", |
| 99 |
"ten, one", |
| 100 |
"one zero one", |
| 101 |
"one hundred and first", |
| 102 |
], |
| 103 |
[ |
| 104 |
"110", |
| 105 |
"one hundred and ten", |
| 106 |
"one, one, zero", |
| 107 |
"eleven, zero", |
| 108 |
"one ten", |
| 109 |
"one hundred and tenth", |
| 110 |
], |
| 111 |
[ |
| 112 |
"111", |
| 113 |
"one hundred and eleven", |
| 114 |
"one, one, one", |
| 115 |
"eleven, one", |
| 116 |
"one eleven", |
| 117 |
"one hundred and eleventh", |
| 118 |
], |
| 119 |
[ |
| 120 |
"900", |
| 121 |
"nine hundred", |
| 122 |
"nine, zero, zero", |
| 123 |
"ninety, zero", |
| 124 |
"nine zero zero", |
| 125 |
"nine hundredth", |
| 126 |
], |
| 127 |
[ |
| 128 |
"999", |
| 129 |
"nine hundred and ninety-nine", |
| 130 |
"nine, nine, nine", |
| 131 |
"ninety-nine, nine", |
| 132 |
"nine ninety-nine", |
| 133 |
"nine hundred and ninety-ninth", |
| 134 |
], |
| 135 |
[ |
| 136 |
"1000", |
| 137 |
"one thousand", |
| 138 |
"one, zero, zero, zero", |
| 139 |
"ten, zero zero", |
| 140 |
"one zero zero, zero", |
| 141 |
"one thousandth", |
| 142 |
], |
| 143 |
[ |
| 144 |
"1001", |
| 145 |
"one thousand and one", |
| 146 |
"one, zero, zero, one", |
| 147 |
"ten, zero one", |
| 148 |
"one zero zero, one", |
| 149 |
"one thousand and first", |
| 150 |
], |
| 151 |
[ |
| 152 |
"1010", |
| 153 |
"one thousand and ten", |
| 154 |
"one, zero, one, zero", |
| 155 |
"ten, ten", |
| 156 |
"one zero one, zero", |
| 157 |
"one thousand and tenth", |
| 158 |
], |
| 159 |
[ |
| 160 |
"1100", |
| 161 |
"one thousand, one hundred", |
| 162 |
"one, one, zero, zero", |
| 163 |
"eleven, zero zero", |
| 164 |
"one ten, zero", |
| 165 |
"one thousand, one hundredth", |
| 166 |
], |
| 167 |
[ |
| 168 |
"2000", |
| 169 |
"two thousand", |
| 170 |
"two, zero, zero, zero", |
| 171 |
"twenty, zero zero", |
| 172 |
"two zero zero, zero", |
| 173 |
"two thousandth", |
| 174 |
], |
| 175 |
[ |
| 176 |
"10000", |
| 177 |
"ten thousand", |
| 178 |
"one, zero, zero, zero, zero", |
| 179 |
"ten, zero zero, zero", |
| 180 |
"one zero zero, zero zero", |
| 181 |
"ten thousandth", |
| 182 |
], |
| 183 |
[ |
| 184 |
"100000", |
| 185 |
"one hundred thousand", |
| 186 |
"one, zero, zero, zero, zero, zero", |
| 187 |
"ten, zero zero, zero zero", |
| 188 |
"one zero zero, zero zero zero", |
| 189 |
"one hundred thousandth", |
| 190 |
], |
| 191 |
[ |
| 192 |
"100001", |
| 193 |
"one hundred thousand and one", |
| 194 |
"one, zero, zero, zero, zero, one", |
| 195 |
"ten, zero zero, zero one", |
| 196 |
"one zero zero, zero zero one", |
| 197 |
"one hundred thousand and first", |
| 198 |
], |
| 199 |
[ |
| 200 |
"123456", |
| 201 |
"one hundred and twenty-three thousand, four hundred and fifty-six", |
| 202 |
"one, two, three, four, five, six", |
| 203 |
"twelve, thirty-four, fifty-six", |
| 204 |
"one twenty-three, four fifty-six", |
| 205 |
"one hundred and twenty-three thousand, four hundred and fifty-sixth", |
| 206 |
], |
| 207 |
[ |
| 208 |
"0123456", |
| 209 |
"one hundred and twenty-three thousand, four hundred and fifty-six", |
| 210 |
"zero, one, two, three, four, five, six", |
| 211 |
"zero one, twenty-three, forty-five, six", |
| 212 |
"zero twelve, three forty-five, six", |
| 213 |
"one hundred and twenty-three thousand, four hundred and fifty-sixth", |
| 214 |
], |
| 215 |
[ |
| 216 |
"1234567", |
| 217 |
"one million, two hundred and thirty-four thousand, " |
| 218 |
"five hundred and sixty-seven", |
| 219 |
"one, two, three, four, five, six, seven", |
| 220 |
"twelve, thirty-four, fifty-six, seven", |
| 221 |
"one twenty-three, four fifty-six, seven", |
| 222 |
"one million, two hundred and thirty-four thousand, " |
| 223 |
"five hundred and sixty-seventh", |
| 224 |
], |
| 225 |
[ |
| 226 |
"12345678", |
| 227 |
"twelve million, three hundred and forty-five thousand, " |
| 228 |
"six hundred and seventy-eight", |
| 229 |
"one, two, three, four, five, six, seven, eight", |
| 230 |
"twelve, thirty-four, fifty-six, seventy-eight", |
| 231 |
"one twenty-three, four fifty-six, seventy-eight", |
| 232 |
"twelve million, three hundred and forty-five thousand, " |
| 233 |
"six hundred and seventy-eighth", |
| 234 |
], |
| 235 |
[ |
| 236 |
"12_345_678", |
| 237 |
"twelve million, three hundred and forty-five thousand, " |
| 238 |
"six hundred and seventy-eight", |
| 239 |
"one, two, three, four, five, six, seven, eight", |
| 240 |
"twelve, thirty-four, fifty-six, seventy-eight", |
| 241 |
"one twenty-three, four fifty-six, seventy-eight", |
| 242 |
], |
| 243 |
[ |
| 244 |
"1234,5678", |
| 245 |
"twelve million, three hundred and forty-five thousand, " |
| 246 |
"six hundred and seventy-eight", |
| 247 |
"one, two, three, four, five, six, seven, eight", |
| 248 |
"twelve, thirty-four, fifty-six, seventy-eight", |
| 249 |
"one twenty-three, four fifty-six, seventy-eight", |
| 250 |
], |
| 251 |
[ |
| 252 |
"1234567890", |
| 253 |
"one billion, two hundred and thirty-four million, five hundred " |
| 254 |
"and sixty-seven thousand, eight hundred and ninety", |
| 255 |
"one, two, three, four, five, six, seven, eight, nine, zero", |
| 256 |
"twelve, thirty-four, fifty-six, seventy-eight, ninety", |
| 257 |
"one twenty-three, four fifty-six, seven eighty-nine, zero", |
| 258 |
"one billion, two hundred and thirty-four million, five hundred " |
| 259 |
"and sixty-seven thousand, eight hundred and ninetieth", |
| 260 |
], |
| 261 |
[ |
| 262 |
"123456789012345", |
| 263 |
"one hundred and twenty-three trillion, four hundred and " |
| 264 |
"fifty-six billion, seven hundred and eighty-nine million, twelve " |
| 265 |
"thousand, three hundred and forty-five", |
| 266 |
"one, two, three, four, five, six, seven, eight, nine, zero, one, " |
| 267 |
"two, three, four, five", |
| 268 |
"twelve, thirty-four, fifty-six, seventy-eight, ninety, twelve, " |
| 269 |
"thirty-four, five", |
| 270 |
"one twenty-three, four fifty-six, seven eighty-nine, " |
| 271 |
"zero twelve, three forty-five", |
| 272 |
"one hundred and twenty-three trillion, four hundred and " |
| 273 |
"fifty-six billion, seven hundred and eighty-nine million, " |
| 274 |
"twelve thousand, three hundred and forty-fifth", |
| 275 |
], |
| 276 |
[ |
| 277 |
"12345678901234567890", |
| 278 |
"twelve quintillion, three hundred and forty-five quadrillion, " |
| 279 |
"six hundred and seventy-eight trillion, nine hundred and one " |
| 280 |
"billion, two hundred and thirty-four million, five hundred and " |
| 281 |
"sixty-seven thousand, eight hundred and ninety", |
| 282 |
"one, two, three, four, five, six, seven, eight, nine, zero, one, " |
| 283 |
"two, three, four, five, six, seven, eight, nine, zero", |
| 284 |
"twelve, thirty-four, fifty-six, seventy-eight, ninety, twelve, " |
| 285 |
"thirty-four, fifty-six, seventy-eight, ninety", |
| 286 |
"one twenty-three, four fifty-six, seven eighty-nine, " |
| 287 |
"zero twelve, three forty-five, six seventy-eight, ninety", |
| 288 |
"twelve quintillion, three hundred and forty-five quadrillion, " |
| 289 |
"six hundred and seventy-eight trillion, nine hundred and one " |
| 290 |
"billion, two hundred and thirty-four million, five hundred and " |
| 291 |
"sixty-seven thousand, eight hundred and ninetieth", |
| 292 |
], |
| 293 |
[ |
| 294 |
"0.987654", |
| 295 |
"zero point nine eight seven six five four", |
| 296 |
"zero, point, nine, eight, seven, six, five, four", |
| 297 |
"zero, point, ninety-eight, seventy-six, fifty-four", |
| 298 |
"zero, point, nine eighty-seven, six fifty-four", |
| 299 |
"zeroth point nine eight seven six five four", |
| 300 |
"zero point nine eight seven six five fourth", |
| 301 |
], |
| 302 |
[ |
| 303 |
".987654", |
| 304 |
"point nine eight seven six five four", |
| 305 |
"point, nine, eight, seven, six, five, four", |
| 306 |
"point, ninety-eight, seventy-six, fifty-four", |
| 307 |
"point, nine eighty-seven, six fifty-four", |
| 308 |
"point nine eight seven six five four", |
| 309 |
"point nine eight seven six five fourth", |
| 310 |
], |
| 311 |
[ |
| 312 |
"9.87654", |
| 313 |
"nine point eight seven six five four", |
| 314 |
"nine, point, eight, seven, six, five, four", |
| 315 |
"nine, point, eighty-seven, sixty-five, four", |
| 316 |
"nine, point, eight seventy-six, fifty-four", |
| 317 |
"ninth point eight seven six five four", |
| 318 |
"nine point eight seven six five fourth", |
| 319 |
], |
| 320 |
[ |
| 321 |
"98.7654", |
| 322 |
"ninety-eight point seven six five four", |
| 323 |
"nine, eight, point, seven, six, five, four", |
| 324 |
"ninety-eight, point, seventy-six, fifty-four", |
| 325 |
"ninety-eight, point, seven sixty-five, four", |
| 326 |
"ninety-eighth point seven six five four", |
| 327 |
"ninety-eight point seven six five fourth", |
| 328 |
], |
| 329 |
[ |
| 330 |
"987.654", |
| 331 |
"nine hundred and eighty-seven point six five four", |
| 332 |
"nine, eight, seven, point, six, five, four", |
| 333 |
"ninety-eight, seven, point, sixty-five, four", |
| 334 |
"nine eighty-seven, point, six fifty-four", |
| 335 |
"nine hundred and eighty-seventh point six five four", |
| 336 |
"nine hundred and eighty-seven point six five fourth", |
| 337 |
], |
| 338 |
[ |
| 339 |
"9876.54", |
| 340 |
"nine thousand, eight hundred and seventy-six point five four", |
| 341 |
"nine, eight, seven, six, point, five, four", |
| 342 |
"ninety-eight, seventy-six, point, fifty-four", |
| 343 |
"nine eighty-seven, six, point, fifty-four", |
| 344 |
"nine thousand, eight hundred and seventy-sixth point five four", |
| 345 |
"nine thousand, eight hundred and seventy-six point five fourth", |
| 346 |
], |
| 347 |
[ |
| 348 |
"98765.4", |
| 349 |
"ninety-eight thousand, seven hundred and sixty-five point four", |
| 350 |
"nine, eight, seven, six, five, point, four", |
| 351 |
"ninety-eight, seventy-six, five, point, four", |
| 352 |
"nine eighty-seven, sixty-five, point, four", |
| 353 |
"ninety-eight thousand, seven hundred and sixty-fifth point four", |
| 354 |
"ninety-eight thousand, seven hundred and sixty-five point fourth", |
| 355 |
], |
| 356 |
[ |
| 357 |
"101.202.303", |
| 358 |
"one hundred and one point two zero two three zero three", |
| 359 |
"one, zero, one, point, two, zero, two, point, three, zero, three", |
| 360 |
"ten, one, point, twenty, two, point, thirty, three", |
| 361 |
"one zero one, point, two zero two, point, three zero three", |
| 362 |
], |
| 363 |
[ |
| 364 |
"98765.", |
| 365 |
"ninety-eight thousand, seven hundred and sixty-five point", |
| 366 |
"nine, eight, seven, six, five, point", |
| 367 |
"ninety-eight, seventy-six, five, point", |
| 368 |
"nine eighty-seven, sixty-five, point", |
| 369 |
], |
| 370 |
] |
| 371 |
|
| 372 |
p = inflect.engine() |
| 373 |
|
| 374 |
for i in nw: |
| 375 |
go(p, i) |
| 376 |
|
| 377 |
|
| 378 |
def go(p, i): |
| 379 |
assert p.number_to_words(i[0]) == i[1] |
| 380 |
assert p.number_to_words(i[0], group=1) == i[2] |
| 381 |
assert p.number_to_words(i[0], group=2) == i[3] |
| 382 |
assert p.number_to_words(i[0], group=3) == i[4] |
| 383 |
if len(i) > 5: |
| 384 |
assert p.number_to_words(p.ordinal(i[0])) == i[5] |
| 385 |
if len(i) > 6: |
| 386 |
assert p.ordinal(p.number_to_words(i[0])) == i[6] |
| 387 |
else: |
| 388 |
if len(i) > 5: |
| 389 |
assert p.ordinal(p.number_to_words(i[0])) == i[5] |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
def test_issue_131(): |
| 396 |
p = inflect.engine() |
| 397 |
for nth_word in inflect.nth_suff: |
| 398 |
assert p.number_to_words(nth_word) == "zero" |