From b1646420c76bd756f06720fe8f1593f01518294b Mon Sep 17 00:00:00 2001 From: David Contreras Date: Fri, 26 Apr 2024 23:20:57 -0600 Subject: [PATCH] Added config test --- src/core/function/config.js | 33 ++++++++++++++--------------- test/unit-tests/core/config.test.js | 6 ++++++ types/index.d.ts | 1 + 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/core/function/config.js b/src/core/function/config.js index f8d06b1524..9efd7fb6d1 100644 --- a/src/core/function/config.js +++ b/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 @@ -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) } } diff --git a/test/unit-tests/core/config.test.js b/test/unit-tests/core/config.test.js index 519ce76526..45802b4cdd 100644 --- a/test/unit-tests/core/config.test.js +++ b/test/unit-tests/core/config.test.js @@ -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) + }) }) diff --git a/types/index.d.ts b/types/index.d.ts index 67a22b6d42..fbd6bfe181 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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