Skip to content

Commit

Permalink
update errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobar79 committed May 28, 2024
1 parent cdc3da1 commit dd2c893
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
22 changes: 11 additions & 11 deletions src/__swaps__/safe-math/SafeMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand All @@ -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';
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
46 changes: 23 additions & 23 deletions src/__swaps__/safe-math/__tests__/SafeMath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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}`);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit dd2c893

Please sign in to comment.