From dd2c89317129a8576519d672051458e50a8f509d Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Tue, 28 May 2024 14:32:23 -0400 Subject: [PATCH] update errors --- src/__swaps__/safe-math/SafeMath.ts | 22 ++++----- .../safe-math/__tests__/SafeMath.test.ts | 46 +++++++++---------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/__swaps__/safe-math/SafeMath.ts b/src/__swaps__/safe-math/SafeMath.ts index e6a2c686bba..4d0eb500112 100644 --- a/src/__swaps__/safe-math/SafeMath.ts +++ b/src/__swaps__/safe-math/SafeMath.ts @@ -53,7 +53,7 @@ export function sumWorklet(num1: string | number, num2: string | number): string const num2Str = toStringWorklet(num2); if (!isNumberStringWorklet(num1Str) || !isNumberStringWorklet(num2Str)) { - throw new Error('Arguments must be a numeric string'); + throw new Error('Arguments must be a numeric string or number'); } if (isZeroWorklet(num1Str)) { return num2Str; @@ -77,7 +77,7 @@ export function subWorklet(num1: string | number, num2: string | number): string const num2Str = toStringWorklet(num2); if (!isNumberStringWorklet(num1Str) || !isNumberStringWorklet(num2Str)) { - throw new Error('Arguments must be a numeric string'); + throw new Error('Arguments must be a numeric string or number'); } if (isZeroWorklet(num2Str)) { @@ -99,7 +99,7 @@ export function mulWorklet(num1: string | number, num2: string | number): string const num2Str = toStringWorklet(num2); if (!isNumberStringWorklet(num1Str) || !isNumberStringWorklet(num2Str)) { - throw new Error('Arguments must be a numeric string'); + throw new Error('Arguments must be a numeric string or number'); } if (isZeroWorklet(num1Str) || isZeroWorklet(num2Str)) { return '0'; @@ -119,7 +119,7 @@ export function divWorklet(num1: string | number, num2: string | number): string const num2Str = toStringWorklet(num2); if (!isNumberStringWorklet(num1Str) || !isNumberStringWorklet(num2Str)) { - throw new Error('Arguments must be a numeric string'); + throw new Error('Arguments must be a numeric string or number'); } if (isZeroWorklet(num2Str)) { throw new Error('Division by zero'); @@ -142,7 +142,7 @@ export function modWorklet(num1: string | number, num2: string | number): string const num2Str = toStringWorklet(num2); if (!isNumberStringWorklet(num1Str) || !isNumberStringWorklet(num2Str)) { - throw new Error('Arguments must be a numeric string'); + throw new Error('Arguments must be a numeric string or number'); } if (isZeroWorklet(num2Str)) { throw new Error('Division by zero'); @@ -165,7 +165,7 @@ export function powWorklet(base: string | number, exponent: string | number): st const exponentStr = toStringWorklet(exponent); if (!isNumberStringWorklet(baseStr) || !isNumberStringWorklet(exponentStr)) { - throw new Error('Arguments must be a numeric string'); + throw new Error('Arguments must be a numeric string or number'); } if (isZeroWorklet(baseStr)) { return '0'; @@ -205,7 +205,7 @@ export function equalWorklet(num1: string | number, num2: string | number): bool const num2Str = toStringWorklet(num2); if (!isNumberStringWorklet(num1Str) || !isNumberStringWorklet(num2Str)) { - throw new Error('Arguments must be a numeric string'); + throw new Error('Arguments must be a numeric string or number'); } const [bigInt1, decimalPlaces1] = removeDecimalWorklet(num1Str); const [bigInt2, decimalPlaces2] = removeDecimalWorklet(num2Str); @@ -221,7 +221,7 @@ export function greaterThanWorklet(num1: string | number, num2: string | number) const num2Str = toStringWorklet(num2); if (!isNumberStringWorklet(num1Str) || !isNumberStringWorklet(num2Str)) { - throw new Error('Arguments must be a numeric string'); + throw new Error('Arguments must be a numeric string or number'); } const [bigInt1, decimalPlaces1] = removeDecimalWorklet(num1Str); const [bigInt2, decimalPlaces2] = removeDecimalWorklet(num2Str); @@ -237,7 +237,7 @@ export function greaterThanOrEqualToWorklet(num1: string | number, num2: string const num2Str = toStringWorklet(num2); if (!isNumberStringWorklet(num1Str) || !isNumberStringWorklet(num2Str)) { - throw new Error('Arguments must be a numeric string'); + throw new Error('Arguments must be a numeric string or number'); } const [bigInt1, decimalPlaces1] = removeDecimalWorklet(num1Str); const [bigInt2, decimalPlaces2] = removeDecimalWorklet(num2Str); @@ -253,7 +253,7 @@ export function lessThanWorklet(num1: string | number, num2: string | number): b const num2Str = toStringWorklet(num2); if (!isNumberStringWorklet(num1Str) || !isNumberStringWorklet(num2Str)) { - throw new Error('Arguments must be a numeric string'); + throw new Error('Arguments must be a numeric string or number'); } const [bigInt1, decimalPlaces1] = removeDecimalWorklet(num1Str); const [bigInt2, decimalPlaces2] = removeDecimalWorklet(num2Str); @@ -269,7 +269,7 @@ export function lessThanOrEqualToWorklet(num1: string | number, num2: string | n const num2Str = toStringWorklet(num2); if (!isNumberStringWorklet(num1Str) || !isNumberStringWorklet(num2Str)) { - throw new Error('Arguments must be a numeric string'); + throw new Error('Arguments must be a numeric string or number'); } const [bigInt1, decimalPlaces1] = removeDecimalWorklet(num1Str); const [bigInt2, decimalPlaces2] = removeDecimalWorklet(num2Str); diff --git a/src/__swaps__/safe-math/__tests__/SafeMath.test.ts b/src/__swaps__/safe-math/__tests__/SafeMath.test.ts index fe279cccf42..2db42ca5f90 100644 --- a/src/__swaps__/safe-math/__tests__/SafeMath.test.ts +++ b/src/__swaps__/safe-math/__tests__/SafeMath.test.ts @@ -42,8 +42,8 @@ const NON_NUMERIC_STRING = 'abc'; describe('SafeMath', () => { test('sumWorklet', () => { - expect(() => sumWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string'); - expect(() => sumWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string'); + expect(() => sumWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string or number'); + expect(() => sumWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string or number'); expect(sumWorklet(ZERO, ZERO)).toBe(ZERO); expect(sumWorklet(VALUE_A, ZERO)).toBe(VALUE_A); expect(sumWorklet(ZERO, VALUE_B)).toBe(VALUE_B); @@ -53,8 +53,8 @@ describe('SafeMath', () => { }); test('subWorklet', () => { - expect(() => subWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string'); - expect(() => subWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string'); + expect(() => subWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string or number'); + expect(() => subWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string or number'); expect(subWorklet(ZERO, ZERO)).toBe(ZERO); expect(subWorklet(VALUE_A, ZERO)).toBe(VALUE_A); expect(subWorklet(ZERO, VALUE_B)).toBe(`-${VALUE_B}`); @@ -65,8 +65,8 @@ describe('SafeMath', () => { }); test('mulWorklet', () => { - expect(() => mulWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string'); - expect(() => mulWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string'); + expect(() => mulWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string or number'); + expect(() => mulWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string or number'); expect(mulWorklet(ZERO, ZERO)).toBe(ZERO); expect(mulWorklet(VALUE_A, ZERO)).toBe(ZERO); expect(mulWorklet(ZERO, VALUE_B)).toBe(ZERO); @@ -76,8 +76,8 @@ describe('SafeMath', () => { }); test('divWorklet', () => { - expect(() => divWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string'); - expect(() => divWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string'); + expect(() => divWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string or number'); + expect(() => divWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string or number'); expect(() => divWorklet(ZERO, ZERO)).toThrow('Division by zero'); expect(() => divWorklet(VALUE_A, ZERO)).toThrow('Division by zero'); expect(divWorklet(ZERO, VALUE_B)).toBe(ZERO); @@ -87,8 +87,8 @@ describe('SafeMath', () => { }); test('modWorklet', () => { - expect(() => modWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string'); - expect(() => modWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string'); + expect(() => modWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string or number'); + expect(() => modWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string or number'); expect(() => modWorklet(ZERO, ZERO)).toThrow('Division by zero'); expect(() => modWorklet(VALUE_A, ZERO)).toThrow('Division by zero'); expect(modWorklet(ZERO, VALUE_B)).toBe(ZERO); @@ -98,8 +98,8 @@ describe('SafeMath', () => { }); test('powWorklet', () => { - expect(() => powWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string'); - expect(() => powWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string'); + expect(() => powWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string or number'); + expect(() => powWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string or number'); expect(powWorklet(ZERO, VALUE_B)).toBe(ZERO); expect(powWorklet(VALUE_A, ZERO)).toBe(ONE); expect(powWorklet(VALUE_A, VALUE_C)).toBe(RESULTS.pow); @@ -108,15 +108,15 @@ describe('SafeMath', () => { }); test('log10Worklet', () => { - expect(() => log10Worklet(NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string'); + expect(() => log10Worklet(NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string or number'); expect(() => log10Worklet(ZERO)).toThrow('Argument must be greater than 0'); expect(log10Worklet(VALUE_C)).toBe(RESULTS.log10); expect(log10Worklet(Number(VALUE_C))).toBe(RESULTS.log10); }); test('equalWorklet', () => { - expect(() => equalWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string'); - expect(() => equalWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string'); + expect(() => equalWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string or number'); + expect(() => equalWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string or number'); expect(equalWorklet(ZERO, ZERO)).toBe(true); expect(equalWorklet(VALUE_A, VALUE_A)).toBe(true); expect(equalWorklet(VALUE_A, VALUE_B)).toBe(false); @@ -126,8 +126,8 @@ describe('SafeMath', () => { }); test('greaterThanWorklet', () => { - expect(() => greaterThanWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string'); - expect(() => greaterThanWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string'); + expect(() => greaterThanWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string or number'); + expect(() => greaterThanWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string or number'); expect(greaterThanWorklet(VALUE_A, VALUE_B)).toBe(true); expect(greaterThanWorklet(VALUE_B, VALUE_A)).toBe(false); expect(greaterThanWorklet(VALUE_A, VALUE_A)).toBe(false); @@ -137,8 +137,8 @@ describe('SafeMath', () => { }); test('greaterThanOrEqualToWorklet', () => { - expect(() => greaterThanOrEqualToWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string'); - expect(() => greaterThanOrEqualToWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string'); + expect(() => greaterThanOrEqualToWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string or number'); + expect(() => greaterThanOrEqualToWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string or number'); expect(greaterThanOrEqualToWorklet(VALUE_A, VALUE_B)).toBe(true); expect(greaterThanOrEqualToWorklet(VALUE_B, VALUE_A)).toBe(false); expect(greaterThanOrEqualToWorklet(VALUE_A, VALUE_A)).toBe(true); @@ -148,8 +148,8 @@ describe('SafeMath', () => { }); test('lessThanWorklet', () => { - expect(() => lessThanWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string'); - expect(() => lessThanWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string'); + expect(() => lessThanWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string or number'); + expect(() => lessThanWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string or number'); expect(lessThanWorklet(VALUE_A, VALUE_B)).toBe(false); expect(lessThanWorklet(VALUE_B, VALUE_A)).toBe(true); expect(lessThanWorklet(VALUE_A, VALUE_A)).toBe(false); @@ -159,8 +159,8 @@ describe('SafeMath', () => { }); test('lessThanOrEqualToWorklet', () => { - expect(() => lessThanOrEqualToWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string'); - expect(() => lessThanOrEqualToWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string'); + expect(() => lessThanOrEqualToWorklet(NON_NUMERIC_STRING, VALUE_B)).toThrow('Arguments must be a numeric string or number'); + expect(() => lessThanOrEqualToWorklet(VALUE_A, NON_NUMERIC_STRING)).toThrow('Arguments must be a numeric string or number'); expect(lessThanOrEqualToWorklet(VALUE_A, VALUE_B)).toBe(false); expect(lessThanOrEqualToWorklet(VALUE_B, VALUE_A)).toBe(true); expect(lessThanOrEqualToWorklet(VALUE_A, VALUE_A)).toBe(true);