diff --git a/lib/opcode.js b/lib/opcode.js index 3218faf..edf02cb 100644 --- a/lib/opcode.js +++ b/lib/opcode.js @@ -67,6 +67,7 @@ Opcode.prototype.toString = function() { }; Opcode.smallInt = function(n) { + $.checkArgument(_.isNumber(n), 'Invalid Argument: n should be number'); $.checkArgument(n >= 0 && n <= 16, 'Invalid Argument: n must be between 0 and 16'); if (n === 0) { return Opcode('OP_0'); diff --git a/test/opcode.js b/test/opcode.js index 6471e13..5de57bd 100644 --- a/test/opcode.js +++ b/test/opcode.js @@ -120,10 +120,23 @@ describe('Opcode', function() { var testSmallInt = function(n, op) { Opcode.smallInt(n).toString().should.equal(op.toString()); }; + for (var i = 0; i < smallints.length; i++) { var op = smallints[i]; it('should work for small int ' + op, testSmallInt.bind(null, i, op)); } + + it('with not number', function () { + Opcode.smallInt.bind(null, '2').should.throw('Invalid Argument'); + }); + + it('with n equal -1', function () { + Opcode.smallInt.bind(null, -1).should.throw('Invalid Argument'); + }); + + it('with n equal 17', function () { + Opcode.smallInt.bind(null, 17).should.throw('Invalid Argument'); + }); }); describe('@isSmallIntOp', function() { var testIsSmallInt = function(op) {