UNPKG

polish-number-to-words

Version:

Spell numbers using words in Polish | Napisz liczbę słownie po polsku

76 lines (75 loc) 5.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const numberToWords_1 = require("../numberToWords"); describe('numberToWordsPL', () => { it('should handle pure integers correctly', () => { expect((0, numberToWords_1.numberToWordsPL)(0)).toBe('zero'); expect((0, numberToWords_1.numberToWordsPL)(5)).toBe('pięć'); expect((0, numberToWords_1.numberToWordsPL)(123)).toBe('sto dwadzieścia trzy'); expect((0, numberToWords_1.numberToWordsPL)(1001)).toBe('tysiąc jeden'); expect((0, numberToWords_1.numberToWordsPL)(-1000000)).toBe('minus milion'); }); describe('formal fractions (default behavior)', () => { it('should handle positive decimal numbers formally with "i"', () => { expect((0, numberToWords_1.numberToWordsPL)(5.5)).toBe('pięć i pięć dziesiątych'); expect((0, numberToWords_1.numberToWordsPL)(7.25)).toBe('siedem i dwadzieścia pięć setnych'); expect((0, numberToWords_1.numberToWordsPL)(0.125)).toBe('sto dwadzieścia pięć tysięcznych'); }); it('should handle negative decimal numbers formally with "i"', () => { expect((0, numberToWords_1.numberToWordsPL)(-2.5)).toBe('minus dwa i pięć dziesiątych'); expect((0, numberToWords_1.numberToWordsPL)(-0.333)).toBe('minus trzysta trzydzieści trzy tysięczne'); expect((0, numberToWords_1.numberToWordsPL)(-10.01)).toBe('minus dziesięć i jedna setna'); }); }); describe('informal fractions (przecinek mode)', () => { it('should handle informal fractions without "i"', () => { expect((0, numberToWords_1.numberToWordsPL)(5.5, { informalFraction: true })).toBe('pięć przecinek pięć'); expect((0, numberToWords_1.numberToWordsPL)(12.25, { informalFraction: true })).toBe('dwanaście przecinek dwadzieścia pięć'); expect((0, numberToWords_1.numberToWordsPL)(0.75, { informalFraction: true })).toBe('zero przecinek siedemdziesiąt pięć'); }); it('should handle informal fractions with digit-by-digit spelling', () => { expect((0, numberToWords_1.numberToWordsPL)(3.1415, { informalFraction: true })).toBe('trzy przecinek jeden cztery jeden pięć'); expect((0, numberToWords_1.numberToWordsPL)(0.56789, { informalFraction: true })).toBe('zero przecinek pięć sześć siedem osiem dziewięć'); }); it('should apply custom informal digit threshold', () => { expect((0, numberToWords_1.numberToWordsPL)(2.3456, { informalFraction: true, informalFractionFormIndividualNumberThreshold: 5, })).toBe('dwa przecinek trzy tysiące czterysta pięćdziesiąt sześć'); expect((0, numberToWords_1.numberToWordsPL)(2.34567, { informalFraction: true, informalFractionFormIndividualNumberThreshold: 5, })).toBe('dwa przecinek trzy cztery pięć sześć siedem'); }); }); describe('single word special cases (pół, półtorej, ćwierć)', () => { it('should handle single word fractions when enabled', () => { expect((0, numberToWords_1.numberToWordsPL)(0.5, { informalFraction: true, useSingleWordFractions: true })).toBe('pół'); expect((0, numberToWords_1.numberToWordsPL)(1.5, { informalFraction: true, useSingleWordFractions: true })).toBe('półtorej'); expect((0, numberToWords_1.numberToWordsPL)(0.25, { informalFraction: true, useSingleWordFractions: true })).toBe('ćwierć'); }); it('should not apply single word special cases when disabled', () => { expect((0, numberToWords_1.numberToWordsPL)(0.5, { informalFraction: true, useSingleWordFractions: false })).toBe('zero przecinek pięć'); expect((0, numberToWords_1.numberToWordsPL)(1.5, { informalFraction: true, useSingleWordFractions: false })).toBe('jeden przecinek pięć'); expect((0, numberToWords_1.numberToWordsPL)(0.25, { informalFraction: true, useSingleWordFractions: false })).toBe('zero przecinek dwadzieścia pięć'); }); it('should correctly add minus for negative special cases', () => { expect((0, numberToWords_1.numberToWordsPL)(-0.5, { informalFraction: true, useSingleWordFractions: true })).toBe('minus pół'); expect((0, numberToWords_1.numberToWordsPL)(-1.5, { informalFraction: true, useSingleWordFractions: true })).toBe('minus półtorej'); }); it('should handle non-special fractions in a standard way', () => { expect((0, numberToWords_1.numberToWordsPL)(3.1415, { informalFraction: true })).toBe('trzy przecinek jeden cztery jeden pięć'); expect((0, numberToWords_1.numberToWordsPL)(0.56789, { informalFraction: true })).toBe('zero przecinek pięć sześć siedem osiem dziewięć'); }); }); describe('simplifyFraction option', () => { it('should spell fraction exactly when simplifyFraction is false (default)', () => { expect((0, numberToWords_1.numberToWordsPL)(0.5, { informalFraction: false, simplifyFraction: false })).toBe('pięć dziesiątych'); expect((0, numberToWords_1.numberToWordsPL)(2.25, { informalFraction: false, simplifyFraction: false })).toBe('dwa i dwadzieścia pięć setnych'); }); it('should simplify fraction when simplifyFraction is true', () => { expect((0, numberToWords_1.numberToWordsPL)(0.5, { informalFraction: false, simplifyFraction: true })).toBe('jedna druga'); expect((0, numberToWords_1.numberToWordsPL)(2.25, { informalFraction: false, simplifyFraction: true })).toBe('dwa i jedna czwarta'); }); }); });