Merge pull request #40 from fanatid/fix/opcode-smallint
Fix Opcode.smallInt
This commit is contained in:
commit
8bd466373e
|
@ -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');
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue