fix: _lt, _lte, _gt, _gte not to throw on non numerics.

This commit is contained in:
Gervwyk 2021-01-19 13:02:57 +02:00
parent 41f59a6d17
commit 0bad71d227
8 changed files with 112 additions and 112 deletions

View File

@ -31,13 +31,6 @@ function _gt({ params, location }) {
)} at ${location}.`
);
}
if (!type.isNumber(params[0]) || !type.isNumber(params[1])) {
throw new Error(
`Operator Error: _gt takes an array of 2 numbers. Received: ${JSON.stringify(
params
)} at ${location}.`
);
}
return params[0] > params[1];
}

View File

@ -31,13 +31,6 @@ function _gte({ params, location }) {
)} at ${location}.`
);
}
if (!type.isNumber(params[0]) || !type.isNumber(params[1])) {
throw new Error(
`Operator Error: _gte takes an array of 2 numbers. Received: ${JSON.stringify(
params
)} at ${location}.`
);
}
return params[0] >= params[1];
}

View File

@ -31,13 +31,6 @@ function _lt({ params, location }) {
)} at ${location}.`
);
}
if (!type.isNumber(params[0]) || !type.isNumber(params[1])) {
throw new Error(
`Operator Error: _lt takes an array of 2 numbers. Received: ${JSON.stringify(
params
)} at ${location}.`
);
}
return params[0] < params[1];
}

View File

@ -31,13 +31,6 @@ function _lte({ params, location }) {
)} at ${location}.`
);
}
if (!type.isNumber(params[0]) || !type.isNumber(params[1])) {
throw new Error(
`Operator Error: _lte takes an array of 2 numbers. Received: ${JSON.stringify(
params
)} at ${location}.`
);
}
return params[0] <= params[1];
}

View File

@ -1,43 +1,50 @@
import gt from '../../src/common/gt';
const location = 'locationId';
test('_gt param 0 greater than param 1', () => {
expect(gt({ params: [1, 0], location: 'locationId' })).toBe(true);
expect(gt({ params: [0, -1], location: 'locationId' })).toBe(true);
expect(gt({ params: [1, -1], location: 'locationId' })).toBe(true);
expect(gt({ params: [0.2, 0.1], location: 'locationId' })).toBe(true);
expect(gt({ params: [1, 0], location })).toBe(true);
expect(gt({ params: [0, -1], location })).toBe(true);
expect(gt({ params: [1, -1], location })).toBe(true);
expect(gt({ params: [0.2, 0.1], location })).toBe(true);
expect(gt({ params: [1, null], location })).toBe(true);
expect(gt({ params: [new Date(2), new Date(1)], location })).toBe(true);
expect(gt({ params: [new Date(2), null], location })).toBe(true);
expect(gt({ params: ['bbb', 'bb'], location })).toBe(true);
});
test('_gt param 0 less than param 1', () => {
expect(gt({ params: [1, 1], location: 'locationId' })).toBe(false);
expect(gt({ params: [0, 1], location: 'locationId' })).toBe(false);
expect(gt({ params: [-1, 0], location: 'locationId' })).toBe(false);
expect(gt({ params: [-1, 1], location: 'locationId' })).toBe(false);
expect(gt({ params: [0.1, 0.2], location: 'locationId' })).toBe(false);
expect(gt({ params: [1, 1], location })).toBe(false);
expect(gt({ params: [0, 1], location })).toBe(false);
expect(gt({ params: [-1, 0], location })).toBe(false);
expect(gt({ params: [-1, 1], location })).toBe(false);
expect(gt({ params: [0.1, 0.2], location })).toBe(false);
expect(gt({ params: [null, 1], location })).toBe(false);
expect(gt({ params: [null, null], location })).toBe(false);
expect(gt({ params: [new Date(1), new Date(2)], location })).toBe(false);
expect(gt({ params: [null, new Date(2)], location })).toBe(false);
expect(gt({ params: [false, true], location })).toBe(false);
expect(gt({ params: ['a', 'b'], location })).toBe(false);
expect(gt({ params: ['aa', 'b'], location })).toBe(false);
expect(gt({ params: ['b', 'bb'], location })).toBe(false);
expect(gt({ params: [new Date(1), new Date(1)], location })).toBe(false);
expect(gt({ params: ['b', 'b'], location })).toBe(false);
});
test('_gt params not an array', () => {
expect(() => gt({ params: '1, 0', location: 'locationId' })).toThrow(
expect(() => gt({ params: '1, 0', location })).toThrow(
'Operator Error: _gt takes an array type as input. Received: "1, 0" at locationId.'
);
});
test('_gt params array with length 1', () => {
expect(() => gt({ params: [1], location: 'locationId' })).toThrow(
expect(() => gt({ params: [1], location })).toThrow(
'Operator Error: _gt takes an array of length 2 as input. Received: [1] at locationId.'
);
});
test('_gt params array with length 3', () => {
expect(() => gt({ params: [1, 2, 3], location: 'locationId' })).toThrow(
expect(() => gt({ params: [1, 2, 3], location })).toThrow(
'Operator Error: _gt takes an array of length 2 as input. Received: [1,2,3] at locationId.'
);
});
test('_gt params array with non numbers', () => {
expect(() => gt({ params: ['1', 1], location: 'locationId' })).toThrow(
'Operator Error: _gt takes an array of 2 numbers. Received: ["1",1] at locationId.'
);
expect(() => gt({ params: [1, '1'], location: 'locationId' })).toThrow(
'Operator Error: _gt takes an array of 2 numbers. Received: [1,"1"] at locationId.'
);
});

View File

@ -1,43 +1,50 @@
import gte from '../../src/common/gte';
const location = 'locationId';
test('_gte param 0 greater than param 1', () => {
expect(gte({ params: [1, 1], location: 'locationId' })).toBe(true);
expect(gte({ params: [1, 0], location: 'locationId' })).toBe(true);
expect(gte({ params: [0, -1], location: 'locationId' })).toBe(true);
expect(gte({ params: [1, -1], location: 'locationId' })).toBe(true);
expect(gte({ params: [0.2, 0.1], location: 'locationId' })).toBe(true);
expect(gte({ params: [1, 1], location })).toBe(true);
expect(gte({ params: [1, 0], location })).toBe(true);
expect(gte({ params: [0, -1], location })).toBe(true);
expect(gte({ params: [1, -1], location })).toBe(true);
expect(gte({ params: [0.2, 0.1], location })).toBe(true);
expect(gte({ params: [1, null], location })).toBe(true);
expect(gte({ params: [null, null], location })).toBe(true);
expect(gte({ params: [new Date(2), new Date(1)], location })).toBe(true);
expect(gte({ params: [new Date(2), null], location })).toBe(true);
expect(gte({ params: ['bbb', 'bb'], location })).toBe(true);
expect(gte({ params: ['b', 'b'], location })).toBe(true);
expect(gte({ params: [new Date(1), new Date(1)], location })).toBe(true);
});
test('_gte param 0 less than param 1', () => {
expect(gte({ params: [0, 1], location: 'locationId' })).toBe(false);
expect(gte({ params: [-1, 0], location: 'locationId' })).toBe(false);
expect(gte({ params: [-1, 1], location: 'locationId' })).toBe(false);
expect(gte({ params: [0.1, 0.2], location: 'locationId' })).toBe(false);
expect(gte({ params: [0, 1], location })).toBe(false);
expect(gte({ params: [-1, 0], location })).toBe(false);
expect(gte({ params: [-1, 1], location })).toBe(false);
expect(gte({ params: [0.1, 0.2], location })).toBe(false);
expect(gte({ params: [null, 1], location })).toBe(false);
expect(gte({ params: [new Date(1), new Date(2)], location })).toBe(false);
expect(gte({ params: [null, new Date(2)], location })).toBe(false);
expect(gte({ params: [false, true], location })).toBe(false);
expect(gte({ params: ['a', 'b'], location })).toBe(false);
expect(gte({ params: ['aa', 'b'], location })).toBe(false);
expect(gte({ params: ['b', 'bb'], location })).toBe(false);
});
test('_gte params not an array', () => {
expect(() => gte({ params: '1, 0', location: 'locationId' })).toThrow(
expect(() => gte({ params: '1, 0', location })).toThrow(
'Operator Error: _gte takes an array type as input. Received: "1, 0" at locationId.'
);
});
test('_gte params array with length 1', () => {
expect(() => gte({ params: [1], location: 'locationId' })).toThrow(
expect(() => gte({ params: [1], location })).toThrow(
'Operator Error: _gte takes an array of length 2 as input. Received: [1] at locationId.'
);
});
test('_gte params array with length 3', () => {
expect(() => gte({ params: [1, 2, 3], location: 'locationId' })).toThrow(
expect(() => gte({ params: [1, 2, 3], location })).toThrow(
'Operator Error: _gte takes an array of length 2 as input. Received: [1,2,3] at locationId.'
);
});
test('_gte params array with non numbers', () => {
expect(() => gte({ params: ['1', 1], location: 'locationId' })).toThrow(
'Operator Error: _gte takes an array of 2 numbers. Received: ["1",1] at locationId.'
);
expect(() => gte({ params: [1, '1'], location: 'locationId' })).toThrow(
'Operator Error: _gte takes an array of 2 numbers. Received: [1,"1"] at locationId.'
);
});

View File

@ -1,43 +1,50 @@
import lt from '../../src/common/lt';
const location = 'locationId';
test('_lt param 0 less than param 1', () => {
expect(lt({ params: [0, 1], location: 'locationId' })).toBe(true);
expect(lt({ params: [-1, 0], location: 'locationId' })).toBe(true);
expect(lt({ params: [-1, 1], location: 'locationId' })).toBe(true);
expect(lt({ params: [0.1, 0.2], location: 'locationId' })).toBe(true);
expect(lt({ params: [0, 1], location })).toBe(true);
expect(lt({ params: [-1, 0], location })).toBe(true);
expect(lt({ params: [-1, 1], location })).toBe(true);
expect(lt({ params: [0.1, 0.2], location })).toBe(true);
expect(lt({ params: [null, 1], location })).toBe(true);
expect(lt({ params: [new Date(1), new Date(2)], location })).toBe(true);
expect(lt({ params: [null, new Date(2)], location })).toBe(true);
expect(lt({ params: [false, true], location })).toBe(true);
expect(lt({ params: ['a', 'b'], location })).toBe(true);
expect(lt({ params: ['aa', 'b'], location })).toBe(true);
expect(lt({ params: ['b', 'bb'], location })).toBe(true);
});
test('_lt param 0 greater than param 1', () => {
expect(lt({ params: [1, 1], location: 'locationId' })).toBe(false);
expect(lt({ params: [1, 0], location: 'locationId' })).toBe(false);
expect(lt({ params: [0, -1], location: 'locationId' })).toBe(false);
expect(lt({ params: [1, -1], location: 'locationId' })).toBe(false);
expect(lt({ params: [0.2, 0.1], location: 'locationId' })).toBe(false);
expect(lt({ params: [1, 1], location })).toBe(false);
expect(lt({ params: [1, 0], location })).toBe(false);
expect(lt({ params: [0, -1], location })).toBe(false);
expect(lt({ params: [1, -1], location })).toBe(false);
expect(lt({ params: [0.2, 0.1], location })).toBe(false);
expect(lt({ params: [1, null], location })).toBe(false);
expect(lt({ params: [null, null], location })).toBe(false);
expect(lt({ params: [new Date(2), new Date(1)], location })).toBe(false);
expect(lt({ params: [new Date(2), null], location })).toBe(false);
expect(lt({ params: ['bbb', 'bb'], location })).toBe(false);
expect(lt({ params: ['b', 'b'], location })).toBe(false);
expect(lt({ params: [new Date(1), new Date(1)], location })).toBe(false);
});
test('_lt params not an array', () => {
expect(() => lt({ params: '1, 0', location: 'locationId' })).toThrow(
expect(() => lt({ params: '1, 0', location })).toThrow(
'Operator Error: _lt takes an array type as input. Received: "1, 0" at locationId.'
);
});
test('_lt params array with length 1', () => {
expect(() => lt({ params: [1], location: 'locationId' })).toThrow(
expect(() => lt({ params: [1], location })).toThrow(
'Operator Error: _lt takes an array of length 2 as input. Received: [1] at locationId.'
);
});
test('_lt params array with length 3', () => {
expect(() => lt({ params: [1, 2, 3], location: 'locationId' })).toThrow(
expect(() => lt({ params: [1, 2, 3], location })).toThrow(
'Operator Error: _lt takes an array of length 2 as input. Received: [1,2,3] at locationId.'
);
});
test('_lt params array with non numbers', () => {
expect(() => lt({ params: ['1', 1], location: 'locationId' })).toThrow(
'Operator Error: _lt takes an array of 2 numbers. Received: ["1",1] at locationId.'
);
expect(() => lt({ params: [1, '1'], location: 'locationId' })).toThrow(
'Operator Error: _lt takes an array of 2 numbers. Received: [1,"1"] at locationId.'
);
});

View File

@ -1,43 +1,50 @@
import lte from '../../src/common/lte';
const location = 'locationId';
test('_lte param 0 less than param 1', () => {
expect(lte({ params: [1, 1], location: 'locationId' })).toBe(true);
expect(lte({ params: [0, 1], location: 'locationId' })).toBe(true);
expect(lte({ params: [-1, 0], location: 'locationId' })).toBe(true);
expect(lte({ params: [-1, 1], location: 'locationId' })).toBe(true);
expect(lte({ params: [0.1, 0.2], location: 'locationId' })).toBe(true);
expect(lte({ params: [1, 1], location })).toBe(true);
expect(lte({ params: [0, 1], location })).toBe(true);
expect(lte({ params: [-1, 0], location })).toBe(true);
expect(lte({ params: [-1, 1], location })).toBe(true);
expect(lte({ params: [0.1, 0.2], location })).toBe(true);
expect(lte({ params: [null, 1], location })).toBe(true);
expect(lte({ params: [null, null], location })).toBe(true);
expect(lte({ params: [new Date(1), new Date(2)], location })).toBe(true);
expect(lte({ params: [new Date(1), new Date(1)], location })).toBe(true);
expect(lte({ params: [null, new Date(2)], location })).toBe(true);
expect(lte({ params: [false, true], location })).toBe(true);
expect(lte({ params: ['a', 'b'], location })).toBe(true);
expect(lte({ params: ['aa', 'b'], location })).toBe(true);
expect(lte({ params: ['b', 'bb'], location })).toBe(true);
expect(lte({ params: ['b', 'b'], location })).toBe(true);
});
test('_lte param 0 greater than param 1', () => {
expect(lte({ params: [1, 0], location: 'locationId' })).toBe(false);
expect(lte({ params: [0, -1], location: 'locationId' })).toBe(false);
expect(lte({ params: [1, -1], location: 'locationId' })).toBe(false);
expect(lte({ params: [0.2, 0.1], location: 'locationId' })).toBe(false);
expect(lte({ params: [1, 0], location })).toBe(false);
expect(lte({ params: [0, -1], location })).toBe(false);
expect(lte({ params: [1, -1], location })).toBe(false);
expect(lte({ params: [0.2, 0.1], location })).toBe(false);
expect(lte({ params: [1, null], location })).toBe(false);
expect(lte({ params: [new Date(2), new Date(1)], location })).toBe(false);
expect(lte({ params: [new Date(2), null], location })).toBe(false);
expect(lte({ params: ['bbb', 'bb'], location })).toBe(false);
});
test('_lte params not an array', () => {
expect(() => lte({ params: '1, 0', location: 'locationId' })).toThrow(
expect(() => lte({ params: '1, 0', location })).toThrow(
'Operator Error: _lte takes an array type as input. Received: "1, 0" at locationId.'
);
});
test('_lte params array with length 1', () => {
expect(() => lte({ params: [1], location: 'locationId' })).toThrow(
expect(() => lte({ params: [1], location })).toThrow(
'Operator Error: _lte takes an array of length 2 as input. Received: [1] at locationId.'
);
});
test('_lte params array with length 3', () => {
expect(() => lte({ params: [1, 2, 3], location: 'locationId' })).toThrow(
expect(() => lte({ params: [1, 2, 3], location })).toThrow(
'Operator Error: _lte takes an array of length 2 as input. Received: [1,2,3] at locationId.'
);
});
test('_lte params array with non numbers', () => {
expect(() => lte({ params: ['1', 1], location: 'locationId' })).toThrow(
'Operator Error: _lte takes an array of 2 numbers. Received: ["1",1] at locationId.'
);
expect(() => lte({ params: [1, '1'], location: 'locationId' })).toThrow(
'Operator Error: _lte takes an array of 2 numbers. Received: [1,"1"] at locationId.'
);
});