diff --git a/lib/function/bitwise/bitAnd.js b/lib/function/bitwise/bitAnd.js index d929d7da8..14bf0d6a8 100644 --- a/lib/function/bitwise/bitAnd.js +++ b/lib/function/bitwise/bitAnd.js @@ -11,7 +11,6 @@ module.exports = function (math, config) { isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger, isNumber = util.number.isNumber, - isString = util.string.isString, isCollection = collection.isCollection, bigBitAnd = util.bignumber.and; @@ -34,8 +33,8 @@ module.exports = function (math, config) { * * bitNot, bitOr, bitXor, leftShift, rightArithShift, rightLogShift * - * @param {Number | BigNumber | Boolean | String | Array | Matrix | null} x First value to and - * @param {Number | BigNumber | Boolean | String | Array | Matrix | null} y Second value to and + * @param {Number | BigNumber | Boolean | Array | Matrix | null} x First value to and + * @param {Number | BigNumber | Boolean | Array | Matrix | null} y Second value to and * @return {Number | BigNumber | Array | Matrix} AND of `x` and `y` */ math.bitAnd = function bitAnd(x, y) { @@ -55,17 +54,6 @@ module.exports = function (math, config) { return collection.deepMap2(x, y, bitAnd); } - if (isString(x)) { - return bitAnd((config.number === 'bignumber') - ? BigNumber.convert(x) - : +x, y); - } - if (isString(y)) { - return bitAnd(x, (config.number === 'bignumber') - ? BigNumber.convert(y) - : +y); - } - if (isBoolean(x) || x === null) { return bitAnd(+x, y); } diff --git a/lib/function/bitwise/bitNot.js b/lib/function/bitwise/bitNot.js index ca9e31489..e7480ad63 100644 --- a/lib/function/bitwise/bitNot.js +++ b/lib/function/bitwise/bitNot.js @@ -11,7 +11,6 @@ module.exports = function (math, config) { isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger, isNumber = util.number.isNumber, - isString = util.string.isString, isCollection = collection.isCollection, bigBitNot = util.bignumber.not; @@ -35,7 +34,7 @@ module.exports = function (math, config) { * * bitAnd, bitOr, bitXor, leftShift, rightArithShift, rightLogShift * - * @param {Number | BigNumber | Boolean | String | Array | Matrix | null} x Value to not + * @param {Number | BigNumber | Boolean | Array | Matrix | null} x Value to not * @return {Number | BigNumber | Array | Matrix} NOT of `x` */ math.bitNot = function bitNot(x) { @@ -59,12 +58,6 @@ module.exports = function (math, config) { return collection.deepMap(x, bitNot); } - if (isString(x)) { - return bitNot((config.number === 'bignumber') - ? BigNumber.convert(x) - : +x); - } - if (isBoolean(x) || x === null) { return bitNot(+x); } diff --git a/lib/function/bitwise/bitOr.js b/lib/function/bitwise/bitOr.js index bceb40cee..4e2e282a1 100644 --- a/lib/function/bitwise/bitOr.js +++ b/lib/function/bitwise/bitOr.js @@ -11,7 +11,6 @@ module.exports = function (math, config) { isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger, isNumber = util.number.isNumber, - isString = util.string.isString, isCollection = collection.isCollection, bigBitOr = util.bignumber.or; @@ -35,8 +34,8 @@ module.exports = function (math, config) { * * bitAnd, bitNot, bitXor, leftShift, rightArithShift, rightLogShift * - * @param {Number | BigNumber | Boolean | String | Array | Matrix | null} x First value to or - * @param {Number | BigNumber | Boolean | String | Array | Matrix | null} y Second value to or + * @param {Number | BigNumber | Boolean | Array | Matrix | null} x First value to or + * @param {Number | BigNumber | Boolean | Array | Matrix | null} y Second value to or * @return {Number | BigNumber | Array | Matrix} OR of `x` and `y` */ math.bitOr = function bitOr(x, y) { @@ -56,17 +55,6 @@ module.exports = function (math, config) { return collection.deepMap2(x, y, bitOr); } - if (isString(x)) { - return bitOr((config.number === 'bignumber') - ? BigNumber.convert(x) - : +x, y); - } - if (isString(y)) { - return bitOr(x, (config.number === 'bignumber') - ? BigNumber.convert(y) - : +y); - } - if (isBoolean(x) || x === null) { return bitOr(+x, y); } diff --git a/lib/function/bitwise/bitXor.js b/lib/function/bitwise/bitXor.js index 23968fa60..63d66ac1a 100644 --- a/lib/function/bitwise/bitXor.js +++ b/lib/function/bitwise/bitXor.js @@ -11,8 +11,6 @@ module.exports = function (math, config) { isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger, isNumber = util.number.isNumber, - isString = util.string.isString, - isUnit = Unit.isUnit, isCollection = collection.isCollection, bigBitXor = util.bignumber.xor; @@ -35,8 +33,8 @@ module.exports = function (math, config) { * * bitAnd, bitNot, bitOr, leftShift, rightArithShift, rightLogShift * - * @param {Number | BigNumber | Boolean | String | Array | Matrix | null} x First value to xor - * @param {Number | BigNumber | Boolean | String | Array | Matrix | null} y Second value to xor + * @param {Number | BigNumber | Boolean | Array | Matrix | null} x First value to xor + * @param {Number | BigNumber | Boolean | Array | Matrix | null} y Second value to xor * @return {Number | BigNumber | Array | Matrix} XOR of `x` and `y` */ math.bitXor = function bitXor(x, y) { @@ -56,17 +54,6 @@ module.exports = function (math, config) { return collection.deepMap2(x, y, bitXor); } - if (isString(x)) { - return bitXor((config.number === 'bignumber') - ? BigNumber.convert(x) - : +x, y); - } - if (isString(y)) { - return bitXor(x, (config.number === 'bignumber') - ? BigNumber.convert(y) - : +y); - } - if (isBoolean(x) || x === null) { return bitXor(+x, y); } diff --git a/lib/function/bitwise/leftShift.js b/lib/function/bitwise/leftShift.js index 8dea82021..44b50f614 100644 --- a/lib/function/bitwise/leftShift.js +++ b/lib/function/bitwise/leftShift.js @@ -11,7 +11,6 @@ module.exports = function (math, config) { isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger, isNumber = util.number.isNumber, - isString = util.string.isString, isCollection = collection.isCollection, bigLeftShift = util.bignumber.leftShift; @@ -35,8 +34,8 @@ module.exports = function (math, config) { * * bitAnd, bitNot, bitOr, bitXor, rightArithShift, rightLogShift * - * @param {Number | BigNumber | Boolean | String | Array | Matrix | null} x Value to be shifted - * @param {Number | BigNumber | Boolean | String | null} y Amount of shifts + * @param {Number | BigNumber | Boolean | Array | Matrix | null} x Value to be shifted + * @param {Number | BigNumber | Boolean | null} y Amount of shifts * @return {Number | BigNumber | Array | Matrix} `x` shifted left `y` times */ math.leftShift = function leftShift(x, y) { @@ -92,17 +91,6 @@ module.exports = function (math, config) { return collection.deepMap2(x, y, leftShift); } - if (isString(x)) { - return leftShift((config.number === 'bignumber') - ? BigNumber.convert(x) - : +x, y); - } - if (isString(y)) { - return leftShift(x, (config.number === 'bignumber') - ? BigNumber.convert(y) - : +y); - } - if (isBoolean(x) || x === null) { return leftShift(+x, y); } diff --git a/lib/function/bitwise/rightArithShift.js b/lib/function/bitwise/rightArithShift.js index 139a9ef09..fae1efaf3 100644 --- a/lib/function/bitwise/rightArithShift.js +++ b/lib/function/bitwise/rightArithShift.js @@ -11,7 +11,6 @@ module.exports = function (math, config) { isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger, isNumber = util.number.isNumber, - isString = util.string.isString, isCollection = collection.isCollection, bigRightShift = util.bignumber.rightShift; @@ -35,8 +34,8 @@ module.exports = function (math, config) { * * bitAnd, bitNot, bitOr, bitXor, leftShift, rightLogShift * - * @param {Number | BigNumber | Boolean | String | Array | Matrix | null} x Value to be shifted - * @param {Number | BigNumber | Boolean | String | null} y Amount of shifts + * @param {Number | BigNumber | Boolean | Array | Matrix | null} x Value to be shifted + * @param {Number | BigNumber | Boolean | null} y Amount of shifts * @return {Number | BigNumber | Array | Matrix} `x` sign-filled shifted right `y` times */ math.rightArithShift = function rightArithShift(x, y) { @@ -94,17 +93,6 @@ module.exports = function (math, config) { return collection.deepMap2(x, y, rightArithShift); } - if (isString(x)) { - return rightArithShift((config.number === 'bignumber') - ? BigNumber.convert(x) - : +x, y); - } - if (isString(y)) { - return rightArithShift(x, (config.number === 'bignumber') - ? BigNumber.convert(y) - : +y); - } - if (isBoolean(x) || x === null) { return rightArithShift(+x, y); } diff --git a/lib/function/bitwise/rightLogShift.js b/lib/function/bitwise/rightLogShift.js index 1ae45699d..a31971035 100644 --- a/lib/function/bitwise/rightLogShift.js +++ b/lib/function/bitwise/rightLogShift.js @@ -10,7 +10,6 @@ module.exports = function (math, config) { isBoolean = util['boolean'].isBoolean, isInteger = util.number.isInteger, isNumber = util.number.isNumber, - isString = util.string.isString, isCollection = collection.isCollection; /** @@ -32,8 +31,8 @@ module.exports = function (math, config) { * * bitAnd, bitNot, bitOr, bitXor, leftShift, rightArithShift * - * @param {Number | Boolean | String | Array | Matrix | null} x Value to be shifted - * @param {Number | Boolean | String | null} y Amount of shifts + * @param {Number | Boolean | Array | Matrix | null} x Value to be shifted + * @param {Number | Boolean | null} y Amount of shifts * @return {Number | Array | Matrix} `x` zero-filled shifted right `y` times */ math.rightLogShift = function rightLogShift(x, y) { @@ -53,17 +52,6 @@ module.exports = function (math, config) { return collection.deepMap2(x, y, rightLogShift); } - if (isString(x)) { - return rightLogShift((config.number === 'bignumber') - ? BigNumber.convert(x) - : +x, y); - } - if (isString(y)) { - return rightLogShift(x, (config.number === 'bignumber') - ? BigNumber.convert(y) - : +y); - } - if (isBoolean(x) || x === null) { return rightLogShift(+x, y); } diff --git a/lib/function/logical/and.js b/lib/function/logical/and.js index 56da1820f..49e4143ea 100644 --- a/lib/function/logical/and.js +++ b/lib/function/logical/and.js @@ -39,7 +39,7 @@ module.exports = function (math) { * * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x First value to check * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} y Second value to check - * @return {Boolean | Matrix} + * @return {Boolean | Array | Matrix} * Returns true when both inputs are defined with a nonzero/nonempty value. */ math.and = function and(x, y) { diff --git a/lib/function/logical/not.js b/lib/function/logical/not.js index 94cf80e79..cafe81fe8 100644 --- a/lib/function/logical/not.js +++ b/lib/function/logical/not.js @@ -36,7 +36,7 @@ module.exports = function (math) { * and, or, xor * * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x First value to check - * @return {Boolean | Matrix} + * @return {Boolean | Array | Matrix} * Returns true when input is a zero or empty value. */ math.not = function not(x) { diff --git a/lib/function/logical/or.js b/lib/function/logical/or.js index 6e025347a..5bf1db4b2 100644 --- a/lib/function/logical/or.js +++ b/lib/function/logical/or.js @@ -39,7 +39,7 @@ module.exports = function (math) { * * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x First value to check * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} y Second value to check - * @return {Boolean | Matrix} + * @return {Boolean | Array | Matrix} * Returns true when one of the inputs is defined with a nonzero/nonempty value. */ math.or = function or(x, y) { diff --git a/lib/function/logical/xor.js b/lib/function/logical/xor.js index 4ce9b6da8..a65b5ac0b 100644 --- a/lib/function/logical/xor.js +++ b/lib/function/logical/xor.js @@ -39,7 +39,7 @@ module.exports = function (math) { * * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x First value to check * @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} y Second value to check - * @return {Boolean | Matrix} + * @return {Boolean | Array | Matrix} * Returns true when one and only one input is defined with a nonzero/nonempty value. */ math.xor = function xor(x, y) { diff --git a/test/function/bitwise/bitAnd.test.js b/test/function/bitwise/bitAnd.test.js index 101a37a04..9348b8c06 100644 --- a/test/function/bitwise/bitAnd.test.js +++ b/test/function/bitwise/bitAnd.test.js @@ -58,25 +58,12 @@ describe('bitAnd', function () { assert.deepEqual(bitAnd(true, bignumber(3)), bignumber(1)); }); - it('should bitwise and mixed strings and bignumbers', function () { - assert.deepEqual(bitAnd(bignumber('-1.0e+31'), '-1.0e+32'), bignumber('-101273397985285317082036849082368')); - assert.deepEqual(bitAnd('1.0e+32', bignumber('1.0e+31')), bignumber('8726602014714682917961003433984')); - }); - it('should throw an error if used with a unit', function() { assert.throws(function () {bitAnd(math.unit('5cm'), 2)}, error.UnsupportedTypeError); assert.throws(function () {bitAnd(2, math.unit('5cm'))}, error.UnsupportedTypeError); assert.throws(function () {bitAnd(math.unit('2cm'), math.unit('5cm'))}, error.UnsupportedTypeError); }); - it('should bitwise and two ints, even in string format', function () { - assert.equal(bitAnd('120', '86'), 80); - assert.equal(bitAnd('86', 120), 80); - assert.equal(bitAnd('-120', '-86'), -120); - assert.equal(bitAnd(-120, '-86'), -120); - assert.equal(bitAnd(-120, '-86e2'), -8696); - }); - it('should throw an error if the parameters are not integers', function () { assert.throws(function () { bitAnd(1.1, 1); @@ -87,12 +74,6 @@ describe('bitAnd', function () { assert.throws(function () { bitAnd(1.1, 1.1); }, /Parameters in function bitAnd must be integer numbers/); - assert.throws(function () { - bitAnd('1.1', 1); - }, /Parameters in function bitAnd must be integer numbers/); - assert.throws(function () { - bitAnd(1, '1.1'); - }, /Parameters in function bitAnd must be integer numbers/); assert.throws(function () { bitAnd(bignumber(1.1), 1); }, /Parameters in function bitAnd must be integer numbers/); @@ -107,14 +88,6 @@ describe('bitAnd', function () { }, /Parameters in function bitAnd must be integer numbers/); }); - it('should bitwise and strings and matrices element wise', function () { - assert.deepEqual(bitAnd('42', ['1', 12, '31']), [0, 8, 10]); - assert.deepEqual(bitAnd(['1', 12, '31'], '42'), [0, 8, 10]); - - assert.deepEqual(bitAnd('42', math.matrix(['1', 12, '31'])), math.matrix([0, 8, 10])); - assert.deepEqual(bitAnd(math.matrix(['1', 12, '31']), '42'), math.matrix([0, 8, 10])); - }); - it('should bitwise and matrices correctly', function () { var a2 = math.matrix([[1,2],[3,4]]); var a3 = math.matrix([[5,6],[7,8]]); @@ -152,4 +125,13 @@ describe('bitAnd', function () { assert.throws(function () {bitAnd(1, 2, 3)}, error.ArgumentsError); }); + it('should throw an error in case of invalid type of arguments', function () { + assert.throws(function () {bitAnd(new Date(), true)}, error.UnsupportedTypeError); + assert.throws(function () {bitAnd(true, new Date())}, error.UnsupportedTypeError); + assert.throws(function () {bitAnd(true, 'foo')}, error.UnsupportedTypeError); + assert.throws(function () {bitAnd('foo', true)}, error.UnsupportedTypeError); + assert.throws(function () {bitAnd(true, undefined)}, error.UnsupportedTypeError); + assert.throws(function () {bitAnd(undefined, true)}, error.UnsupportedTypeError); + }); + }); diff --git a/test/function/bitwise/bitNot.test.js b/test/function/bitwise/bitNot.test.js index 722c505f5..187f1c0a5 100644 --- a/test/function/bitwise/bitNot.test.js +++ b/test/function/bitwise/bitNot.test.js @@ -15,12 +15,6 @@ describe('bitNot', function () { assert.equal(bitNot(null), -1); }); - it('should return bitwise not of a string', function () { - assert.equal(bitNot('2'), -3); - assert.equal(bitNot('-2'), 1); - assert.equal(bitNot('-86e2'), 8599); - }); - it('should perform bitwise not of a number', function () { assert.deepEqual(bitNot(2), -3); assert.deepEqual(bitNot(-2), 1); @@ -37,9 +31,6 @@ describe('bitNot', function () { assert.throws(function () { bitNot(1.1); }, /Parameter in function bitNot must be integer numbers/); - assert.throws(function () { - bitNot('1.1'); - }, /Parameter in function bitNot must be integer numbers/); assert.throws(function () { bitNot(bignumber(1.1)); }, /Parameter in function bitNot must be integer numbers/); @@ -68,6 +59,8 @@ describe('bitNot', function () { it('should throw an error in case of invalid type of argument', function () { assert.throws(function () {bitNot(new Date())}, error.UnsupportedTypeError); + assert.throws(function () {bitNot('foo')}, error.UnsupportedTypeError); + assert.throws(function () {bitNot(undefined)}, error.UnsupportedTypeError); }); }); diff --git a/test/function/bitwise/bitOr.test.js b/test/function/bitwise/bitOr.test.js index b80e8d8a5..3b8c5e4be 100644 --- a/test/function/bitwise/bitOr.test.js +++ b/test/function/bitwise/bitOr.test.js @@ -57,25 +57,12 @@ describe('bitOr', function () { assert.deepEqual(bitOr(true, bignumber(2)), bignumber(3)); }); - it('should bitwise or mixed strings and bignumbers', function () { - assert.deepEqual(bitOr('-1.0e+31', bignumber('-1.0e+32')), bignumber('-8726602014714682917963150917632')); - assert.deepEqual(bitOr(bignumber('1.0e+31'), '1.0e+32'), bignumber('101273397985285317082038996566016')); - }); - it('should throw an error if used with a unit', function() { assert.throws(function () {bitOr(math.unit('5cm'), 2)}, error.UnsupportedTypeError); assert.throws(function () {bitOr(2, math.unit('5cm'))}, error.UnsupportedTypeError); assert.throws(function () {bitOr(math.unit('2cm'), math.unit('5cm'))}, error.UnsupportedTypeError); }); - it('should bitwise or two ints, even in string format', function () { - assert.equal(bitOr('120', '86'), 126); - assert.equal(bitOr('86', 120), 126); - assert.equal(bitOr('-120', '-86'), -86); - assert.equal(bitOr(-120, '-86'), -86); - assert.equal(bitOr(-120, '-86e2'), -24); - }); - it('should throw an error if the parameters are not integers', function () { assert.throws(function () { bitOr(1.1, 1); @@ -86,12 +73,6 @@ describe('bitOr', function () { assert.throws(function () { bitOr(1.1, 1.1); }, /Parameters in function bitOr must be integer numbers/); - assert.throws(function () { - bitOr('1.1', 1); - }, /Parameters in function bitOr must be integer numbers/); - assert.throws(function () { - bitOr(1, '1.1'); - }, /Parameters in function bitOr must be integer numbers/); assert.throws(function () { bitOr(bignumber(1.1), 1); }, /Parameters in function bitOr must be integer numbers/); @@ -106,14 +87,6 @@ describe('bitOr', function () { }, /Parameters in function bitOr must be integer numbers/); }); - it('should bitwise or strings and matrices element wise', function () { - assert.deepEqual(bitOr('42', ['1', 12, '31']), [43, 46, 63]); - assert.deepEqual(bitOr(['1', 12, '31'], '42'), [43, 46, 63]); - - assert.deepEqual(bitOr('42', math.matrix(['1', 12, '31'])), math.matrix([43, 46, 63])); - assert.deepEqual(bitOr(math.matrix(['1', 12, '31']), '42'), math.matrix([43, 46, 63])); - }); - it('should bitwise or matrices correctly', function () { var a2 = math.matrix([[1,2],[3,4]]); var a3 = math.matrix([[5,6],[7,8]]); @@ -150,5 +123,13 @@ describe('bitOr', function () { assert.throws(function () {bitOr(1)}, error.ArgumentsError); assert.throws(function () {bitOr(1, 2, 3)}, error.ArgumentsError); }); + it('should throw an error in case of invalid type of arguments', function () { + assert.throws(function () {bitOr(new Date(), true)}, error.UnsupportedTypeError); + assert.throws(function () {bitOr(true, new Date())}, error.UnsupportedTypeError); + assert.throws(function () {bitOr(true, 'foo')}, error.UnsupportedTypeError); + assert.throws(function () {bitOr('foo', true)}, error.UnsupportedTypeError); + assert.throws(function () {bitOr(true, undefined)}, error.UnsupportedTypeError); + assert.throws(function () {bitOr(undefined, true)}, error.UnsupportedTypeError); + }); }); diff --git a/test/function/bitwise/bitXor.test.js b/test/function/bitwise/bitXor.test.js index bf0a1d88f..02c1d5788 100644 --- a/test/function/bitwise/bitXor.test.js +++ b/test/function/bitwise/bitXor.test.js @@ -59,25 +59,12 @@ describe('bitXor', function () { assert.deepEqual(bitXor(false, bignumber(3)), bignumber(3)); }); - it('should bitwise and mixed strings and bignumbers', function () { - assert.deepEqual(bitXor(bignumber('-1.0e+31'), '-1.0e+32'), bignumber('92546795970570634164073698164736')); - assert.deepEqual(bitXor('1.0e+31', bignumber('1.0e+32')), bignumber('92546795970570634164077993132032')); - }); - it('should throw an error if used with a unit', function() { assert.throws(function () {bitXor(math.unit('5cm'), 2)}, error.UnsupportedTypeError); assert.throws(function () {bitXor(2, math.unit('5cm'))}, error.UnsupportedTypeError); assert.throws(function () {bitXor(math.unit('2cm'), math.unit('5cm'))}, error.UnsupportedTypeError); }); - it('should xor two ints, even in string format', function () { - assert.equal(bitXor('120', '86'), 46); - assert.equal(bitXor('86', 120), 46); - assert.equal(bitXor('-120', '-86'), 34); - assert.equal(bitXor(-120, '-86'), 34); - assert.equal(bitXor(-120, '-86e2'), 8672); - }); - it('should throw an error if the parameters are not integers', function () { assert.throws(function () { bitXor(1.1, 1); @@ -88,12 +75,6 @@ describe('bitXor', function () { assert.throws(function () { bitXor(1.1, 1.1); }, /Parameters in function bitXor must be integer numbers/); - assert.throws(function () { - bitXor('1.1', 1); - }, /Parameters in function bitXor must be integer numbers/); - assert.throws(function () { - bitXor(1, '1.1'); - }, /Parameters in function bitXor must be integer numbers/); assert.throws(function () { bitXor(bignumber(1.1), 1); }, /Parameters in function bitXor must be integer numbers/); @@ -108,14 +89,6 @@ describe('bitXor', function () { }, /Parameters in function bitXor must be integer numbers/); }); - it('should xor strings and matrices element wise', function () { - assert.deepEqual(bitXor('42', ['1', 12, '31']), [43, 38, 53]); - assert.deepEqual(bitXor(['1', 12, '31'], '42'), [43, 38, 53]); - - assert.deepEqual(bitXor('42', math.matrix(['1', 12, '31'])), math.matrix([43, 38, 53])); - assert.deepEqual(bitXor(math.matrix(['1', 12, '31']), '42'), math.matrix([43, 38, 53])); - }); - it('should xor matrices correctly', function () { var a2 = math.matrix([[1,2],[3,4]]); var a3 = math.matrix([[5,6],[7,8]]); @@ -152,5 +125,13 @@ describe('bitXor', function () { assert.throws(function () {bitXor(1)}, error.ArgumentsError); assert.throws(function () {bitXor(1, 2, 3)}, error.ArgumentsError); }); + it('should throw an error in case of invalid type of arguments', function () { + assert.throws(function () {bitXor(new Date(), true)}, error.UnsupportedTypeError); + assert.throws(function () {bitXor(true, new Date())}, error.UnsupportedTypeError); + assert.throws(function () {bitXor(true, 'foo')}, error.UnsupportedTypeError); + assert.throws(function () {bitXor('foo', true)}, error.UnsupportedTypeError); + assert.throws(function () {bitXor(true, undefined)}, error.UnsupportedTypeError); + assert.throws(function () {bitXor(undefined, true)}, error.UnsupportedTypeError); + }); }); diff --git a/test/function/bitwise/leftShift.test.js b/test/function/bitwise/leftShift.test.js index 8da5478d0..88f6a2290 100644 --- a/test/function/bitwise/leftShift.test.js +++ b/test/function/bitwise/leftShift.test.js @@ -64,27 +64,12 @@ describe('leftShift', function () { assert.deepEqual(leftShift(bignumber(3), true), bignumber(6)); }); - it('should left shift mixed bignumbers and string', function () { - assert.deepEqual(leftShift(bignumber(2), '3'), bignumber(16)); - assert.deepEqual(leftShift('2', bignumber(3)), bignumber(16)); - assert.deepEqual(leftShift(bignumber(-1), '2'), bignumber(-4)); - assert.deepEqual(leftShift('-2', bignumber(3)), bignumber(-16)); - }); - it('should throw an error if used with a unit', function() { assert.throws(function () {leftShift(math.unit('5cm'), 2)}, error.UnsupportedTypeError); assert.throws(function () {leftShift(2, math.unit('5cm'))}, error.UnsupportedTypeError); assert.throws(function () {leftShift(math.unit('2cm'), math.unit('5cm'))}, error.UnsupportedTypeError); }); - it('should left shift by values given by strings', function () { - assert.equal(leftShift('0', '1000'), 0); - assert.equal(leftShift('2', 0), 2); - assert.equal(leftShift(2, '3'), 16); - assert.equal(leftShift('-2', 2), -8); - assert.equal(leftShift(-2, '1e2'), -32); - }); - it('should throw an error if the parameters are not integers', function () { assert.throws(function () { leftShift(1.1, 1); @@ -95,12 +80,6 @@ describe('leftShift', function () { assert.throws(function () { leftShift(1.1, 1.1); }, /Parameters in function leftShift must be integer numbers/); - assert.throws(function () { - leftShift('1.1', 1); - }, /Parameters in function leftShift must be integer numbers/); - assert.throws(function () { - leftShift(1, '1.1'); - }, /Parameters in function leftShift must be integer numbers/); assert.throws(function () { leftShift(bignumber(1.1), 1); }, /Parameters in function leftShift must be integer numbers/); @@ -140,4 +119,13 @@ describe('leftShift', function () { assert.throws(function () {leftShift(1, 2, 3)}, error.ArgumentsError); }); + it('should throw an error in case of invalid type of arguments', function () { + assert.throws(function () {leftShift(new Date(), true)}, error.UnsupportedTypeError); + assert.throws(function () {leftShift(true, new Date())}, error.UnsupportedTypeError); + assert.throws(function () {leftShift(true, 'foo')}, error.UnsupportedTypeError); + assert.throws(function () {leftShift('foo', true)}, error.UnsupportedTypeError); + assert.throws(function () {leftShift(true, undefined)}, error.UnsupportedTypeError); + assert.throws(function () {leftShift(undefined, true)}, error.UnsupportedTypeError); + }); + }); diff --git a/test/function/bitwise/rightArithShift.test.js b/test/function/bitwise/rightArithShift.test.js index 0d118569d..4c9d418d4 100644 --- a/test/function/bitwise/rightArithShift.test.js +++ b/test/function/bitwise/rightArithShift.test.js @@ -39,14 +39,6 @@ describe('rightArithShift', function () { assert.equal(rightArithShift(null, 1), 0); }); - it('should right arithmetically shift by values given by strings', function () { - assert.equal(rightArithShift('0', '1000'), 0); - assert.equal(rightArithShift('2', 0), 2); - assert.equal(rightArithShift(22, '3'), 2); - assert.equal(rightArithShift('-256', 2), -64); - assert.equal(rightArithShift('-256', '1e2'), -16); - }); - it('should right arithmetically shift bignumbers', function () { assert.deepEqual(rightArithShift(bignumber(17), bignumber(3)), bignumber(2)); assert.deepEqual(rightArithShift(bignumber('633825300114114700748351602688000'), bignumber(100)), bignumber(500)); @@ -75,13 +67,6 @@ describe('rightArithShift', function () { assert.deepEqual(rightArithShift(bignumber(3), true), bignumber(1)); }); - it('should right arithmetically shift mixed bignumbers and string', function () { - assert.deepEqual(rightArithShift(bignumber(17), '3'), bignumber(2)); - assert.deepEqual(rightArithShift('17', bignumber(3)), bignumber(2)); - assert.deepEqual(rightArithShift(bignumber('-17'), '3'), bignumber(-3)); - assert.deepEqual(rightArithShift('-17', bignumber(3)), bignumber(-3)); - }); - it('should throw an error if the parameters are not integers', function () { assert.throws(function () { rightArithShift(1.1, 1); @@ -92,12 +77,6 @@ describe('rightArithShift', function () { assert.throws(function () { rightArithShift(1.1, 1.1); }, /Parameters in function rightArithShift must be integer numbers/); - assert.throws(function () { - rightArithShift('1.1', 1); - }, /Parameters in function rightArithShift must be integer numbers/); - assert.throws(function () { - rightArithShift(1, '1.1'); - }, /Parameters in function rightArithShift must be integer numbers/); assert.throws(function () { rightArithShift(bignumber(1.1), 1); }, /Parameters in function rightArithShift must be integer numbers/); @@ -143,4 +122,13 @@ describe('rightArithShift', function () { assert.throws(function () {rightArithShift(1, 2, 3)}, error.ArgumentsError); }); + it('should throw an error in case of invalid type of arguments', function () { + assert.throws(function () {rightArithShift(new Date(), true)}, error.UnsupportedTypeError); + assert.throws(function () {rightArithShift(true, new Date())}, error.UnsupportedTypeError); + assert.throws(function () {rightArithShift(true, 'foo')}, error.UnsupportedTypeError); + assert.throws(function () {rightArithShift('foo', true)}, error.UnsupportedTypeError); + assert.throws(function () {rightArithShift(true, undefined)}, error.UnsupportedTypeError); + assert.throws(function () {rightArithShift(undefined, true)}, error.UnsupportedTypeError); + }); + }); diff --git a/test/function/bitwise/rightLogShift.test.js b/test/function/bitwise/rightLogShift.test.js index d797e311c..f1a4aaf3c 100644 --- a/test/function/bitwise/rightLogShift.test.js +++ b/test/function/bitwise/rightLogShift.test.js @@ -38,14 +38,6 @@ describe('rightLogShift', function () { assert.equal(rightLogShift(null, 1), 0); }); - it('should right logically shift by values given by strings', function () { - assert.equal(rightLogShift('0', '1000'), 0); - assert.equal(rightLogShift('2', 0), 2); - assert.equal(rightLogShift(22, '3'), 2); - assert.equal(rightLogShift('-256', 2), 1073741760); - assert.equal(rightLogShift('-256', '1e2'), 268435440); - }); - it('should throw an error if the parameters are not integers', function () { assert.throws(function () { rightLogShift(1.1, 1); @@ -56,15 +48,6 @@ describe('rightLogShift', function () { assert.throws(function () { rightLogShift(1.1, 1.1); }, /Parameters in function rightLogShift must be integer numbers/); - assert.throws(function () { - rightLogShift('1.1', '1.1'); - }, /Parameters in function rightLogShift must be integer numbers/); - assert.throws(function () { - rightLogShift('1.1', 1); - }, /Parameters in function rightLogShift must be integer numbers/); - assert.throws(function () { - rightLogShift(1, '1.1'); - }, /Parameters in function rightLogShift must be integer numbers/); }); it('should throw an error if used with a unit', function() { @@ -98,4 +81,13 @@ describe('rightLogShift', function () { assert.throws(function () {rightLogShift(1, 2, 3)}, error.ArgumentsError); }); + it('should throw an error in case of invalid type of arguments', function () { + assert.throws(function () {rightLogShift(new Date(), true)}, error.UnsupportedTypeError); + assert.throws(function () {rightLogShift(true, new Date())}, error.UnsupportedTypeError); + assert.throws(function () {rightLogShift(true, 'foo')}, error.UnsupportedTypeError); + assert.throws(function () {rightLogShift('foo', true)}, error.UnsupportedTypeError); + assert.throws(function () {rightLogShift(true, undefined)}, error.UnsupportedTypeError); + assert.throws(function () {rightLogShift(undefined, true)}, error.UnsupportedTypeError); + }); + }); diff --git a/test/function/logical/and.test.js b/test/function/logical/and.test.js index 238c48309..87834a92e 100644 --- a/test/function/logical/and.test.js +++ b/test/function/logical/and.test.js @@ -137,15 +137,18 @@ describe('and', function () { assert.deepEqual(and(matrix([0, 2]), 10), matrix([false, true])); }); - it('should throw an error in case of invalid type if arguments', function () { - assert.throws(function () {and(new Date(), new Date())}, TypeError); - assert.throws(function () {and(2, '23')}, TypeError); - assert.throws(function () {and(2, undefined)}, TypeError); - }); - it('should throw an error in case of invalid number of arguments', function () { assert.throws(function () {and(1)}, error.ArgumentsError); assert.throws(function () {and(1, 2, 3)}, error.ArgumentsError); }); + it('should throw an error in case of invalid type of arguments', function () { + assert.throws(function () {and(new Date(), true)}, error.UnsupportedTypeError); + assert.throws(function () {and(true, new Date())}, error.UnsupportedTypeError); + assert.throws(function () {and(true, 'foo')}, error.UnsupportedTypeError); + assert.throws(function () {and('foo', true)}, error.UnsupportedTypeError); + assert.throws(function () {and(true, undefined)}, error.UnsupportedTypeError); + assert.throws(function () {and(undefined, true)}, error.UnsupportedTypeError); + }); + }); diff --git a/test/function/logical/not.test.js b/test/function/logical/not.test.js index 7db8bbad3..1f3bdec49 100644 --- a/test/function/logical/not.test.js +++ b/test/function/logical/not.test.js @@ -71,15 +71,15 @@ describe('not', function () { assert.deepEqual(not(matrix([])), matrix([])); }); - it('should throw an error in case of invalid type if arguments', function () { - assert.throws(function () {not(new Date())}, TypeError); - assert.throws(function () {not('23')}, TypeError); - assert.throws(function () {not({})}, TypeError); - }); - it('should throw an error in case of invalid number of arguments', function () { assert.throws(function () {not()}, error.ArgumentsError); assert.throws(function () {not(1, 2)}, error.ArgumentsError); }); + it('should throw an error in case of invalid type if arguments', function () { + assert.throws(function () {not(new Date())}, error.UnsupportedTypeError); + assert.throws(function () {not('23')}, error.UnsupportedTypeError); + assert.throws(function () {not({})}, error.UnsupportedTypeError); + }); + }); diff --git a/test/function/logical/or.test.js b/test/function/logical/or.test.js index 866133e30..39920c63b 100644 --- a/test/function/logical/or.test.js +++ b/test/function/logical/or.test.js @@ -161,15 +161,18 @@ describe('or', function () { assert.deepEqual(or(matrix([0, 2]), 0), matrix([false, true])); }); - it('should throw an error in case of invalid type if arguments', function () { - assert.throws(function () {or(new Date(), new Date())}, TypeError); - assert.throws(function () {or(2, '23')}, TypeError); - assert.throws(function () {or(2, undefined)}, TypeError); - }); - it('should throw an error in case of invalid number of arguments', function () { assert.throws(function () {or(1)}, error.ArgumentsError); assert.throws(function () {or(1, 2, 3)}, error.ArgumentsError); }); + it('should throw an error in case of invalid type of arguments', function () { + assert.throws(function () {or(new Date(), true)}, error.UnsupportedTypeError); + assert.throws(function () {or(true, new Date())}, error.UnsupportedTypeError); + assert.throws(function () {or(true, 'foo')}, error.UnsupportedTypeError); + assert.throws(function () {or('foo', true)}, error.UnsupportedTypeError); + assert.throws(function () {or(true, undefined)}, error.UnsupportedTypeError); + assert.throws(function () {or(undefined, true)}, error.UnsupportedTypeError); + }); + }); diff --git a/test/function/logical/xor.test.js b/test/function/logical/xor.test.js index 2144719b1..001851f78 100644 --- a/test/function/logical/xor.test.js +++ b/test/function/logical/xor.test.js @@ -157,15 +157,18 @@ describe('xor', function () { assert.deepEqual(xor(matrix([0, 2]), 0), matrix([false, true])); }); - it('should throw an error in case of invalid type if arguments', function () { - assert.throws(function () {xor(new Date(), new Date())}, TypeError); - assert.throws(function () {xor(2, '23')}, TypeError); - assert.throws(function () {xor(2, undefined)}, TypeError); - }); - it('should throw an error in case of invalid number of arguments', function () { assert.throws(function () {xor(1)}, error.ArgumentsError); assert.throws(function () {xor(1, 2, 3)}, error.ArgumentsError); }); + it('should throw an error in case of invalid type of arguments', function () { + assert.throws(function () {xor(new Date(), true)}, error.UnsupportedTypeError); + assert.throws(function () {xor(true, new Date())}, error.UnsupportedTypeError); + assert.throws(function () {xor(true, 'foo')}, error.UnsupportedTypeError); + assert.throws(function () {xor('foo', true)}, error.UnsupportedTypeError); + assert.throws(function () {xor(true, undefined)}, error.UnsupportedTypeError); + assert.throws(function () {xor(undefined, true)}, error.UnsupportedTypeError); + }); + });