mathjs/test/function/combinatorics/composition.test.js
greenkeeper[bot] c5971b371a Update standard to the latest version 🚀 (#1226)
* chore(package): update standard to version 12.0.0

* update to new lint version with --fix

I believe this mainly adds whitespace to `{}`'s.

* Replace assert.equal with assert.strictEqual

This breaks a lot of tests which I will endevour to fix in the next
commits.

* Fix most errors due to assert.strictEquals

Some instances of `strictEquals` are replaced by `deepEquals`.
`toString` has been used to make some string comparisions explicit.
Tests will still fail untill #1236 and #1237 are fixed.

* Fix assertion erros due to -0

With node 10, assert.strictEqual no longer considers `0 === -0`.
I missed these first time round as I was using node 8.

* Put toString correct side of bracket

I was converting the constructor to a string rather
than the result of the computation. Oops.

* Fixed #1236: quantileSeq has inconsistant return

* Update package-lock

* Fixed #1237: norm sometimes returning a complex number instead of number

* Fix cli tests

* More changes for standardjs, and fixes in unit tests
2018-09-08 16:33:58 +02:00

33 lines
2.0 KiB
JavaScript

const assert = require('assert')
const math = require('../../../src/main')
const composition = math.composition
describe('composition', function () {
it('should calculate the number of ways to compose a set of n objects into k non-empty subsets', function () {
assert.strictEqual(composition(5, 3), 6)
assert.strictEqual(composition(1, 1), 1)
assert.strictEqual(composition(8, 3), 21)
})
it('should calculate the composition of n items taken k at a time with BigNumbers', function () {
assert.deepStrictEqual(composition(math.bignumber(7), math.bignumber(5)), math.bignumber(15))
assert.deepStrictEqual(composition(math.bignumber(70), math.bignumber(3)), math.bignumber(2346))
assert.deepStrictEqual(composition(math.bignumber(56), math.bignumber(11)), math.bignumber(29248649430))
})
it('should not work with non-integer and negative input', function () {
assert.throws(function () { composition(0.5, 3) }, /TypeError: Positive integer value expected in function composition/)
assert.throws(function () { composition(-2, 3) }, /TypeError: Positive integer value expected in function composition/)
assert.throws(function () { composition(6, -2) }, /TypeError: Positive integer value expected in function composition/)
assert.throws(function () { composition(3, 5) }, /TypeError: k must be less than or equal to n in function composition/)
assert.throws(function () { composition(math.bignumber(3), math.bignumber(5)) }, /TypeError: k must be less than or equal to n in function composition/)
assert.throws(function () { composition(math.bignumber(3.5), math.bignumber(-3)) }, /TypeError: Positive integer value expected in function composition/)
assert.throws(function () { composition(math.bignumber(3.5), 0.25) }, /TypeError: Positive integer value expected in function composition/)
})
it('should not work with the wrong number or type of arguments', function () {
assert.throws(function () { composition(5, 3, 2) })
assert.throws(function () { composition(true, 'hello world') })
})
})