|
- import { describe, it, expect } from 'vitest';
- import { parse, stringify, systems } from '../../src';
- import { numberToExponential } from '../../src/exponent';
-
- const options = { system: systems.enUS };
-
- describe('numerica', () => {
- describe('group names', () => {
- describe('0-9', () => {
- it.each`
- ones | expected
- ${0} | ${'zero'}
- ${1} | ${'one'}
- ${2} | ${'two'}
- ${3} | ${'three'}
- ${4} | ${'four'}
- ${5} | ${'five'}
- ${6} | ${'six'}
- ${7} | ${'seven'}
- ${8} | ${'eight'}
- ${9} | ${'nine'}
- `('converts $ones to $expected', ({ ones, expected }: { ones: number, expected: string }) => {
- expect(stringify(ones, options)).toBe(expected);
- expect(parse(expected, { ...options, type: 'number' })).toBe(ones);
- });
- });
-
- describe('10-19', () => {
- it.each`
- tenPlusOnes | expected
- ${10} | ${'ten'}
- ${11} | ${'eleven'}
- ${12} | ${'twelve'}
- ${13} | ${'thirteen'}
- ${14} | ${'fourteen'}
- ${15} | ${'fifteen'}
- ${16} | ${'sixteen'}
- ${17} | ${'seventeen'}
- ${18} | ${'eighteen'}
- ${19} | ${'nineteen'}
- `('converts $tenPlusOnes to $expected', ({ tenPlusOnes, expected }: { tenPlusOnes: number, expected: string }) => {
- expect(stringify(tenPlusOnes, options)).toBe(expected);
- expect(parse(expected, { ...options, type: 'number' })).toBe(tenPlusOnes);
- });
- });
-
- describe.each`
- tensStart | tensEnd | tensBase
- ${20} | ${29} | ${'twenty'}
- ${30} | ${39} | ${'thirty'}
- ${40} | ${49} | ${'forty'}
- ${50} | ${59} | ${'fifty'}
- ${60} | ${69} | ${'sixty'}
- ${70} | ${79} | ${'seventy'}
- ${80} | ${89} | ${'eighty'}
- ${90} | ${99} | ${'ninety'}
- `('$tensStart-$tensEnd', ({
- tensStart, tensBase,
- }: { tensStart: number, tensBase: string }) => {
- it.each`
- value | expected
- ${tensStart} | ${tensBase}
- ${tensStart + 1} | ${`${tensBase} one`}
- ${tensStart + 2} | ${`${tensBase} two`}
- ${tensStart + 3} | ${`${tensBase} three`}
- ${tensStart + 4} | ${`${tensBase} four`}
- ${tensStart + 5} | ${`${tensBase} five`}
- ${tensStart + 6} | ${`${tensBase} six`}
- ${tensStart + 7} | ${`${tensBase} seven`}
- ${tensStart + 8} | ${`${tensBase} eight`}
- ${tensStart + 9} | ${`${tensBase} nine`}
- `('converts $value to $expected', ({ value, expected }: { value: number, expected: string }) => {
- expect(stringify(value, options)).toBe(expected);
- expect(parse(expected, { ...options, type: 'number' })).toBe(value);
- });
- });
-
- describe.each`
- hundredsStart | hundredsEnd | hundredsBase
- ${100} | ${199} | ${'one hundred'}
- ${200} | ${299} | ${'two hundred'}
- ${300} | ${399} | ${'three hundred'}
- ${400} | ${499} | ${'four hundred'}
- ${500} | ${599} | ${'five hundred'}
- ${600} | ${699} | ${'six hundred'}
- ${700} | ${799} | ${'seven hundred'}
- ${800} | ${899} | ${'eight hundred'}
- ${900} | ${999} | ${'nine hundred'}
- `('$hundredsStart-$hundredsEnd', ({
- hundredsStart, hundredsBase,
- }: { hundredsStart: number, hundredsBase: string }) => {
- describe(`${hundredsStart}-${hundredsStart + 9}`, () => {
- it.each`
- value | expected
- ${hundredsStart} | ${hundredsBase}
- ${hundredsStart + 1} | ${`${hundredsBase} one`}
- ${hundredsStart + 2} | ${`${hundredsBase} two`}
- ${hundredsStart + 3} | ${`${hundredsBase} three`}
- ${hundredsStart + 4} | ${`${hundredsBase} four`}
- ${hundredsStart + 5} | ${`${hundredsBase} five`}
- ${hundredsStart + 6} | ${`${hundredsBase} six`}
- ${hundredsStart + 7} | ${`${hundredsBase} seven`}
- ${hundredsStart + 8} | ${`${hundredsBase} eight`}
- ${hundredsStart + 9} | ${`${hundredsBase} nine`}
- `('converts $value to $expected', ({ value, expected }: { value: number, expected: string }) => {
- expect(stringify(value, options)).toBe(expected);
- expect(parse(expected, { ...options, type: 'number' })).toBe(value);
- });
- });
-
- describe(`${hundredsStart + 10}-${hundredsStart + 19}`, () => {
- it.each`
- value | expected
- ${hundredsStart + 10} | ${`${hundredsBase} ten`}
- ${hundredsStart + 11} | ${`${hundredsBase} eleven`}
- ${hundredsStart + 12} | ${`${hundredsBase} twelve`}
- ${hundredsStart + 13} | ${`${hundredsBase} thirteen`}
- ${hundredsStart + 14} | ${`${hundredsBase} fourteen`}
- ${hundredsStart + 15} | ${`${hundredsBase} fifteen`}
- ${hundredsStart + 16} | ${`${hundredsBase} sixteen`}
- ${hundredsStart + 17} | ${`${hundredsBase} seventeen`}
- ${hundredsStart + 18} | ${`${hundredsBase} eighteen`}
- ${hundredsStart + 19} | ${`${hundredsBase} nineteen`}
- `('converts $value to $expected', ({ value, expected }: { value: number, expected: string }) => {
- expect(stringify(value, options)).toBe(expected);
- expect(parse(expected, { ...options, type: 'number' })).toBe(value);
- });
- });
-
- describe.each`
- start | end | base
- ${20} | ${29} | ${'twenty'}
- ${30} | ${39} | ${'thirty'}
- ${40} | ${49} | ${'forty'}
- ${50} | ${59} | ${'fifty'}
- ${60} | ${69} | ${'sixty'}
- ${70} | ${79} | ${'seventy'}
- ${80} | ${89} | ${'eighty'}
- ${90} | ${99} | ${'ninety'}
- `('$start-$end', ({
- start, base,
- }: { start: number, base: string }) => {
- it.each`
- value | expected
- ${hundredsStart + start} | ${`${hundredsBase} ${base}`}
- ${hundredsStart + start + 1} | ${`${hundredsBase} ${base} one`}
- ${hundredsStart + start + 2} | ${`${hundredsBase} ${base} two`}
- ${hundredsStart + start + 3} | ${`${hundredsBase} ${base} three`}
- ${hundredsStart + start + 4} | ${`${hundredsBase} ${base} four`}
- ${hundredsStart + start + 5} | ${`${hundredsBase} ${base} five`}
- ${hundredsStart + start + 6} | ${`${hundredsBase} ${base} six`}
- ${hundredsStart + start + 7} | ${`${hundredsBase} ${base} seven`}
- ${hundredsStart + start + 8} | ${`${hundredsBase} ${base} eight`}
- ${hundredsStart + start + 9} | ${`${hundredsBase} ${base} nine`}
- `('converts $value to $expected', ({ value, expected }: { value: number, expected: string }) => {
- expect(stringify(value, options)).toBe(expected);
- expect(parse(expected, { ...options, type: 'number' })).toBe(value);
- });
- });
- });
- });
-
- it('converts 1000 to one thousand', () => {
- expect(stringify(1000, options)).toBe('one thousand');
- expect(parse('one thousand', { ...options, type: 'number' })).toBe(1000);
- });
-
- it('converts 10000 to ten thousand', () => {
- expect(stringify(10000, options)).toBe('ten thousand');
- expect(parse('ten thousand', { ...options, type: 'number' })).toBe(10000);
- });
-
- it('converts 100000 to one hundred thousand', () => {
- expect(stringify(100000, options)).toBe('one hundred thousand');
- expect(parse('one hundred thousand', { ...options, type: 'number' })).toBe(100000);
- });
-
- it('converts 123456 to one hundred twenty three thousand four hundred fifty six', () => {
- expect(stringify(123456, options)).toBe('one hundred twenty three thousand four hundred fifty six');
- expect(parse('one hundred twenty three thousand four hundred fifty six', { ...options, type: 'number' })).toBe(123456);
- });
-
- it.each`
- value | expected
- ${1e+6} | ${'one million'}
- ${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'}
- `('converts $value to $expected', ({ value, expected }: { value: number, expected: string }) => {
- expect(stringify(value, options)).toBe(expected);
- expect(parse(expected, { ...options, type: 'number' })).toBe(value);
- });
-
- it.each`
- value | expected
- ${'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'}
- `('converts $value to $expected', ({ value, expected }: { value: string, expected: string }) => {
- expect(stringify(value, options)).toBe(expected);
- expect(parse(expected, options)).toBe(value);
- });
-
- it.each`
- value | expected
- ${'1e+63'} | ${'one vigintillion'}
- ${'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'}
- `('converts $value to $expected', ({ value, expected }: { value: string, expected: string }) => {
- expect(stringify(value, options)).toBe(expected);
- expect(parse(expected, options)).toBe(value);
- });
-
- it.each`
- value | expected
- ${'1e+93'} | ${'one trigintillion'}
- ${'1e+123'} | ${'one quadragintillion'}
- ${'1e+153'} | ${'one quinquagintillion'}
- ${'1e+183'} | ${'one sexagintillion'}
- ${'1e+213'} | ${'one septuagintillion'}
- ${'1e+243'} | ${'one octogintillion'}
- ${'1e+273'} | ${'one nonagintillion'}
- `('converts $value to $expected', ({ value, expected }: { value: string, expected: string }) => {
- expect(stringify(value, options)).toBe(expected);
- expect(parse(expected, options)).toBe(value);
- });
-
- it('converts values', () => {
- const exp1 = numberToExponential('123,456,789,012,345,678,901,234,567,890');
- //
- // one hundred twenty three octillion
- // four hundred fifty six septillion
- // seven hundred eighty nine sextillion
- // twelve quintillion
- // three hundred forty five quadrillion
- // six hundred seventy eight trillion
- // nine hundred one billion
- // two hundred thirty four million
- // five hundred sixty seven thousand
- // eight hundred ninety
- expect(parse(stringify('123456789012345678901234567890'))).toBe(exp1);
-
- const value2 = '1000005000000';
- const exp2 = numberToExponential(value2);
- expect(stringify(value2)).toBe('one trillion five million');
- expect(parse(stringify(value2))).toBe(exp2);
-
- const value3 = '12012';
- const exp3 = numberToExponential(value3);
- expect(stringify(value3)).toBe('twelve thousand twelve');
- expect(parse(stringify(value3))).toBe(exp3);
-
- const value4 = '12020';
- const exp4 = numberToExponential(value4);
- expect(stringify(value4)).toBe('twelve thousand twenty');
- expect(parse(stringify(value4))).toBe(exp4);
- });
- });
|