|
- import { describe, it, expect } from 'vitest';
- import { stringify, parse } from '../src';
- import { numberToExponential } from '../src/exponent';
-
- const stringifyOptions = {
- stringifyGroupsOptions: {
- addTensDashes: false,
- },
- };
-
- describe('Landon\'s original test cases', () => {
- describe('Basic conversions', () => {
- it.each`
- value | numberName
- ${'1e+0'} | ${'one'}
- ${'1e+3'} | ${'one thousand'}
- ${'1e+6'} | ${'one million'}
- ${'1e+9'} | ${'one billion'}
- ${'1e+12'} | ${'one trillion'}
- ${'1e+15'} | ${'one quadrillion'}
- ${'1e+18'} | ${'one quintillion'}
- `('converts $value to $numberName', ({ value, numberName }: { value: number, numberName: string }) => {
- expect(stringify(value, stringifyOptions)).toBe(numberName);
- expect(parse(numberName)).toBe(value);
- });
-
- it(
- 'converts 987654321 to nine hundred eighty seven million six hundred fifty four thousand three hundred twenty one',
- () => {
- expect(stringify(987654321, stringifyOptions))
- .toBe('nine hundred eighty seven million six hundred fifty four thousand three hundred twenty one');
- },
- );
-
- 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',
- () => {
- expect(stringify('123456789246801357', stringifyOptions))
- .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',
- );
- },
- );
-
- 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',
- () => {
- expect(stringify(
- '123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
- stringifyOptions,
- ))
- .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',
- );
- },
- );
-
- 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',
- () => {
- expect(stringify(
- '123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
- stringifyOptions,
- ))
- .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',
- );
- },
- );
-
- 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',
- () => {
- expect(stringify(
- '123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
- stringifyOptions,
- ))
- .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',
- );
- },
- );
- });
-
- describe('Medium size numbers (<= 1e+63)', () => {
- describe('Table 1', () => {
- it.each`
- value | numberName
- ${'1e+9'} | ${'one billion'}
- ${'1e+12'} | ${'one trillion'}
- ${'1e+15'} | ${'one quadrillion'}
- ${'1e+18'} | ${'one quintillion'}
- ${'1e+21'} | ${'one sextillion'}
- ${'1e+24'} | ${'one septillion'}
- ${'1e+27'} | ${'one octillion'}
- ${'1e+30'} | ${'one nonillion'}
- ${'1e+33'} | ${'one decillion'}
- ${'1e+36'} | ${'one undecillion'}
- ${'1e+39'} | ${'one duodecillion'}
- ${'1e+42'} | ${'one tredecillion'}
- ${'1e+45'} | ${'one quattuordecillion'}
- ${'1e+48'} | ${'one quindecillion'}
- ${'1e+51'} | ${'one sexdecillion'}
- ${'1e+54'} | ${'one septendecillion'}
- ${'1e+57'} | ${'one octodecillion'}
- ${'1e+60'} | ${'one novemdecillion'}
- ${'1e+63'} | ${'one vigintillion'}
- `('converts $value to $numberName', ({ value, numberName }: { value: string, numberName: string }) => {
- expect(stringify(value, stringifyOptions)).toBe(numberName);
- expect(parse(numberName)).toBe(value);
- });
- });
- });
-
- describe('Large size numbers (< 1e+303)', () => {
- it.each`
- value | numberName
- ${'1e+66'} | ${'one unvigintillion'}
- ${'1e+69'} | ${'one duovigintillion'}
- ${'1e+72'} | ${'one trevigintillion'}
- ${'1e+75'} | ${'one quattuorvigintillion'}
- ${'1e+78'} | ${'one quinvigintillion'}
- ${'1e+81'} | ${'one sexvigintillion'}
- ${'1e+84'} | ${'one septenvigintillion'}
- ${'1e+87'} | ${'one octovigintillion'}
- ${'1e+90'} | ${'one novemvigintillion'}
- ${'1e+93'} | ${'one trigintillion'}
- ${'1e+123'} | ${'one quadragintillion'}
- ${'1e+150'} | ${'one novemquadragintillion'}
- ${'1e+153'} | ${'one quinquagintillion'}
- ${'1e+156'} | ${'one unquinquagintillion'}
- ${'1e+183'} | ${'one sexagintillion'}
- ${'1e+213'} | ${'one septuagintillion'}
- ${'1e+222'} | ${'one treseptuagintillion'}
- ${'1e+243'} | ${'one octogintillion'}
- ${'1e+273'} | ${'one nonagintillion'}
- ${'1e+300'} | ${'one novemnonagintillion'}
- `('converts $value to $numberName', ({ value, numberName }: { value: string, numberName: string }) => {
- expect(stringify(value, stringifyOptions)).toBe(numberName);
- expect(parse(numberName)).toBe(value);
- });
- });
-
- describe('Gigantic size numbers (< 1e+3003)', () => {
- it.each`
- value | numberName
- ${'1e+303'} | ${'one centillion'}
- ${'1e+306'} | ${'one cenuntillion'}
- ${'1e+309'} | ${'one cenduotillion'}
- ${'1e+312'} | ${'one centretillion'}
- ${'1e+315'} | ${'one cenquattuortillion'}
- ${'1e+318'} | ${'one cenquintillion'}
- ${'1e+321'} | ${'one censextillion'}
- ${'1e+324'} | ${'one censeptentillion'}
- ${'1e+327'} | ${'one cenoctotillion'}
- ${'1e+330'} | ${'one cennovemtillion'}
- ${'1e+603'} | ${'one duocentillion'}
- ${'1e+903'} | ${'one trecentillion'}
- ${'1e+1203'} | ${'one quadringentillion'}
- ${'1e+1503'} | ${'one quingentillion'}
- ${'1e+1803'} | ${'one sescentillion'}
- ${'1e+2103'} | ${'one septingentillion'}
- ${'1e+2403'} | ${'one octingentillion'}
- ${'1e+2703'} | ${'one nongentillion'}
- `('converts $value to $numberName', ({ value, numberName }: { value: string, numberName: string }) => {
- expect(stringify(value, stringifyOptions)).toBe(numberName);
- expect(parse(numberName)).toBe(value);
- });
- });
-
- describe('Titanic size numbers (< 1e+3000003)', () => {
- 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',
- () => {
- expect(stringify(
- '123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
- stringifyOptions,
- ))
- .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',
- );
- },
- );
-
- it.each`
- value | numberName
- ${'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'}
- ${'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'}
- ${'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'}
- ${'1e+3003'} | ${'one milliatillion'}
- ${'1e+98025'} | ${'one duotriginmilliasescenquattuorseptuagintillion'}
- ${'1e+3000003'} | ${'one milliamilliatillion'}
- ${'1e+2570329536'} | ${'one octingensexquinquaginmilliamilliaseptingensexseptuaginmilliaquingenundecillion'}
- ${'1e+3000000003'} | ${'one milliamilliamilliatillion'}
- ${'1e+1174743648579'} | ${'one trecenunnonaginmilliamilliamilliaquingenunoctoginmilliamilliaduocensexdecmilliacenduononagintillion'}
- ${'1e+3000000000003'} | ${'one milliamilliamilliamilliatillion'}
- ${'1e+696276510359811'} | ${'one duocenduotriginmilliamilliamilliamilliaduononaginmilliamilliamilliacenseptuaginmilliamilliacennovemdecmillianongensextrigintillion'}
- `('converts $value to $numberName', ({ value, numberName }: { value: string, numberName: string }) => {
- expect(stringify(value, stringifyOptions)).toBe(numberName);
- expect(parse(numberName)).toBe(numberToExponential(value));
- });
- });
- });
|