Skip to content

Commit

Permalink
Implemented snapshot testing for all exported bundles and instances
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Jan 23, 2019
1 parent 1031da4 commit 19bc1e0
Show file tree
Hide file tree
Showing 20 changed files with 1,149 additions and 187 deletions.
1 change: 0 additions & 1 deletion docs/reference/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,3 @@ A node in an expression-tree, which can be used to analyze, manipulate, and eval
- [ParenthesisNode](../expressions/expression_trees.md#parenthesisnode)
- [RangeNode](../expressions/expression_trees.md#rangenode)
- [SymbolNode](../expressions/expression_trees.md#symbolnode)
- [UpdateNode](../expressions/expression_trees.md#updatenode)
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ gulp.task('validate', ['minify'], function (cb) {

// this is run in a separate process as the modules need to be reloaded
// with every validation (and required modules stay in cache).
childProcess.execFile('node', ['./tools/validate'], function (err, stdout, stderr) {
childProcess.execFile('node', ['./tools/validateEmbeddedDocs'], function (err, stdout, stderr) {
if (err instanceof Error) {
throw err
}
Expand Down
125 changes: 66 additions & 59 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const createLOG10E = /* #__PURE__ */ recreateFactory(
: Math.LOG10E
)

export const createSQRTHalf = /* #__PURE__ */ recreateFactory(
export const createSQRT1_2 = /* #__PURE__ */ recreateFactory( // eslint-disable-line camelcase
'SQRT1_2',
['config', 'type.BigNumber'],
({ config, type: { BigNumber } }) => (config.number === 'BigNumber')
Expand Down
14 changes: 7 additions & 7 deletions src/core/function/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import { clone, mapObject, deepExtend } from '../../utils/object'
import { DEFAULT_CONFIG } from '../config'

export function configFactory (config, emit) {
const MATRIX = ['Matrix', 'Array'] // valid values for option matrix
const NUMBER = ['number', 'BigNumber', 'Fraction'] // valid values for option number
export const MATRIX_OPTIONS = ['Matrix', 'Array'] // valid values for option matrix
export const NUMBER_OPTIONS = ['number', 'BigNumber', 'Fraction'] // valid values for option number

export function configFactory (config, emit) {
/**
* Set configuration options for math.js, and get current options.
* Will emit a 'config' event, with arguments (curr, prev, changes).
Expand Down Expand Up @@ -46,8 +46,8 @@ export function configFactory (config, emit) {
const prev = mapObject(config, clone)

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

// merge options
deepExtend(config, options)
Expand All @@ -66,8 +66,8 @@ export function configFactory (config, emit) {
}

// attach the valid options to the function so they can be extended
_config.MATRIX = MATRIX
_config.NUMBER = NUMBER
_config.MATRIX_OPTIONS = MATRIX_OPTIONS
_config.NUMBER_OPTIONS = NUMBER_OPTIONS

// attach the config properties as readonly properties to the config function
Object.keys(DEFAULT_CONFIG).forEach(key => {
Expand Down
6 changes: 0 additions & 6 deletions src/function/algebra/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import { createDerivative } from './derivative'
import { createSimplify } from './simplify'
import { createResolve } from './simplify/resolve'
import { createRationalize } from './rationalize'
import { createSimplifyConstant } from './simplify/simplifyConstant'
import { createSimplifyCore } from './simplify/simplifyCore'

import { createLup } from './decomposition/lup'
import { createQr } from './decomposition/qr'
Expand All @@ -19,9 +16,6 @@ export default [

// simplify
createSimplify,
createResolve,
createSimplifyConstant,
createSimplifyCore,

// polynomial
createRationalize,
Expand Down
83 changes: 72 additions & 11 deletions src/function/algebra/rationalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,90 @@

import { isInteger } from '../../utils/number'
import { factory } from '../../utils/factory'
import { createSimplifyConstant } from './simplify/simplifyConstant'
import { createSimplifyCore } from './simplify/simplifyCore'

const name = 'rationalize'
const dependencies = [
'config',
'typed',
'equal',
'isZero',
'add',
'subtract',
'multiply',
'divide',
'pow',
'parse',
'simplify',
'algebra.simplify.simplifyConstant',
'algebra.simplify.simplifyCore',
'bignumber',
'fraction',
'math',
'expression.node.ConstantNode',
'expression.node.OperatorNode',
'expression.node.SymbolNode'
'expression.node.FunctionNode',
'expression.node.SymbolNode',
'expression.node.ParenthesisNode'
]

export const createRationalize = /* #__PURE__ */ factory(name, dependencies, (
{
typed,
parse,
simplify,
algebra: { simplify: { simplifyConstant, simplifyCore } },
expression: { node: { ConstantNode, OperatorNode, SymbolNode }
export const createRationalize = /* #__PURE__ */ factory(name, dependencies, ({
config,
typed,
equal,
isZero,
add,
subtract,
multiply,
divide,
pow,
parse,
simplify,
fraction,
bignumber,
math,
expression: {
node: {
ConstantNode,
OperatorNode,
FunctionNode,
SymbolNode,
ParenthesisNode
}
}
) => {
}) => {
const simplifyConstant = createSimplifyConstant({
typed,
config,
math,
fraction,
bignumber,
expression: {
node: {
ConstantNode,
OperatorNode,
FunctionNode,
SymbolNode
}
}
})
const simplifyCore = createSimplifyCore({
equal,
isZero,
add,
subtract,
multiply,
divide,
pow,
expression: {
node: {
ConstantNode,
OperatorNode,
FunctionNode,
ParenthesisNode
}
}
})

/**
* Transform a rationalizable expression in a rational fraction.
* If rational fraction is one variable polynomial then converts
Expand Down
79 changes: 74 additions & 5 deletions src/function/algebra/simplify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@
import { isConstantNode, isParenthesisNode } from '../../utils/is'
import { factory } from '../../utils/factory'
import { createUtil } from './simplify/util'
import { createSimplifyCore } from './simplify/simplifyCore'
import { createSimplifyConstant } from './simplify/simplifyConstant'
import { createResolve } from './simplify/resolve'

const name = 'simplify'
const dependencies = [
'config',
'typed',
'parse',
'add',
'subtract',
'multiply',
'divide',
'pow',
'isZero',
'equal',
'algebra.simplify.simplifyConstant',
'algebra.simplify.simplifyCore',
'algebra.simplify.resolve',
'fraction',
'bignumber',
'math',
'expression.node.ConstantNode',
'expression.node.FunctionNode',
'expression.node.OperatorNode',
Expand All @@ -21,14 +31,73 @@ const dependencies = [

export const createSimplify = /* #__PURE__ */ factory(name, dependencies, (
{
config,
typed,
parse,
add,
subtract,
multiply,
divide,
pow,
isZero,
equal,
algebra: { simplify: { simplifyConstant, simplifyCore, resolve } },
expression: { node: { ConstantNode, FunctionNode, OperatorNode, ParenthesisNode, SymbolNode }
fraction,
bignumber,
math,
expression: {
node: {
ConstantNode,
FunctionNode,
OperatorNode,
ParenthesisNode,
SymbolNode
}
}
}
) => {
const simplifyConstant = createSimplifyConstant({
typed,
config,
math,
fraction,
bignumber,
expression: {
node: {
ConstantNode,
OperatorNode,
FunctionNode,
SymbolNode
}
}
})
const simplifyCore = createSimplifyCore({
equal,
isZero,
add,
subtract,
multiply,
divide,
pow,
expression: {
node: {
ConstantNode,
OperatorNode,
FunctionNode,
ParenthesisNode
}
}
})
const resolve = createResolve({
expression: {
parse,
node: {
FunctionNode,
OperatorNode,
ParenthesisNode
}
}
})

const { isCommutative, isAssociative, flatten, unflattenr, unflattenl, createMakeNodeFunction } =
createUtil({ expression: { node: { FunctionNode, OperatorNode, SymbolNode } } })

Expand Down
6 changes: 2 additions & 4 deletions src/function/algebra/simplify/resolve.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
'use strict'

import { isFunctionNode, isOperatorNode, isParenthesisNode, isSymbolNode } from '../../../utils/is'
import { isFunctionNode, isNode, isOperatorNode, isParenthesisNode, isSymbolNode } from '../../../utils/is'
import { factory } from '../../../utils/factory'

const name = 'algebra.simplify.resolve'
const dependencies = [
'expression.parse',
'expression.node.Node',
'expression.node.FunctionNode',
'expression.node.OperatorNode',
'expression.node.ParenthesisNode'
]

export const createResolve = /* #__PURE__ */ factory(name, dependencies, ({ expression: { parse, node: {
Node,
FunctionNode,
OperatorNode,
ParenthesisNode
Expand Down Expand Up @@ -41,7 +39,7 @@ export const createResolve = /* #__PURE__ */ factory(name, dependencies, ({ expr
}
if (isSymbolNode(node)) {
const value = scope[node.name]
if (value instanceof Node) {
if (isNode(value)) {
return resolve(value, scope)
} else if (typeof value === 'number') {
return parse(String(value))
Expand Down
2 changes: 0 additions & 2 deletions src/function/algebra/simplify/simplifyConstant.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ export const createSimplifyConstant = /* #__PURE__ */ factory(name, dependencies
/* falls through */
case 'RangeNode':
/* falls through */
case 'UpdateNode':
/* falls through */
case 'ConditionalNode':
/* falls through */
default:
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
createPhi,
createPi,
createSQRT2,
createSQRTHalf,
createSQRT1_2, // eslint-disable-line camelcase
createTau,
createTrue,
createUppercaseE,
Expand All @@ -46,7 +46,7 @@ export default [
createLN10,
createLOG2E,
createLOG10E,
createSQRTHalf,
createSQRT1_2, // eslint-disable-line camelcase
createSQRT2,
createI,
createVersion,
Expand Down
Loading

0 comments on commit 19bc1e0

Please sign in to comment.