mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
* 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
101 lines
3.2 KiB
JavaScript
101 lines
3.2 KiB
JavaScript
const assert = require('assert')
|
|
const math = require('../../../src/main')
|
|
|
|
describe('seed', function () {
|
|
after(function () {
|
|
// Randomly seed random number generator
|
|
math.config({ randomSeed: null })
|
|
})
|
|
|
|
it('should generate same number with seed', function () {
|
|
math.config({ randomSeed: 'a' })
|
|
const first = math.random()
|
|
math.config({ randomSeed: 'a' })
|
|
const second = math.random()
|
|
assert.strictEqual(first, second)
|
|
})
|
|
|
|
it('should generate different number subsequent calls to seeded random', function () {
|
|
math.config({ randomSeed: 'a' })
|
|
const first = math.random()
|
|
const second = math.random()
|
|
assert.notStrictEqual(first, second)
|
|
})
|
|
|
|
it('calling with no parameters should unseed rng', function () {
|
|
math.config({ randomSeed: 'a' })
|
|
const firstA = math.random()
|
|
const secondA = math.random()
|
|
math.config({ randomSeed: 'a' })
|
|
const firstB = math.random()
|
|
math.config({ randomSeed: null })
|
|
const secondB = math.random()
|
|
assert.strictEqual(firstA, firstB)
|
|
assert.notStrictEqual(secondA, secondB)
|
|
})
|
|
|
|
it('should generate same matrix with seed', function () {
|
|
math.config({ randomSeed: 'a' })
|
|
const first = math.random([5, 5])
|
|
math.config({ randomSeed: 'a' })
|
|
const second = math.random([5, 5])
|
|
assert.strictEqual(math.deepEqual(first, second), true)
|
|
})
|
|
|
|
it('should generate different matrices subsequent calls to seeded random', function () {
|
|
math.config({ randomSeed: 'a' })
|
|
const first = math.random([5, 5])
|
|
const second = math.random([5, 5])
|
|
assert.strictEqual(math.deepEqual(first, second), false)
|
|
})
|
|
|
|
it('should pick same number with seed', function () {
|
|
const range = math.range(1, 1000)
|
|
math.config({ randomSeed: 'a' })
|
|
const first = math.pickRandom(range)
|
|
math.config({ randomSeed: 'a' })
|
|
const second = math.pickRandom(range)
|
|
assert.strictEqual(first, second)
|
|
})
|
|
|
|
it('should pick different number subsequent calls to seeded random', function () {
|
|
// In theory these might be the same but with 'a' as seed they are different and always will be
|
|
const range = math.range(1, 1000)
|
|
math.config({ randomSeed: 'a' })
|
|
const first = math.pickRandom(range)
|
|
const second = math.pickRandom(range)
|
|
assert.notStrictEqual(first, second)
|
|
})
|
|
|
|
it('should pick same int with seed', function () {
|
|
math.config({ randomSeed: 'a' })
|
|
const first = math.randomInt(1, 100)
|
|
math.config({ randomSeed: 'a' })
|
|
const second = math.randomInt(1, 100)
|
|
assert.strictEqual(first, second)
|
|
})
|
|
|
|
it('should pick different int subsequent calls to seeded random', function () {
|
|
math.config({ randomSeed: 'a' })
|
|
const first = math.randomInt(1, 100)
|
|
const second = math.randomInt(1, 100)
|
|
assert.notStrictEqual(first, second)
|
|
})
|
|
|
|
it('should work for number seeds', function () {
|
|
math.config({ randomSeed: 1 })
|
|
const first = math.random()
|
|
math.config({ randomSeed: 1 })
|
|
const second = math.random()
|
|
assert.strictEqual(first, second)
|
|
})
|
|
|
|
it('should work for object seeds', function () {
|
|
math.config({ randomSeed: { a: 1 } })
|
|
const first = math.random()
|
|
math.config({ randomSeed: { a: 1 } })
|
|
const second = math.random()
|
|
assert.strictEqual(first, second)
|
|
})
|
|
})
|