Gets the name of a number, even if it's stupidly big. Supersedes TheoryOfNekomata/number-name.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

127 строки
17 KiB

  1. import getNumberName from '../..';
  2. describe('Landon\'s original test cases', () => {
  3. describe('Basic conversions', () => {
  4. it.each`
  5. value | americanName
  6. ${1} | ${'one'}
  7. ${1000} | ${'one thousand'}
  8. ${1000000} | ${'one million'}
  9. ${1000000000} | ${'one billion'}
  10. ${1000000000000} | ${'one trillion'}
  11. ${1000000000000000} | ${'one quadrillion'}
  12. ${1000000000000000000} | ${'one quintillion'}
  13. `('converts $value to $americanName', ({ value, americanName }) => {
  14. expect(getNumberName(value)).toBe(americanName)
  15. })
  16. it('converts 987654321 to nine hundred eighty seven million six hundred fifty four thousand three hundred twenty one', () => {
  17. expect(getNumberName(987654321)).toBe('nine hundred eighty seven million six hundred fifty four thousand three hundred twenty one')
  18. })
  19. it('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', () => {
  20. expect(getNumberName('123456789246801357')).toBe('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')
  21. })
  22. it('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', () => {
  23. expect(getNumberName('123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')).toBe('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')
  24. })
  25. it('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', () => {
  26. expect(getNumberName('123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')).toBe('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')
  27. })
  28. it('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', () => {
  29. expect(getNumberName('123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')).toBe('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')
  30. })
  31. })
  32. describe('Medium size numbers (<= 1e+63)', () => {
  33. describe('Table 1', () => {
  34. it.each`
  35. value | americanName
  36. ${'1e+9'} | ${'billion'}
  37. ${'1e+12'} | ${'trillion'}
  38. ${'1e+15'} | ${'quadrillion'}
  39. ${'1e+18'} | ${'quintillion'}
  40. ${'1e+21'} | ${'sextillion'}
  41. ${'1e+24'} | ${'septillion'}
  42. ${'1e+27'} | ${'octillion'}
  43. ${'1e+30'} | ${'nonillion'}
  44. ${'1e+33'} | ${'decillion'}
  45. ${'1e+36'} | ${'undecillion'}
  46. ${'1e+39'} | ${'duodecillion'}
  47. ${'1e+42'} | ${'tredecillion'}
  48. ${'1e+45'} | ${'quattuordecillion'}
  49. ${'1e+48'} | ${'quindecillion'}
  50. ${'1e+51'} | ${'sexdecillion'}
  51. ${'1e+54'} | ${'septendecillion'}
  52. ${'1e+57'} | ${'octodecillion'}
  53. ${'1e+60'} | ${'novemdecillion'}
  54. ${'1e+63'} | ${'vigintillion'}
  55. `('converts $value to $americanName', ({ value, americanName }) => {
  56. expect(getNumberName(value)).toBe(`one ${americanName}`)
  57. })
  58. })
  59. })
  60. describe('Large size numbers (< 1e+303)', () => {
  61. it.each`
  62. value | americanName
  63. ${'1e+66'} | ${'unvigintillion'}
  64. ${'1e+69'} | ${'duovigintillion'}
  65. ${'1e+72'} | ${'trevigintillion'}
  66. ${'1e+75'} | ${'quattuorvigintillion'}
  67. ${'1e+78'} | ${'quinvigintillion'}
  68. ${'1e+81'} | ${'sexvigintillion'}
  69. ${'1e+84'} | ${'septenvigintillion'}
  70. ${'1e+87'} | ${'octovigintillion'}
  71. ${'1e+90'} | ${'novemvigintillion'}
  72. ${'1e+93'} | ${'trigintillion'}
  73. ${'1e+123'} | ${'quadragintillion'}
  74. ${'1e+150'} | ${'novemquadragintillion'}
  75. ${'1e+153'} | ${'quinquagintillion'}
  76. ${'1e+156'} | ${'unquinquagintillion'}
  77. ${'1e+183'} | ${'sexagintillion'}
  78. ${'1e+213'} | ${'septuagintillion'}
  79. ${'1e+222'} | ${'treseptuagintillion'}
  80. ${'1e+243'} | ${'octogintillion'}
  81. ${'1e+273'} | ${'nonagintillion'}
  82. ${'1e+300'} | ${'novemnonagintillion'}
  83. `('converts $value to $americanName', ({ value, americanName }) => {
  84. expect(getNumberName(value)).toBe(`one ${americanName}`)
  85. })
  86. })
  87. describe('Gigantic size numbers (< 1e+3003)', () => {
  88. it.each`
  89. value | americanName
  90. ${'1e+303'} | ${'centillion'}
  91. ${'1e+306'} | ${'cenuntillion'}
  92. ${'1e+309'} | ${'cenduotillion'}
  93. ${'1e+312'} | ${'centretillion'}
  94. ${'1e+315'} | ${'cenquattuortillion'}
  95. ${'1e+318'} | ${'cenquintillion'}
  96. ${'1e+321'} | ${'censextillion'}
  97. ${'1e+324'} | ${'censeptentillion'}
  98. ${'1e+327'} | ${'cenoctotillion'}
  99. ${'1e+330'} | ${'cennovemtillion'}
  100. ${'1e+603'} | ${'duocentillion'}
  101. ${'1e+903'} | ${'trecentillion'}
  102. ${'1e+1203'} | ${'quadringentillion'}
  103. ${'1e+1503'} | ${'quingentillion'}
  104. ${'1e+1803'} | ${'sescentillion'}
  105. ${'1e+2103'} | ${'septingentillion'}
  106. ${'1e+2403'} | ${'octingentillion'}
  107. ${'1e+2703'} | ${'nongentillion'}
  108. `('converts $value to $americanName', ({ value, americanName }) => {
  109. expect(getNumberName(value)).toBe(`one ${americanName}`)
  110. })
  111. })
  112. describe('Titanic size numbers (< 1e+3000003', () => {
  113. it('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', () => {
  114. expect(getNumberName('123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')).toBe('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')
  115. })
  116. })
  117. })