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.
 
 

45 regels
1.9 KiB

  1. import getNumberName from '../../../index';
  2. describe('Technical numbers', () => {
  3. describe('Number.MAX_SAFE_INTEGER', () => {
  4. it(
  5. 'converts Number.MAX_SAFE_INTEGER to nine quadrillion seven trillion one hundred ninety nine billion two hundred fifty four million seven hundred forty thousand nine hundred ninety one',
  6. () => {
  7. expect(Number.MAX_SAFE_INTEGER).toBe(9_007_199_254_740_991);
  8. expect(getNumberName(Number.MAX_SAFE_INTEGER))
  9. .toBe(
  10. 'nine quadrillion seven trillion one hundred ninety nine billion two hundred fifty four million seven hundred forty thousand nine hundred ninety one');
  11. },
  12. );
  13. });
  14. describe('Powers of 2', () => {
  15. it.each`
  16. value | name
  17. ${2 ** 0} | ${'one'}
  18. ${2 ** 1} | ${'two'}
  19. ${2 ** 2} | ${'four'}
  20. ${2 ** 3} | ${'eight'}
  21. ${2 ** 4} | ${'sixteen'}
  22. ${2 ** 5} | ${'thirty two'}
  23. ${2 ** 6} | ${'sixty four'}
  24. ${2 ** 7} | ${'one hundred twenty eight'}
  25. ${2 ** 8} | ${'two hundred fifty six'}
  26. ${2 ** 9} | ${'five hundred twelve'}
  27. ${2 ** 10} | ${'one thousand twenty four'}
  28. ${2 ** 11} | ${'two thousand forty eight'}
  29. ${2 ** 12} | ${'four thousand ninety six'}
  30. ${2 ** 13} | ${'eight thousand one hundred ninety two'}
  31. ${2 ** 14} | ${'sixteen thousand three hundred eighty four'}
  32. ${2 ** 15} | ${'thirty two thousand seven hundred sixty eight'}
  33. ${2 ** 16} | ${'sixty five thousand five hundred thirty six'}
  34. ${2 ** 17} | ${'one hundred thirty one thousand seventy two'}
  35. ${2 ** 18} | ${'two hundred sixty two thousand one hundred forty four'}
  36. ${2 ** 19} | ${'five hundred twenty four thousand two hundred eighty eight'}
  37. ${2 ** 20} | ${'one million forty eight thousand five hundred seventy six'}
  38. `('converts $value to $name', ({value, name}) => {
  39. expect(getNumberName(value)).toBe(name);
  40. });
  41. });
  42. });