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.
 
 

58 lines
1.5 KiB

  1. import { describe, it, expect } from 'vitest';
  2. import { numberToExponential } from '../src/exponent';
  3. describe('numberToExponential', () => {
  4. it('converts 0 to 0e+0', () => {
  5. expect(numberToExponential(0)).toBe('0e+0');
  6. });
  7. it('converts "0" to 0e+0', () => {
  8. expect(numberToExponential('0')).toBe('0e+0');
  9. });
  10. it('converts "00000000000000000" to 0e+0', () => {
  11. expect(numberToExponential('00000000000000000')).toBe('0e+0');
  12. });
  13. it('converts 1 to 1e+0', () => {
  14. expect(numberToExponential(1)).toBe('1e+0');
  15. });
  16. it('converts "0.1" to 1e-1', () => {
  17. expect(numberToExponential('0.1')).toBe('1e-1');
  18. });
  19. it('converts "0.10" to 1e-1', () => {
  20. expect(numberToExponential('0.10')).toBe('1e-1');
  21. });
  22. it('converts "1" to 1e+0', () => {
  23. expect(numberToExponential('1')).toBe('1e+0');
  24. });
  25. it('converts "10" to 1e+1', () => {
  26. expect(numberToExponential('10')).toBe('1e+1');
  27. });
  28. it('converts "100" to 1e+2', () => {
  29. expect(numberToExponential('100')).toBe('1e+2');
  30. });
  31. it('converts "0100" to 1e+2', () => {
  32. expect(numberToExponential('0100')).toBe('1e+2');
  33. });
  34. it('converts "1234567890" to 1.23456789e+9', () => {
  35. expect(numberToExponential('1234567890')).toBe('1.23456789e+9');
  36. });
  37. it('converts "1234567890.1234567890" to 1.234567890123456789e+9', () => {
  38. expect(numberToExponential('1234567890.1234567890')).toBe('1.234567890123456789e+9');
  39. });
  40. it('converts "1e+100" to 1e+100', () => {
  41. expect(numberToExponential('1e+100')).toBe('1e+100');
  42. });
  43. });