Skip to content

Commit

Permalink
Added config test
Browse files Browse the repository at this point in the history
  • Loading branch information
dvd101x committed Apr 27, 2024
1 parent a4ac4a8 commit b164642
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/core/function/config.js
@@ -1,4 +1,4 @@
import { clone, mapObject, deepExtend } from '../../utils/object.js'
import { clone, deepExtend } from '../../utils/object.js'
import { DEFAULT_CONFIG } from '../config.js'

export const MATRIX_OPTIONS = ['Matrix', 'Array'] // valid values for option matrix
Expand Down Expand Up @@ -53,34 +53,33 @@ export function configFactory (config, emit) {
function _config (options) {
if (options) {
if (options.epsilon !== undefined) {
// backwards compatibility
// this if is only for backwards compatibility, it can be removed in the future.
console.warn('Warning: The configuration option "epsilon" is deprecated. Use "relTol" and "absTol" instead.')
const optionsFix = mapObject(options, clone)
const optionsFix = clone(options)
optionsFix.relTol = options.epsilon
optionsFix.absTol = options.epsilon * 1e-3
delete optionsFix.epsilon
return _config(optionsFix)
} else {
const prev = mapObject(config, clone)
}
const prev = clone(config)

// validate some of the options
validateOption(options, 'matrix', MATRIX_OPTIONS)
validateOption(options, 'number', NUMBER_OPTIONS)
// validate some of the options
validateOption(options, 'matrix', MATRIX_OPTIONS)
validateOption(options, 'number', NUMBER_OPTIONS)

// merge options
deepExtend(config, options)
// merge options
deepExtend(config, options)

const curr = mapObject(config, clone)
const curr = clone(config)

const changes = mapObject(options, clone)
const changes = clone(options)

// emit 'config' event
emit('config', curr, prev, changes)
// emit 'config' event
emit('config', curr, prev, changes)

return curr
}
return curr
} else {
return mapObject(config, clone)
return clone(config)
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/unit-tests/core/config.test.js
Expand Up @@ -17,4 +17,10 @@ describe('config', function () {
})

// TODO: test function config

it('should work with config epsilon during depercation', function () {
const math2 = math.create()
assert.doesNotThrow(function () { math2.config({ epsilon: 1e-5 }) })
assert.strictEqual(math2.config().relTol, 1e-5)
})
})
1 change: 1 addition & 0 deletions types/index.d.ts
Expand Up @@ -4300,6 +4300,7 @@ export interface Help {
export interface ConfigOptions {
relTol?: number
absTol?: number
epsilon?: number
matrix?: 'Matrix' | 'Array'
number?: 'number' | 'BigNumber' | 'Fraction'
precision?: number
Expand Down

0 comments on commit b164642

Please sign in to comment.