mathjs/test/function/utils/isPrime.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

48 lines
2.0 KiB
JavaScript

const assert = require('assert')
const math = require('../../../src/main')
const isPrime = math.isPrime
const bignumber = math.bignumber
const complex = math.complex
describe('isPrime', function () {
it('should test whether a number is prime', function () {
assert.strictEqual(isPrime(0), false)
assert.strictEqual(isPrime(-0), false)
assert.strictEqual(isPrime(-1), false)
assert.strictEqual(isPrime(1), false)
assert.strictEqual(isPrime(2), true)
assert.strictEqual(isPrime(3), true)
assert.strictEqual(isPrime(5), true)
assert.strictEqual(isPrime(7), true)
assert.strictEqual(isPrime(4), false)
assert.strictEqual(isPrime(100), false)
assert.strictEqual(isPrime(102), false)
assert.strictEqual(isPrime(999), false)
})
it('should test whether a BigNumber is prime', function () {
assert.strictEqual(isPrime(bignumber(0)), false)
assert.strictEqual(isPrime(bignumber(-0)), false)
assert.strictEqual(isPrime(bignumber(-1)), false)
assert.strictEqual(isPrime(bignumber(1)), false)
assert.strictEqual(isPrime(bignumber(2)), true)
assert.strictEqual(isPrime(bignumber(3)), true)
assert.strictEqual(isPrime(bignumber(5)), true)
assert.strictEqual(isPrime(bignumber(7)), true)
assert.strictEqual(isPrime(bignumber(4)), false)
assert.strictEqual(isPrime(bignumber(100)), false)
assert.strictEqual(isPrime(bignumber(102)), false)
assert.strictEqual(isPrime(bignumber(999)), false)
})
it('should test isPrime element wise on an Array', function () {
assert.deepStrictEqual(isPrime([0, 1, 2, 5, 9]), [false, false, true, true, false])
})
it('should throw an error in case of unsupported data types', function () {
assert.throws(function () { isPrime(complex(2, 3)) }, /TypeError: Unexpected type of argument/)
assert.throws(function () { isPrime(new Date()) }, /TypeError: Unexpected type of argument/)
assert.throws(function () { isPrime({}) }, /TypeError: Unexpected type of argument/)
})
})