Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Fix Opcode.smallInt
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Feb 1, 2016
1 parent 6ae9b2f commit af4d9ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/opcode.js
Expand Up @@ -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');
Expand Down
13 changes: 13 additions & 0 deletions test/opcode.js
Expand Up @@ -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) {
Expand Down

0 comments on commit af4d9ae

Please sign in to comment.