import { describe, it, expect } from 'vitest'; import {parse, stringify, systems} from '../../src'; 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 }) => { 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 }) => { 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, }) => { it.each` value | expected ${tensStart + 0} | ${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 }) => { 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, }) => { describe(`${hundredsStart}-${hundredsStart + 9}`, () => { it.each` value | expected ${hundredsStart + 0} | ${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 }) => { 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 }) => { 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, }) => { it.each` value | expected ${hundredsStart + start + 0} | ${`${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 }) => { 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 }) => { 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 }) => { 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 }) => { 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 }) => { expect(stringify(value, options)).toBe(expected); expect(parse(expected, options)).toBe(value); }); });