Gets the name of a number, even if it's stupidly big. Supersedes TheoryOfNekomata/number-name.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chongo.test.ts 20 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import { describe, it, expect } from 'vitest';
  2. import { stringify, parse } from '../../../src';
  3. import { numberToExponential } from '../../../src/exponent';
  4. describe('Landon\'s original test cases', () => {
  5. describe('Basic conversions', () => {
  6. it.each`
  7. value | americanName
  8. ${1} | ${'one'}
  9. ${1000} | ${'one thousand'}
  10. ${1000000} | ${'one million'}
  11. ${1000000000} | ${'one billion'}
  12. ${1000000000000} | ${'one trillion'}
  13. ${1000000000000000} | ${'one quadrillion'}
  14. ${1000000000000000000} | ${'one quintillion'}
  15. `('converts $value to $americanName', ({value, americanName}) => {
  16. expect(stringify(value)).toBe(americanName);
  17. expect(parse(americanName, { type: 'number' })).toBe(value);
  18. });
  19. it(
  20. 'converts 987654321 to nine hundred eighty seven million six hundred fifty four thousand three hundred twenty one',
  21. () => {
  22. expect(stringify(987654321))
  23. .toBe('nine hundred eighty seven million six hundred fifty four thousand three hundred twenty one');
  24. },
  25. );
  26. it(
  27. 'converts 123456789246801357 to one hundred twenty three quadrillion four hundred fifty six trillion seven hundred eighty nine billion two hundred forty six million eight hundred one thousand three hundred fifty seven',
  28. () => {
  29. expect(stringify('123456789246801357'))
  30. .toBe(
  31. 'one hundred twenty three quadrillion four hundred fifty six trillion seven hundred eighty nine billion two hundred forty six million eight hundred one thousand three hundred fifty seven');
  32. },
  33. );
  34. it(
  35. 'converts 123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 to one hundred twenty three duoseptuagintillion four hundred fifty six unseptuagintillion seven hundred eighty nine septuagintillion two hundred forty six novemsexagintillion eight hundred one octosexagintillion three hundred fifty seven septensexagintillion',
  36. () => {
  37. expect(stringify(
  38. '123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'))
  39. .toBe(
  40. 'one hundred twenty three duoseptuagintillion four hundred fifty six unseptuagintillion seven hundred eighty nine septuagintillion two hundred forty six novemsexagintillion eight hundred one octosexagintillion three hundred fifty seven septensexagintillion');
  41. },
  42. );
  43. it(
  44. 'converts 123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 to one hundred twenty three cenduoseptuagintillion four hundred fifty six cenunseptuagintillion seven hundred eighty nine censeptuagintillion two hundred forty six cennovemsexagintillion eight hundred one cenoctosexagintillion three hundred fifty seven censeptensexagintillion',
  45. () => {
  46. expect(stringify(
  47. '123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'))
  48. .toBe(
  49. 'one hundred twenty three cenduoseptuagintillion four hundred fifty six cenunseptuagintillion seven hundred eighty nine censeptuagintillion two hundred forty six cennovemsexagintillion eight hundred one cenoctosexagintillion three hundred fifty seven censeptensexagintillion');
  50. },
  51. );
  52. it(
  53. 'converts 123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 to one hundred twenty three trecenduoseptuagintillion four hundred fifty six trecenunseptuagintillion seven hundred eighty nine trecenseptuagintillion two hundred forty six trecennovemsexagintillion eight hundred one trecenoctosexagintillion three hundred fifty seven trecenseptensexagintillion',
  54. () => {
  55. expect(stringify(
  56. '123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'))
  57. .toBe(
  58. 'one hundred twenty three trecenduoseptuagintillion four hundred fifty six trecenunseptuagintillion seven hundred eighty nine trecenseptuagintillion two hundred forty six trecennovemsexagintillion eight hundred one trecenoctosexagintillion three hundred fifty seven trecenseptensexagintillion');
  59. },
  60. );
  61. });
  62. describe('Medium size numbers (<= 1e+63)', () => {
  63. describe('Table 1', () => {
  64. it.each`
  65. value | americanName
  66. ${'1e+9'} | ${'billion'}
  67. ${'1e+12'} | ${'trillion'}
  68. ${'1e+15'} | ${'quadrillion'}
  69. ${'1e+18'} | ${'quintillion'}
  70. ${'1e+21'} | ${'sextillion'}
  71. ${'1e+24'} | ${'septillion'}
  72. ${'1e+27'} | ${'octillion'}
  73. ${'1e+30'} | ${'nonillion'}
  74. ${'1e+33'} | ${'decillion'}
  75. ${'1e+36'} | ${'undecillion'}
  76. ${'1e+39'} | ${'duodecillion'}
  77. ${'1e+42'} | ${'tredecillion'}
  78. ${'1e+45'} | ${'quattuordecillion'}
  79. ${'1e+48'} | ${'quindecillion'}
  80. ${'1e+51'} | ${'sexdecillion'}
  81. ${'1e+54'} | ${'septendecillion'}
  82. ${'1e+57'} | ${'octodecillion'}
  83. ${'1e+60'} | ${'novemdecillion'}
  84. ${'1e+63'} | ${'vigintillion'}
  85. `('converts $value to $americanName', ({value, americanName}) => {
  86. expect(stringify(value)).toBe(`one ${americanName}`);
  87. expect(parse(`one ${americanName}`)).toBe(value);
  88. });
  89. });
  90. });
  91. describe('Large size numbers (< 1e+303)', () => {
  92. it.each`
  93. value | americanName
  94. ${'1e+66'} | ${'unvigintillion'}
  95. ${'1e+69'} | ${'duovigintillion'}
  96. ${'1e+72'} | ${'trevigintillion'}
  97. ${'1e+75'} | ${'quattuorvigintillion'}
  98. ${'1e+78'} | ${'quinvigintillion'}
  99. ${'1e+81'} | ${'sexvigintillion'}
  100. ${'1e+84'} | ${'septenvigintillion'}
  101. ${'1e+87'} | ${'octovigintillion'}
  102. ${'1e+90'} | ${'novemvigintillion'}
  103. ${'1e+93'} | ${'trigintillion'}
  104. ${'1e+123'} | ${'quadragintillion'}
  105. ${'1e+150'} | ${'novemquadragintillion'}
  106. ${'1e+153'} | ${'quinquagintillion'}
  107. ${'1e+156'} | ${'unquinquagintillion'}
  108. ${'1e+183'} | ${'sexagintillion'}
  109. ${'1e+213'} | ${'septuagintillion'}
  110. ${'1e+222'} | ${'treseptuagintillion'}
  111. ${'1e+243'} | ${'octogintillion'}
  112. ${'1e+273'} | ${'nonagintillion'}
  113. ${'1e+300'} | ${'novemnonagintillion'}
  114. `('converts $value to $americanName', ({value, americanName}) => {
  115. expect(stringify(value)).toBe(`one ${americanName}`);
  116. expect(parse(`one ${americanName}`)).toBe(value);
  117. });
  118. });
  119. describe('Gigantic size numbers (< 1e+3003)', () => {
  120. it.each`
  121. value | americanName
  122. ${'1e+303'} | ${'centillion'}
  123. ${'1e+306'} | ${'cenuntillion'}
  124. ${'1e+309'} | ${'cenduotillion'}
  125. ${'1e+312'} | ${'centretillion'}
  126. ${'1e+315'} | ${'cenquattuortillion'}
  127. ${'1e+318'} | ${'cenquintillion'}
  128. ${'1e+321'} | ${'censextillion'}
  129. ${'1e+324'} | ${'censeptentillion'}
  130. ${'1e+327'} | ${'cenoctotillion'}
  131. ${'1e+330'} | ${'cennovemtillion'}
  132. ${'1e+603'} | ${'duocentillion'}
  133. ${'1e+903'} | ${'trecentillion'}
  134. ${'1e+1203'} | ${'quadringentillion'}
  135. ${'1e+1503'} | ${'quingentillion'}
  136. ${'1e+1803'} | ${'sescentillion'}
  137. ${'1e+2103'} | ${'septingentillion'}
  138. ${'1e+2403'} | ${'octingentillion'}
  139. ${'1e+2703'} | ${'nongentillion'}
  140. `('converts $value to $americanName', ({value, americanName}) => {
  141. expect(stringify(value)).toBe(`one ${americanName}`);
  142. expect(parse(`one ${americanName}`)).toBe(value);
  143. });
  144. });
  145. describe('Titanic size numbers (< 1e+3000003)', () => {
  146. it(
  147. 'converts 123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 to one hundred twenty three milliaduoseptuagintillion four hundred fifty six milliaunseptuagintillion seven hundred eighty nine milliaseptuagintillion two hundred forty six millianovemsexagintillion eight hundred one milliaoctosexagintillion three hundred fifty seven milliaseptensexagintillion',
  148. () => {
  149. expect(stringify(
  150. '123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'))
  151. .toBe(
  152. 'one hundred twenty three milliaduoseptuagintillion four hundred fifty six milliaunseptuagintillion seven hundred eighty nine milliaseptuagintillion two hundred forty six millianovemsexagintillion eight hundred one milliaoctosexagintillion three hundred fifty seven milliaseptensexagintillion');
  153. },
  154. );
  155. it.each`
  156. value | americanName
  157. ${'1.23456789246801357e+6221'} | ${'one hundred twenty three duomilliaduoseptuagintillion four hundred fifty six duomilliaunseptuagintillion seven hundred eighty nine duomilliaseptuagintillion two hundred forty six duomillianovemsexagintillion eight hundred one duomilliaoctosexagintillion three hundred fifty seven duomilliaseptensexagintillion'}
  158. ${'1.23456789246801357e+2961221'} | ${'one hundred twenty three nongenseptenoctoginmilliaduoseptuagintillion four hundred fifty six nongenseptenoctoginmilliaunseptuagintillion seven hundred eighty nine nongenseptenoctoginmilliaseptuagintillion two hundred forty six nongenseptenoctoginmillianovemsexagintillion eight hundred one nongenseptenoctoginmilliaoctosexagintillion three hundred fifty seven nongenseptenoctoginmilliaseptensexagintillion'}
  159. ${'123.456789246801357e+2961000000219'} | ${'one hundred twenty three nongenseptenoctoginmilliamilliamilliaduoseptuagintillion four hundred fifty six nongenseptenoctoginmilliamilliamilliaunseptuagintillion seven hundred eighty nine nongenseptenoctoginmilliamilliamilliaseptuagintillion two hundred forty six nongenseptenoctoginmilliamilliamillianovemsexagintillion eight hundred one nongenseptenoctoginmilliamilliamilliaoctosexagintillion three hundred fifty seven nongenseptenoctoginmilliamilliamilliaseptensexagintillion'}
  160. ${'1e+3003'} | ${'one milliatillion'}
  161. ${'1e+98025'} | ${'one duotriginmilliasescenquattuorseptuagintillion'}
  162. ${'1e+3000003'} | ${'one milliamilliatillion'}
  163. ${'1e+2570329536'} | ${'one octingensexquinquaginmilliamilliaseptingensexseptuaginmilliaquingenundecillion'}
  164. ${'1e+3000000003'} | ${'one milliamilliamilliatillion'}
  165. ${'1e+1174743648579'} | ${'one trecenunnonaginmilliamilliamilliaquingenunoctoginmilliamilliaduocensexdecmilliacenduononagintillion'}
  166. ${'1e+3000000000003'} | ${'one milliamilliamilliamilliatillion'}
  167. ${'1e+696276510359811'} | ${'one duocenduotriginmilliamilliamilliamilliaduononaginmilliamilliamilliacenseptuaginmilliamilliacennovemdecmillianongensextrigintillion'}
  168. `('converts $value to $americanName', ({value, americanName}) => {
  169. expect(stringify(value)).toBe(americanName);
  170. expect(parse(americanName)).toBe(numberToExponential(value));
  171. });
  172. });
  173. });