Fixing IntegerOverflow on Composition. Updated tests as well.

This commit is contained in:
Devan Patel 2015-05-04 16:03:59 -04:00
parent ff73f26132
commit c3f051ee8b
2 changed files with 2 additions and 1 deletions

View File

@ -57,7 +57,7 @@ module.exports = function (math) {
if (k.gt(n)) {
throw new TypeError('k must be less than n in function composition');
}
return math.combinations(n-1,k-1);
return math.combinations(n.minus(1), k.minus(1));
} else {
throw new TypeError('Integer values are expected in composition')
}

View File

@ -14,6 +14,7 @@ describe('composition', function() {
it('should calculate the composition of n items taken k at a time with BigNumbers', function(){
assert.equal(composition(math.bignumber(7), math.bignumber(5)), math.bignumber(15));
assert.equal(composition(math.bignumber(70), math.bignumber(3)), math.bignumber(2346));
assert.equal(composition(math.bignumber(56), math.bignumber(11)), math.bignumber(29248649430));
});
it('should not work with non-integer and negative input', function() {