import { NumberUtils } from '../../src/utils/NumberUtils'; import { changeFormatCases, formatCases, safeFormatCases, keepOnlyDecimalSeparatorCases, roundTestCases, stringToNumberCases, getValueOrDefaultCases, getValueOrZeroCases, compareCases, } from '../testCases/NumberUtilsTestCases'; describe('NumberUtils', function() { describe('stringToNumber', () => { stringToNumberCases.forEach(e => { it(`should return ${e.valueOutput} when value is ${e.valueInput}`, () => { expect(NumberUtils.stringToNumber(e.valueInput)).toBe(e.valueOutput); }); }); }); describe('format', () => { formatCases.forEach(e => { it(`should return ${e.strvalueOutPut} when: [ value: ${e.strvalue}, precision: ${e.precision}, prettyPrecision: ${e.prettyprecision} ]`, () => { expect(NumberUtils.format(e.strvalue, e.precision, e.prettyprecision)).toBe(e.strvalueOutPut); }); }); }); describe('changeFormat', () => { changeFormatCases.forEach(e => { it(`should return ${e.outPutValue} when value is ${e.inputValue}`, () => { expect(NumberUtils.changeFormat(e.inputValue)).toBe(e.outPutValue); }); }); }); describe('keepOnlyDecimalSeparator', () => { keepOnlyDecimalSeparatorCases.forEach(e => { it(`should return ${e.outPutValue} when: [ value: ${e.inputValue}, formatNumber: ${e.formatnumber} ]`, () => { expect(NumberUtils.keepOnlyDecimalSeparator(e.inputValue, e.formatnumber)).toBe(e.outPutValue); }); }); }); describe('round', () => { roundTestCases.forEach(e => { it(`should return ${e.outPutValue} when: [ value: ${e.inputValue}, decimal: ${e.decimal} ]`, () => { expect(NumberUtils.round(e.inputValue, e.decimal)).toBe(e.outPutValue); }); }); }); describe('safeFormat', () => { safeFormatCases.forEach(e => { it(`should return ${e.strvalueOutPut} when: [ value: ${e.strvalue}, precision: ${e.precision}, prettyPrecision: ${e.prettyprecision} ]`, () => { expect(NumberUtils.safeFormat(e.strvalue, e.precision, e.prettyprecision)).toBe(e.strvalueOutPut); }); }); }); describe('getValueOrDefault', () => { getValueOrDefaultCases.forEach(e => { it(`should return ${e.expected} when value is ${e.value}`, () => { expect(NumberUtils.getValueOrDefault(e.value, e.defaultValue)).toBe(e.expected); }); }); }); describe('getValueOrZero', () => { getValueOrZeroCases.forEach(e => { it(`should return ${e.expected} when value is ${e.value}`, () => { expect(NumberUtils.getValueOrZero(e.value)).toBe(e.expected); }); }); }); describe('compare', () => { compareCases.forEach(({ a, b, expected }) => { it(`should return ${expected} when comparing ${a} and ${b}`, () => { expect(NumberUtils.compare(a, b)).toBe(expected); }); }); }); });