nerdamer 1.1.13 → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +184 -0
- package/README.md +293 -312
- package/dist/bundle.js +2 -0
- package/dist/bundle.js.LICENSE.txt +7 -0
- package/dist/parser.js +2 -0
- package/dist/parser.js.LICENSE.txt +7 -0
- package/docs-data/parser-functions.json +1960 -0
- package/index.d.ts +10 -426
- package/output/algebra/adapters.d.ts +33 -0
- package/output/algebra/adapters.js +109 -0
- package/output/algebra/algorithms/arith.d.ts +84 -0
- package/output/algebra/algorithms/arith.js +323 -0
- package/output/algebra/algorithms/factor.d.ts +3 -0
- package/output/algebra/algorithms/factor.js +5 -0
- package/output/algebra/algorithms/factorMultivariate.d.ts +23 -0
- package/output/algebra/algorithms/factorMultivariate.js +2393 -0
- package/output/algebra/algorithms/factorUnivariate.d.ts +72 -0
- package/output/algebra/algorithms/factorUnivariate.js +1072 -0
- package/output/algebra/algorithms/gcd.d.ts +22 -0
- package/output/algebra/algorithms/gcd.js +690 -0
- package/output/algebra/algorithms/groebnerBase.d.ts +157 -0
- package/output/algebra/algorithms/groebnerBase.js +1166 -0
- package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +137 -0
- package/output/algebra/algorithms/multiPoly/MultiPoly.js +346 -0
- package/output/algebra/algorithms/poly.d.ts +228 -0
- package/output/algebra/algorithms/poly.js +1299 -0
- package/output/algebra/algorithms/rational.d.ts +17 -0
- package/output/algebra/algorithms/rational.js +115 -0
- package/output/algebra/factor/factor.d.ts +62 -0
- package/output/algebra/factor/factor.js +158 -0
- package/output/algebra/gcd/gcd.d.ts +29 -0
- package/output/algebra/gcd/gcd.js +141 -0
- package/output/algebra/groebner.d.ts +21 -0
- package/output/algebra/groebner.js +42 -0
- package/output/algebra/partfrac.d.ts +19 -0
- package/output/algebra/partfrac.js +398 -0
- package/output/algebra/polynomialize.d.ts +20 -0
- package/output/algebra/polynomialize.js +24 -0
- package/output/algebra/simplify/complexsimp.d.ts +7 -0
- package/output/algebra/simplify/complexsimp.js +24 -0
- package/output/algebra/simplify/factorCommon.d.ts +13 -0
- package/output/algebra/simplify/factorCommon.js +136 -0
- package/output/algebra/simplify/funcsimp.d.ts +26 -0
- package/output/algebra/simplify/funcsimp.js +633 -0
- package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
- package/output/algebra/simplify/invtrigrewrite.js +96 -0
- package/output/algebra/simplify/ratsimp.d.ts +21 -0
- package/output/algebra/simplify/ratsimp.js +140 -0
- package/output/algebra/simplify/simplify.d.ts +25 -0
- package/output/algebra/simplify/simplify.js +228 -0
- package/output/algebra/simplify/trigreduce.d.ts +38 -0
- package/output/algebra/simplify/trigreduce.js +424 -0
- package/output/algebra/simplify/trigrewrite.d.ts +17 -0
- package/output/algebra/simplify/trigrewrite.js +156 -0
- package/output/algebra/simplify/trigsimp.d.ts +11 -0
- package/output/algebra/simplify/trigsimp.js +369 -0
- package/output/algebra/simplify/utils.d.ts +32 -0
- package/output/algebra/simplify/utils.js +56 -0
- package/output/algebra/utils.d.ts +32 -0
- package/output/algebra/utils.js +48 -0
- package/output/api/advanced.d.ts +7 -0
- package/output/api/advanced.js +18 -0
- package/output/api/algebra.d.ts +17 -0
- package/output/api/algebra.js +32 -0
- package/output/api/assumptions.d.ts +4 -0
- package/output/api/assumptions.js +11 -0
- package/output/api/calculus.d.ts +9 -0
- package/output/api/calculus.js +21 -0
- package/output/api/core.d.ts +17 -0
- package/output/api/core.js +41 -0
- package/output/api/debug.d.ts +16 -0
- package/output/api/debug.js +23 -0
- package/output/api/parser.d.ts +85 -0
- package/output/api/parser.js +16 -0
- package/output/api/solve.d.ts +10 -0
- package/output/api/solve.js +16 -0
- package/output/api/structures.d.ts +10 -0
- package/output/api/structures.js +22 -0
- package/output/calculus/derivative/diff.d.ts +30 -0
- package/output/calculus/derivative/diff.js +238 -0
- package/output/calculus/fresnel.d.ts +16 -0
- package/output/calculus/fresnel.js +39 -0
- package/output/calculus/integrate/byParts.d.ts +18 -0
- package/output/calculus/integrate/byParts.js +339 -0
- package/output/calculus/integrate/bySubstitution.d.ts +135 -0
- package/output/calculus/integrate/bySubstitution.js +411 -0
- package/output/calculus/integrate/integrate.d.ts +38 -0
- package/output/calculus/integrate/integrate.js +652 -0
- package/output/calculus/integrate/integrationTable.d.ts +2 -0
- package/output/calculus/integrate/integrationTable.js +914 -0
- package/output/calculus/integrate/utils.d.ts +28 -0
- package/output/calculus/integrate/utils.js +96 -0
- package/output/calculus/laplace/ilaplace.d.ts +31 -0
- package/output/calculus/laplace/ilaplace.js +192 -0
- package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
- package/output/calculus/laplace/ilaplaceTable.js +200 -0
- package/output/calculus/laplace/laplace.d.ts +22 -0
- package/output/calculus/laplace/laplace.js +109 -0
- package/output/calculus/laplace/laplaceTable.d.ts +2 -0
- package/output/calculus/laplace/laplaceTable.js +187 -0
- package/output/calculus/limit/limit.d.ts +35 -0
- package/output/calculus/limit/limit.js +1183 -0
- package/output/calculus/limit/limitsTable.d.ts +2 -0
- package/output/calculus/limit/limitsTable.js +7 -0
- package/output/core/Settings.d.ts +32 -0
- package/output/core/Settings.js +68 -0
- package/output/core/adapters.d.ts +18 -0
- package/output/core/adapters.js +40 -0
- package/output/core/classes/assumption/Assumption.d.ts +218 -0
- package/output/core/classes/assumption/Assumption.js +605 -0
- package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
- package/output/core/classes/assumption/assertiveFunctions.js +64 -0
- package/output/core/classes/assumption/assume.d.ts +90 -0
- package/output/core/classes/assumption/assume.js +145 -0
- package/output/core/classes/collection/Collection.d.ts +107 -0
- package/output/core/classes/collection/Collection.js +231 -0
- package/output/core/classes/complex/Complex.d.ts +99 -0
- package/output/core/classes/complex/Complex.js +135 -0
- package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
- package/output/core/classes/decimalSet/DecimalSet.js +453 -0
- package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
- package/output/core/classes/dictionary/Dictionary.js +213 -0
- package/output/core/classes/equation/Equation.d.ts +256 -0
- package/output/core/classes/equation/Equation.js +350 -0
- package/output/core/classes/expression/CoeffObject.d.ts +100 -0
- package/output/core/classes/expression/CoeffObject.js +198 -0
- package/output/core/classes/expression/Expression.d.ts +1674 -0
- package/output/core/classes/expression/Expression.js +2332 -0
- package/output/core/classes/expression/analysis.d.ts +25 -0
- package/output/core/classes/expression/analysis.js +218 -0
- package/output/core/classes/expression/collect.d.ts +9 -0
- package/output/core/classes/expression/collect.js +49 -0
- package/output/core/classes/expression/format.d.ts +45 -0
- package/output/core/classes/expression/format.js +217 -0
- package/output/core/classes/expression/products.d.ts +23 -0
- package/output/core/classes/expression/products.js +115 -0
- package/output/core/classes/expression/shortcuts.d.ts +35 -0
- package/output/core/classes/expression/shortcuts.js +129 -0
- package/output/core/classes/expression/traversal.d.ts +31 -0
- package/output/core/classes/expression/traversal.js +216 -0
- package/output/core/classes/expression/trig.d.ts +25 -0
- package/output/core/classes/expression/trig.js +40 -0
- package/output/core/classes/expression/utils.d.ts +52 -0
- package/output/core/classes/expression/utils.js +189 -0
- package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
- package/output/core/classes/lookupTable/LookupTable.js +55 -0
- package/output/core/classes/matrix/Matrix.d.ts +227 -0
- package/output/core/classes/matrix/Matrix.js +889 -0
- package/output/core/classes/matrix/Sylvester.d.ts +11 -0
- package/output/core/classes/matrix/Sylvester.js +54 -0
- package/output/core/classes/matrix/functions.d.ts +26 -0
- package/output/core/classes/matrix/functions.js +52 -0
- package/output/core/classes/matrix/utils.d.ts +9 -0
- package/output/core/classes/matrix/utils.js +22 -0
- package/output/core/classes/parser/Parser.d.ts +480 -0
- package/output/core/classes/parser/Parser.js +1812 -0
- package/output/core/classes/parser/Token.d.ts +58 -0
- package/output/core/classes/parser/Token.js +137 -0
- package/output/core/classes/parser/constants.d.ts +160 -0
- package/output/core/classes/parser/constants.js +227 -0
- package/output/core/classes/parser/helpers.d.ts +21 -0
- package/output/core/classes/parser/helpers.js +42 -0
- package/output/core/classes/parser/operations/add.d.ts +15 -0
- package/output/core/classes/parser/operations/add.js +238 -0
- package/output/core/classes/parser/operations/comma.d.ts +7 -0
- package/output/core/classes/parser/operations/comma.js +11 -0
- package/output/core/classes/parser/operations/compare.d.ts +21 -0
- package/output/core/classes/parser/operations/compare.js +461 -0
- package/output/core/classes/parser/operations/divide.d.ts +2 -0
- package/output/core/classes/parser/operations/divide.js +72 -0
- package/output/core/classes/parser/operations/functions.d.ts +46 -0
- package/output/core/classes/parser/operations/functions.js +430 -0
- package/output/core/classes/parser/operations/multiply.d.ts +11 -0
- package/output/core/classes/parser/operations/multiply.js +321 -0
- package/output/core/classes/parser/operations/power.d.ts +48 -0
- package/output/core/classes/parser/operations/power.js +673 -0
- package/output/core/classes/parser/operations/subtract.d.ts +3 -0
- package/output/core/classes/parser/operations/subtract.js +35 -0
- package/output/core/classes/parser/preprocess.d.ts +14 -0
- package/output/core/classes/parser/preprocess.js +259 -0
- package/output/core/classes/parser/scripting/controlFlow.d.ts +121 -0
- package/output/core/classes/parser/scripting/controlFlow.js +355 -0
- package/output/core/classes/parser/scripting/evaluate.d.ts +10 -0
- package/output/core/classes/parser/scripting/evaluate.js +112 -0
- package/output/core/classes/parser/scripting/functions.d.ts +14 -0
- package/output/core/classes/parser/scripting/functions.js +59 -0
- package/output/core/classes/parser/scripting/scope.d.ts +35 -0
- package/output/core/classes/parser/scripting/scope.js +155 -0
- package/output/core/classes/parser/types.d.ts +125 -0
- package/output/core/classes/parser/types.js +2 -0
- package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
- package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
- package/output/core/classes/polynomial/Polynomial.d.ts +500 -0
- package/output/core/classes/polynomial/Polynomial.js +1149 -0
- package/output/core/classes/polynomial/Term.d.ts +222 -0
- package/output/core/classes/polynomial/Term.js +430 -0
- package/output/core/classes/polynomial/functions.d.ts +69 -0
- package/output/core/classes/polynomial/functions.js +126 -0
- package/output/core/classes/polynomial/utils.d.ts +62 -0
- package/output/core/classes/polynomial/utils.js +206 -0
- package/output/core/classes/rational/Rational.d.ts +504 -0
- package/output/core/classes/rational/Rational.js +779 -0
- package/output/core/classes/seq/SEQ.d.ts +13 -0
- package/output/core/classes/seq/SEQ.js +137 -0
- package/output/core/classes/valuesSet/ValuesSet.d.ts +179 -0
- package/output/core/classes/valuesSet/ValuesSet.js +381 -0
- package/output/core/classes/vector/Vector.d.ts +222 -0
- package/output/core/classes/vector/Vector.js +497 -0
- package/output/core/classes/vector/functions.d.ts +28 -0
- package/output/core/classes/vector/functions.js +47 -0
- package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
- package/output/core/common/classes/MathematicalAggregate.js +140 -0
- package/output/core/common/classes/Scope.d.ts +62 -0
- package/output/core/common/classes/Scope.js +122 -0
- package/output/core/common/classes/StructuredEntity.d.ts +55 -0
- package/output/core/common/classes/StructuredEntity.js +151 -0
- package/output/core/common/common.d.ts +63 -0
- package/output/core/common/common.js +279 -0
- package/output/core/common/functions/functions.d.ts +14 -0
- package/output/core/common/functions/functions.js +33 -0
- package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
- package/output/core/common/functions/structuredEntityUtils.js +40 -0
- package/output/core/converters/BaseConverter.d.ts +97 -0
- package/output/core/converters/BaseConverter.js +405 -0
- package/output/core/converters/Converter.d.ts +111 -0
- package/output/core/converters/Converter.js +802 -0
- package/output/core/converters/Pattern.d.ts +71 -0
- package/output/core/converters/Pattern.js +302 -0
- package/output/core/dispatch.d.ts +34 -0
- package/output/core/dispatch.js +304 -0
- package/output/core/errors.d.ts +531 -0
- package/output/core/errors.js +621 -0
- package/output/core/functions/bigint/bigint.d.ts +121 -0
- package/output/core/functions/bigint/bigint.js +392 -0
- package/output/core/functions/bigint/primeFactor.d.ts +49 -0
- package/output/core/functions/bigint/primeFactor.js +267 -0
- package/output/core/functions/bigint/primes.d.ts +1 -0
- package/output/core/functions/bigint/primes.js +11 -0
- package/output/core/functions/build/definitions.d.ts +12 -0
- package/output/core/functions/build/definitions.js +133 -0
- package/output/core/functions/build/index.d.ts +32 -0
- package/output/core/functions/build/index.js +136 -0
- package/output/core/functions/complex.d.ts +90 -0
- package/output/core/functions/complex.js +482 -0
- package/output/core/functions/decimal.d.ts +24 -0
- package/output/core/functions/decimal.js +664 -0
- package/output/core/functions/expand/expand.d.ts +42 -0
- package/output/core/functions/expand/expand.js +376 -0
- package/output/core/functions/fresnelNumeric.d.ts +12 -0
- package/output/core/functions/fresnelNumeric.js +123 -0
- package/output/core/functions/numeric.d.ts +140 -0
- package/output/core/functions/numeric.js +790 -0
- package/output/core/functions/rationalNormalization.d.ts +11 -0
- package/output/core/functions/rationalNormalization.js +117 -0
- package/output/core/functions/setFunction.d.ts +19 -0
- package/output/core/functions/setFunction.js +75 -0
- package/output/core/functions/string.d.ts +26 -0
- package/output/core/functions/string.js +101 -0
- package/output/core/functions/subst.d.ts +90 -0
- package/output/core/functions/subst.js +498 -0
- package/output/core/functions/utils.d.ts +24 -0
- package/output/core/functions/utils.js +51 -0
- package/output/core/types.d.ts +48 -0
- package/output/core/types.js +2 -0
- package/output/index.d.ts +339 -0
- package/output/index.js +715 -0
- package/output/math/defint/defintDecimal.d.ts +37 -0
- package/output/math/defint/defintDecimal.js +320 -0
- package/output/math/defint/defintNative.d.ts +57 -0
- package/output/math/defint/defintNative.js +292 -0
- package/output/math/geometry.d.ts +8 -0
- package/output/math/geometry.js +32 -0
- package/output/math/math.d.ts +655 -0
- package/output/math/math.js +1811 -0
- package/output/math/trig.d.ts +518 -0
- package/output/math/trig.js +1444 -0
- package/output/math/trunc.d.ts +19 -0
- package/output/math/trunc.js +36 -0
- package/output/math/utils.d.ts +60 -0
- package/output/math/utils.js +180 -0
- package/output/solve/classes/DecimalMatrix.d.ts +17 -0
- package/output/solve/classes/DecimalMatrix.js +86 -0
- package/output/solve/classes/FunctionSolver.d.ts +135 -0
- package/output/solve/classes/FunctionSolver.js +433 -0
- package/output/solve/classes/MultivariateSolver.d.ts +84 -0
- package/output/solve/classes/MultivariateSolver.js +240 -0
- package/output/solve/classes/PolynomialSolver.d.ts +85 -0
- package/output/solve/classes/PolynomialSolver.js +292 -0
- package/output/solve/classes/SolutionSet.d.ts +153 -0
- package/output/solve/classes/SolutionSet.js +357 -0
- package/output/solve/classes/Solver.d.ts +17 -0
- package/output/solve/classes/Solver.js +132 -0
- package/output/solve/classes/SymbolicSolver.d.ts +74 -0
- package/output/solve/classes/SymbolicSolver.js +601 -0
- package/output/solve/linsolve.d.ts +51 -0
- package/output/solve/linsolve.js +225 -0
- package/output/solve/solve.d.ts +34 -0
- package/output/solve/solve.js +260 -0
- package/output/solve/solveSystem.d.ts +31 -0
- package/output/solve/solveSystem.js +290 -0
- package/output/solve/utils.d.ts +9 -0
- package/output/solve/utils.js +62 -0
- package/output/utils/array.d.ts +42 -0
- package/output/utils/array.js +98 -0
- package/output/utils/debug.d.ts +131 -0
- package/output/utils/debug.js +295 -0
- package/output/utils/decimal.d.ts +3 -0
- package/output/utils/decimal.js +16 -0
- package/output/utils/numeric.d.ts +14 -0
- package/output/utils/numeric.js +51 -0
- package/output/utils/object.d.ts +26 -0
- package/output/utils/object.js +56 -0
- package/package.json +213 -57
- package/.travis.yml +0 -3
- package/Algebra.js +0 -4568
- package/BREAKING_CHANGES.md +0 -5
- package/CODE_OF_CONDUCT.md +0 -46
- package/CONTRIBUTING.md +0 -14
- package/Calculus.js +0 -2675
- package/Extra.js +0 -622
- package/Solve.js +0 -1783
- package/all.js +0 -16
- package/all.min.js +0 -1
- package/gulpfile.js +0 -16
- package/index.html +0 -158
- package/license.txt +0 -19
- package/nerdamer.core.js +0 -12510
- package/spec/LaTeX.spec.js +0 -302
- package/spec/TeXConvert.spec.js +0 -8
- package/spec/algebra.spec.js +0 -287
- package/spec/basic_parser.spec.js +0 -134
- package/spec/build.spec.js +0 -131
- package/spec/calculus.spec.js +0 -183
- package/spec/core.spec.js +0 -2970
- package/spec/extra.spec.js +0 -54
- package/spec/solve.spec.js +0 -126
- package/spec/support/jasmine.json +0 -11
- package/spec/support/utils.js +0 -42
- package/spec/text.spec.js +0 -132
package/spec/core.spec.js
DELETED
|
@@ -1,2970 +0,0 @@
|
|
|
1
|
-
/* global expect */
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
var nerdamer = require('../nerdamer.core.js');
|
|
6
|
-
|
|
7
|
-
var utils = require('./support/utils');
|
|
8
|
-
var _ = utils.toFixed;
|
|
9
|
-
var run = utils.run;
|
|
10
|
-
var core = nerdamer.getCore();
|
|
11
|
-
var round = core.Utils.round;
|
|
12
|
-
var block = core.Utils.block;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//, x=2.1, y=3.3, z=1, a=7.42
|
|
16
|
-
var values = {
|
|
17
|
-
x: 2.1,
|
|
18
|
-
y: 3.3,
|
|
19
|
-
z: 1,
|
|
20
|
-
a: 7.42
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
describe('Nerdamer core', function () {
|
|
24
|
-
it('should perform simple arithmetic', function () {
|
|
25
|
-
// given
|
|
26
|
-
var testCases = [
|
|
27
|
-
{
|
|
28
|
-
given: '((((((1+1))))))',
|
|
29
|
-
expected: '2',
|
|
30
|
-
expectedValue: '2'
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
given: '((((((1+1))+4)))+3)',
|
|
34
|
-
expected: '9',
|
|
35
|
-
expectedValue: '9'
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
given: '1+1',
|
|
39
|
-
expected: '2',
|
|
40
|
-
expectedValue: '2'
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
given: '4^2',
|
|
44
|
-
expected: '16',
|
|
45
|
-
expectedValue: '16'
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
given: '2*-4',
|
|
49
|
-
expected: '-8',
|
|
50
|
-
expectedValue: '-8'
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
given: '2+(3/4)',
|
|
54
|
-
expected: '11/4',
|
|
55
|
-
expectedValue: '2.75'
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
given: '2/3+2/3',
|
|
59
|
-
expected: '4/3',
|
|
60
|
-
expectedValue: '1.3333333333333333'
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
given: '6.5*2',
|
|
64
|
-
expected: '13',
|
|
65
|
-
expectedValue: '13'
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
given: '(11.85)^(1/2)',
|
|
69
|
-
expected: '(1/2)*sqrt(237)*sqrt(5)^(-1)',
|
|
70
|
-
expectedValue: '3.4423828956117015'
|
|
71
|
-
}
|
|
72
|
-
];
|
|
73
|
-
|
|
74
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
75
|
-
// when
|
|
76
|
-
var parsed = nerdamer(testCases[i].given);
|
|
77
|
-
var value = parsed.evaluate().text('decimals');
|
|
78
|
-
|
|
79
|
-
// then
|
|
80
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
81
|
-
expect(round(value), 14).toEqual(round(testCases[i].expectedValue) ,14);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
it('should handle minus sign properly', function () {
|
|
85
|
-
// given
|
|
86
|
-
var cases = [
|
|
87
|
-
{
|
|
88
|
-
given: '0-4',
|
|
89
|
-
expected: '-4'
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
given: '-(4)',
|
|
93
|
-
expected: '-4'
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
given: '3*-(4)',
|
|
97
|
-
expected: '-12'
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
given: '-3*-(4)',
|
|
101
|
-
expected: '12'
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
given: '-(3*-(4))',
|
|
105
|
-
expected: '12'
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
given: '-(-3*-(4))',
|
|
109
|
-
expected: '-12'
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
given: '-(3)-3',
|
|
113
|
-
expected: '-6'
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
given: '3^-1^-1',
|
|
117
|
-
expected: '1/3'
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
given: '-1',
|
|
121
|
-
expected: '-1'
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
given: '--1',
|
|
125
|
-
expected: '1'
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
given: '8-1',
|
|
129
|
-
expected: '7'
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
given: '(-1)',
|
|
133
|
-
expected: '-1'
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
given: '-(1)-1',
|
|
137
|
-
expected: '-2'
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
given: '-(-1-1)',
|
|
141
|
-
expected: '2'
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
given: '-(-1-+1)^2',
|
|
145
|
-
expected: '-4'
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
given: '-(-1-1+1)',
|
|
149
|
-
expected: '1'
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
given: '-(1)--(1-1--1)',
|
|
153
|
-
expected: '0'
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
given: '-(-(1))-(--1)',
|
|
157
|
-
expected: '0'
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
given: '5^-3',
|
|
161
|
-
expected: '1/125'
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
given: '5^---3',
|
|
165
|
-
expected: '1/125'
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
given: '5^-(1--2)',
|
|
169
|
-
expected: '1/125'
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
given: '5^-(++1+--+2)',
|
|
173
|
-
expected: '1/125'
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
given: '(5^-(++1+--+2))^-2',
|
|
177
|
-
expected: '15625'
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
given: '(5^-3^2)',
|
|
181
|
-
expected: '1/1953125'
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
given: '(5^-3^-2)',
|
|
185
|
-
expected: '5^(-1/9)'
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
given: '-(5^-3^-2)^-3',
|
|
189
|
-
expected: '-5^(1/3)'
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
given: '-(--5*--7)',
|
|
193
|
-
expected: '-35'
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
given: '(-1)^(3/4)',
|
|
197
|
-
expected: '(-1)^(3/4)'
|
|
198
|
-
}
|
|
199
|
-
];
|
|
200
|
-
|
|
201
|
-
for (var k in cases) {
|
|
202
|
-
// when
|
|
203
|
-
var parsed = nerdamer(cases[k].given);
|
|
204
|
-
// then
|
|
205
|
-
expect(parsed.toString()).toEqual(cases[k].expected);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
it('should perform simple calculations with variables', function () {
|
|
209
|
-
// given
|
|
210
|
-
var testCases = [
|
|
211
|
-
{
|
|
212
|
-
given: 'x+x',
|
|
213
|
-
expected: '2*x',
|
|
214
|
-
expectedValue: '4.2'
|
|
215
|
-
}, {
|
|
216
|
-
given: 'x+1',
|
|
217
|
-
expected: '1+x',
|
|
218
|
-
expectedValue: '3.1'
|
|
219
|
-
}, {
|
|
220
|
-
given: 'x+y',
|
|
221
|
-
expected: 'x+y',
|
|
222
|
-
expectedValue: '5.4'
|
|
223
|
-
}, {
|
|
224
|
-
given: '-9-x+y-11',
|
|
225
|
-
expected: '-20-x+y',
|
|
226
|
-
expectedValue: '-18.8'
|
|
227
|
-
}, {
|
|
228
|
-
given: '(x+1)+(1+x)',
|
|
229
|
-
expected: '2+2*x',
|
|
230
|
-
expectedValue: '6.2'
|
|
231
|
-
}, {
|
|
232
|
-
given: '9+(x+1)-(1+x)',
|
|
233
|
-
expected: '9',
|
|
234
|
-
expectedValue: '9'
|
|
235
|
-
}, {
|
|
236
|
-
given: '0-x-2*x+6',
|
|
237
|
-
expected: '-3*x+6',
|
|
238
|
-
expectedValue: '-0.3'
|
|
239
|
-
}, {
|
|
240
|
-
given: '(x+y)+(a+x)',
|
|
241
|
-
expected: '2*x+a+y',
|
|
242
|
-
expectedValue: '14.92'
|
|
243
|
-
}, {
|
|
244
|
-
given: '7*(x+y)+2*(a+x)',
|
|
245
|
-
expected: '2*a+7*y+9*x',
|
|
246
|
-
expectedValue: '56.84'
|
|
247
|
-
}, {
|
|
248
|
-
given: 'x^y+x^y',
|
|
249
|
-
expected: '2*x^y',
|
|
250
|
-
expectedValue: '23.13948390048293'
|
|
251
|
-
}, {
|
|
252
|
-
given: 'x*x',
|
|
253
|
-
expected: 'x^2',
|
|
254
|
-
expectedValue: '4.41'
|
|
255
|
-
}, {
|
|
256
|
-
given: '-x*x',
|
|
257
|
-
expected: '-x^2',
|
|
258
|
-
expectedValue: '-4.41'
|
|
259
|
-
}, {
|
|
260
|
-
given: '-x*-x',
|
|
261
|
-
expected: 'x^2',
|
|
262
|
-
expectedValue: '4.41'
|
|
263
|
-
}, {
|
|
264
|
-
given: 'x-y',
|
|
265
|
-
expected: '-y+x',
|
|
266
|
-
expectedValue: '-1.2'
|
|
267
|
-
}, {
|
|
268
|
-
given: 'x-x',
|
|
269
|
-
expected: '0',
|
|
270
|
-
expectedValue: '0'
|
|
271
|
-
}, {
|
|
272
|
-
given: 'x*2',
|
|
273
|
-
expected: '2*x',
|
|
274
|
-
expectedValue: '4.2'
|
|
275
|
-
}, {
|
|
276
|
-
given: 'x*y',
|
|
277
|
-
expected: 'x*y',
|
|
278
|
-
expectedValue: '6.93'
|
|
279
|
-
}, {
|
|
280
|
-
given: 'x^x',
|
|
281
|
-
expected: 'x^x',
|
|
282
|
-
expectedValue: '4.749638091742242'
|
|
283
|
-
}, {
|
|
284
|
-
given: 'x^(x)',
|
|
285
|
-
expected: 'x^x',
|
|
286
|
-
expectedValue: '4.749638091742242'
|
|
287
|
-
}, {
|
|
288
|
-
given: 'y^y^3',
|
|
289
|
-
expected: 'y^y^3',
|
|
290
|
-
expectedValue: '4303635263255155700'
|
|
291
|
-
},
|
|
292
|
-
{
|
|
293
|
-
given: '(x-1)^2+(x-1)^2',
|
|
294
|
-
expected: '2*(-1+x)^2',
|
|
295
|
-
expectedValue: '2.4200000000000004'
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
given: '(-5(x/2-5)/4)^0',
|
|
299
|
-
expected: '1',
|
|
300
|
-
expectedValue: '1'
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
given: '((1+x)^(-2))+((1+x)^(-1))+((1+x)^(-1))+(1)',
|
|
304
|
-
expected: '(1+x)^(-2)+2*(1+x)^(-1)+1',
|
|
305
|
-
expectedValue: '1.74921956295526'
|
|
306
|
-
}
|
|
307
|
-
];
|
|
308
|
-
|
|
309
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
310
|
-
// when
|
|
311
|
-
var parsed = nerdamer(testCases[i].given);
|
|
312
|
-
var value = parsed.evaluate(values).text('decimals');
|
|
313
|
-
|
|
314
|
-
// then
|
|
315
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
316
|
-
expect(round(value), 14).toEqual(round(testCases[i].expectedValue) ,14);
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
it('should handle errors', function () {
|
|
320
|
-
var formulas = [
|
|
321
|
-
'0/0',
|
|
322
|
-
'0^0',
|
|
323
|
-
'-Infinity+Infinity',
|
|
324
|
-
'Infinity/Infinity',
|
|
325
|
-
'Infinity^Infinity',
|
|
326
|
-
'1^Infinity',
|
|
327
|
-
'Infinity^0',
|
|
328
|
-
'(-Infinity)^0',
|
|
329
|
-
'Infinity*0'
|
|
330
|
-
];
|
|
331
|
-
|
|
332
|
-
for(var i=0; i<formulas.length; i++)
|
|
333
|
-
expect(function (){ nerdamer(formulas[i]) }).toThrowError();
|
|
334
|
-
});
|
|
335
|
-
it('should set postfix operators correctly', function () {
|
|
336
|
-
var core = nerdamer.getCore();
|
|
337
|
-
var _ = core.PARSER;
|
|
338
|
-
var Symbol = core.Symbol;
|
|
339
|
-
nerdamer.setOperator({
|
|
340
|
-
precedence: 4,
|
|
341
|
-
operator: '°',
|
|
342
|
-
postfix: true,
|
|
343
|
-
operation: function(x){
|
|
344
|
-
return _.divide(_.multiply(x, new Symbol('pi')), new Symbol(180));
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
expect(nerdamer('x+1°+π+x').toString()).toEqual('(181/180)*pi+2*x');
|
|
349
|
-
});
|
|
350
|
-
it('should correctly calculate Infinity', function () {
|
|
351
|
-
// given
|
|
352
|
-
var testCases = [
|
|
353
|
-
{
|
|
354
|
-
given: '0^Infinity',
|
|
355
|
-
expected: '0'
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
given: 'Infinity*Infinity',
|
|
359
|
-
expected: 'Infinity'
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
given: '-Infinity*Infinity',
|
|
363
|
-
expected: '-Infinity'
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
given: '-Infinity*-Infinity',
|
|
367
|
-
expected: 'Infinity'
|
|
368
|
-
},
|
|
369
|
-
{
|
|
370
|
-
given: '-a*-Infinity',
|
|
371
|
-
expected: 'Infinity*a'
|
|
372
|
-
},
|
|
373
|
-
{
|
|
374
|
-
given: '-a-Infinity',
|
|
375
|
-
expected: '-Infinity'
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
given: '-a*Infinity',
|
|
379
|
-
expected: '-Infinity*a'
|
|
380
|
-
},
|
|
381
|
-
{
|
|
382
|
-
given: '-a^Infinity',
|
|
383
|
-
expected: '-a^Infinity'
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
given: '-2^Infinity',
|
|
387
|
-
expected: '-Infinity'
|
|
388
|
-
},
|
|
389
|
-
{
|
|
390
|
-
given: '-2^-Infinity',
|
|
391
|
-
expected: '0'
|
|
392
|
-
},
|
|
393
|
-
|
|
394
|
-
];
|
|
395
|
-
|
|
396
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
397
|
-
// when
|
|
398
|
-
var parsed = nerdamer(testCases[i].given);
|
|
399
|
-
// then
|
|
400
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
it('should calculate fib correctly', function () {
|
|
404
|
-
// given
|
|
405
|
-
var testCases = [
|
|
406
|
-
{
|
|
407
|
-
given: 'fib(0)',
|
|
408
|
-
expected: '0'
|
|
409
|
-
},
|
|
410
|
-
{
|
|
411
|
-
given: 'fib(14)',
|
|
412
|
-
expected: '377'
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
given: 'fib(-14)',
|
|
416
|
-
expected: '-377'
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
given: 'fib(15)',
|
|
420
|
-
expected: '610'
|
|
421
|
-
},
|
|
422
|
-
{
|
|
423
|
-
given: 'fib(-15)',
|
|
424
|
-
expected: '610'
|
|
425
|
-
}
|
|
426
|
-
];
|
|
427
|
-
|
|
428
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
429
|
-
// when
|
|
430
|
-
var parsed = nerdamer(testCases[i].given).evaluate();
|
|
431
|
-
// then
|
|
432
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
it('should calculate sinc correctly', function () {
|
|
436
|
-
// given
|
|
437
|
-
var testCases = [
|
|
438
|
-
{
|
|
439
|
-
given: 'sinc(x)',
|
|
440
|
-
expected: 'sinc(x)',
|
|
441
|
-
eval: false
|
|
442
|
-
},
|
|
443
|
-
{
|
|
444
|
-
given: 'sinc(0)',
|
|
445
|
-
expected: '1',
|
|
446
|
-
eval: true
|
|
447
|
-
},
|
|
448
|
-
{
|
|
449
|
-
given: 'sinc(9)',
|
|
450
|
-
expected: '23287849/508568891',
|
|
451
|
-
eval: true
|
|
452
|
-
},
|
|
453
|
-
{
|
|
454
|
-
given: 'sinc(x-a)-sin(x-a)/(x-a)',
|
|
455
|
-
expected: '0',
|
|
456
|
-
eval: true
|
|
457
|
-
}
|
|
458
|
-
];
|
|
459
|
-
|
|
460
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
461
|
-
var testCase = testCases[i];
|
|
462
|
-
// when
|
|
463
|
-
var parsed = testCase.eval ? nerdamer(testCase.given).evaluate() : nerdamer(testCase.given);
|
|
464
|
-
|
|
465
|
-
// then
|
|
466
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
it('should expand terms', function () {
|
|
470
|
-
// given
|
|
471
|
-
var testCases = [
|
|
472
|
-
{
|
|
473
|
-
given: 'expand((9*y*x+1)^3)',
|
|
474
|
-
expected: '1+243*x^2*y^2+27*x*y+729*x^3*y^3',
|
|
475
|
-
expectedValue: '254478.51475300005'
|
|
476
|
-
},
|
|
477
|
-
{
|
|
478
|
-
given: 'expand(x*(x+1))',
|
|
479
|
-
expected: 'x+x^2',
|
|
480
|
-
expectedValue: '6.51'
|
|
481
|
-
},
|
|
482
|
-
{
|
|
483
|
-
given: 'expand(x*(x+1)^5)',
|
|
484
|
-
expected: '10*x^3+10*x^4+5*x^2+5*x^5+x+x^6',
|
|
485
|
-
expectedValue: '601.212171'
|
|
486
|
-
},
|
|
487
|
-
{
|
|
488
|
-
given: 'expand((x*y)^x+(x*y)^2)',
|
|
489
|
-
expected: '(x*y)^x+x^2*y^2',
|
|
490
|
-
expectedValue: '106.3076174497575'
|
|
491
|
-
},
|
|
492
|
-
{
|
|
493
|
-
given: 'expand((3*x+4*y)^4)',
|
|
494
|
-
expected: '256*y^4+432*x^3*y+768*x*y^3+81*x^4+864*x^2*y^2',
|
|
495
|
-
expectedValue: '144590.0625'
|
|
496
|
-
},
|
|
497
|
-
{
|
|
498
|
-
given: 'expand((9*y*x+1)^2)',
|
|
499
|
-
expected: '1+18*x*y+81*x^2*y^2',
|
|
500
|
-
expectedValue: '4015.7568999999994'
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
given: 'expand((x+5)*(x-3)-x^2)',
|
|
504
|
-
expected: '-15+2*x',
|
|
505
|
-
expectedValue: '-10.8'
|
|
506
|
-
},
|
|
507
|
-
{
|
|
508
|
-
given: 'expand(((x^3+x)^x*(x^2+x)^x+1)*x)',
|
|
509
|
-
expected: '(x+x^2)^x*(x+x^3)^x*x+x',
|
|
510
|
-
expectedValue: '17667.12052556627'
|
|
511
|
-
},
|
|
512
|
-
];
|
|
513
|
-
|
|
514
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
515
|
-
// when
|
|
516
|
-
var parsed = nerdamer(testCases[i].given);
|
|
517
|
-
var value = parsed.evaluate(values).text('decimals');
|
|
518
|
-
|
|
519
|
-
// then
|
|
520
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
521
|
-
expect(round(value, 12)).toEqual(round(testCases[i].expectedValue, 12)) ;
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
it('should expand correctly', function() {
|
|
525
|
-
expect(nerdamer('expand((a^2*b*c)^(-1))').toString()).toEqual('a^(-2)*b^(-1)*c^(-1)');
|
|
526
|
-
expect(nerdamer('expand(((a^2*b)(x+1))^2)').toString()).toEqual('2*a^4*b^2*x+a^4*b^2+a^4*b^2*x^2');
|
|
527
|
-
expect(nerdamer('expand(5*x/(c+d)^2)').toString()).toEqual('5*(2*c*d+c^2+d^2)^(-1)*x');
|
|
528
|
-
expect(nerdamer('expand((a+b)*(c+d))').toString()).toEqual('a*c+a*d+b*c+b*d');
|
|
529
|
-
expect(nerdamer('expand(5*(a+b)*(c+d))').toString()).toEqual('5*a*c+5*a*d+5*b*c+5*b*d');
|
|
530
|
-
expect(nerdamer('expand(4*parens(x+1)^2)').toString()).toEqual('4+4*x^2+8*x');
|
|
531
|
-
expect(nerdamer('expand(4*(a*b)*(c*b))').toString()).toEqual('4*a*b^2*c');
|
|
532
|
-
expect(nerdamer('expand(4*(a*b)*(c*b)+1)').toString()).toEqual('1+4*a*b^2*c');
|
|
533
|
-
expect(nerdamer('expand(3*(a+b)*(g+i)*(x*k))').toString()).toEqual('3*a*g*k*x+3*a*i*k*x+3*b*g*k*x+3*b*i*k*x');
|
|
534
|
-
expect(nerdamer('expand(2*x*(x+1)^3)').toString()).toEqual('2*x+2*x^4+6*x^2+6*x^3');
|
|
535
|
-
expect(nerdamer('expand((2*(a*b)*(x+1)^3)^2)').toString()).toEqual('24*a^2*b^2*x+24*a^2*b^2*x^5+4*a^2*b^2+4*a^2*b^2*x^6+60*a^2*b^2*x^2+60*a^2*b^2*x^4+80*a^2*b^2*x^3');
|
|
536
|
-
expect(nerdamer('expand((2*(a*b)*(x+1)^3)^2+1)').toString()).toEqual('1+24*a^2*b^2*x+24*a^2*b^2*x^5+4*a^2*b^2+4*a^2*b^2*x^6+60*a^2*b^2*x^2+60*a^2*b^2*x^4+80*a^2*b^2*x^3');
|
|
537
|
-
expect(nerdamer('expand((d/(x+1)+1)^2)').toString()).toEqual('(1+2*x+x^2)^(-1)*d^2+1+2*(1+x)^(-1)*d');
|
|
538
|
-
expect(nerdamer('expand(2*cos((d/(x+1)+1)^2)^2)').toString()).toEqual('2*cos((1+2*x+x^2)^(-1)*d^2+1+2*(1+x)^(-1)*d)^2');
|
|
539
|
-
});
|
|
540
|
-
it('should handle imaginary log arguments', function () {
|
|
541
|
-
// given
|
|
542
|
-
var testCases = [
|
|
543
|
-
{
|
|
544
|
-
given: 'log(5*i)',
|
|
545
|
-
expected: '1.5707963267948966*i+1.6094379124341003'
|
|
546
|
-
},
|
|
547
|
-
{
|
|
548
|
-
given: 'log(8+5*i)',
|
|
549
|
-
expected: '0.5585993153435624*i+2.2443181848660699'
|
|
550
|
-
},
|
|
551
|
-
{
|
|
552
|
-
given: 'log(123-2*i)',
|
|
553
|
-
expected: '-0.01625872980512958*i+4.8123165343435139'
|
|
554
|
-
},
|
|
555
|
-
{
|
|
556
|
-
given: 'log(123-2*i+a)',
|
|
557
|
-
expected: 'log(-2*i+123+a)'
|
|
558
|
-
},
|
|
559
|
-
/*
|
|
560
|
-
{
|
|
561
|
-
given: 'log(123-2*i+a)',
|
|
562
|
-
expected: '-atan2(123+a,-2)*i+1.5707963267948966*i+log(sqrt((123+a)^2+4))'
|
|
563
|
-
},
|
|
564
|
-
{
|
|
565
|
-
given: 'log(x+2*i)',
|
|
566
|
-
expected: '-atan2(x,2)*i+1.5707963267948966*i+log(sqrt(4+x^2))'
|
|
567
|
-
}
|
|
568
|
-
*/
|
|
569
|
-
];
|
|
570
|
-
|
|
571
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
572
|
-
// when
|
|
573
|
-
var parsed = nerdamer(testCases[i].given);
|
|
574
|
-
var value = parsed.evaluate().text('decimals', 17);
|
|
575
|
-
|
|
576
|
-
// then
|
|
577
|
-
expect(value).toEqual(testCases[i].expected);
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
|
-
it('should convert from polar to rectangular', function () {
|
|
581
|
-
// given
|
|
582
|
-
var testCases = [
|
|
583
|
-
{
|
|
584
|
-
given: 'rectform(sqrt(34)*e^(i*atan(3/5)))',
|
|
585
|
-
expected: '3*i+5'
|
|
586
|
-
},
|
|
587
|
-
//PENDING:
|
|
588
|
-
//(-1)^(1/4)*sqrt(2)
|
|
589
|
-
];
|
|
590
|
-
|
|
591
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
592
|
-
// when
|
|
593
|
-
var parsed = nerdamer(testCases[i].given);
|
|
594
|
-
var value = parsed.evaluate().text('decimals');
|
|
595
|
-
|
|
596
|
-
// then
|
|
597
|
-
expect(value).toEqual(testCases[i].expected);
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
it('should convert from rectangular to polar', function () {
|
|
601
|
-
// given
|
|
602
|
-
var testCases = [
|
|
603
|
-
{
|
|
604
|
-
given: 'polarform(3*i+5)',
|
|
605
|
-
expected: 'e^(atan(3/5)*i)*sqrt(34)'
|
|
606
|
-
},
|
|
607
|
-
{
|
|
608
|
-
given: 'polarform(i-1)',
|
|
609
|
-
expected: '(i*sqrt(2)^(-1)+sqrt(2)^(-1))*sqrt(2)'
|
|
610
|
-
},
|
|
611
|
-
{
|
|
612
|
-
given: 'polarform(i+1)',
|
|
613
|
-
expected: 'e^(atan(1)*i)*sqrt(2)'
|
|
614
|
-
},
|
|
615
|
-
{
|
|
616
|
-
given: 'polarform(a*i+b*1)',
|
|
617
|
-
expected: 'e^(atan(a*b^(-1))*i)*sqrt(a^2+b^2)'
|
|
618
|
-
},
|
|
619
|
-
{
|
|
620
|
-
given: 'polarform(3)',
|
|
621
|
-
expected: '3'
|
|
622
|
-
},
|
|
623
|
-
{
|
|
624
|
-
given: 'polarform(i)',
|
|
625
|
-
expected: 'i'
|
|
626
|
-
},
|
|
627
|
-
];
|
|
628
|
-
|
|
629
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
630
|
-
// when
|
|
631
|
-
var parsed = nerdamer(testCases[i].given);
|
|
632
|
-
var value = parsed.toString();
|
|
633
|
-
|
|
634
|
-
// then
|
|
635
|
-
expect(value).toEqual(testCases[i].expected);
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
it('should compute powers', function () {
|
|
639
|
-
// given
|
|
640
|
-
var testCases = [
|
|
641
|
-
{
|
|
642
|
-
given: '0^(1/2)',
|
|
643
|
-
expected: '0',
|
|
644
|
-
expectedValue: '0'
|
|
645
|
-
},
|
|
646
|
-
{
|
|
647
|
-
given: '2^(1/2)',
|
|
648
|
-
expected: 'sqrt(2)',
|
|
649
|
-
expectedValue: '1.4142135623730951'
|
|
650
|
-
},
|
|
651
|
-
{
|
|
652
|
-
given: '3/4/-5/7',
|
|
653
|
-
expected: '-3/140',
|
|
654
|
-
expectedValue: '-0.02142857142857143'
|
|
655
|
-
},
|
|
656
|
-
{
|
|
657
|
-
given: '(2/5)^(1/2)',
|
|
658
|
-
expected: 'sqrt(2)*sqrt(5)^(-1)',
|
|
659
|
-
expectedValue: '0.6324555320336757'
|
|
660
|
-
},
|
|
661
|
-
{
|
|
662
|
-
given: '2^(1/2)+sqrt(2)',
|
|
663
|
-
expected: '2*sqrt(2)',
|
|
664
|
-
expectedValue: '2.8284271247461903'
|
|
665
|
-
}
|
|
666
|
-
];
|
|
667
|
-
|
|
668
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
669
|
-
// when
|
|
670
|
-
var parsed = nerdamer(testCases[i].given);
|
|
671
|
-
var value = parsed.evaluate(values).text('decimals');
|
|
672
|
-
|
|
673
|
-
// then
|
|
674
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
675
|
-
expect(round(value), 14).toEqual(round(testCases[i].expectedValue) ,14);
|
|
676
|
-
}
|
|
677
|
-
});
|
|
678
|
-
it('should handle large exponents', function() {
|
|
679
|
-
expect(nerdamer("((0.06/3650))^(365)").toString()).toEqual('1410126170338158616048224728371571380367482072097134683678107761'+
|
|
680
|
-
'52508851857709566371341862240808591002757985609412198322971415396168976254349069'+
|
|
681
|
-
'9072942506404339112922628405843/22958690276909851695578696288325771692413979062611'+
|
|
682
|
-
'991343897836236337139161946070457727457304403772796893304635803331160164612018173513'+
|
|
683
|
-
'31134891165302696107379996154818718135122744754040421370203240041207474864695474953483'+
|
|
684
|
-
'0902803016857824896441156744745927014013655670039876606817604403974679132586661890547851'+
|
|
685
|
-
'679296531769750182377028054935351721036749094036432130424970214049875323757624442119121774'+
|
|
686
|
-
'055322139084444881193088085062373618050647934648517067336395372063877340185058649456212635239'+
|
|
687
|
-
'066781525382959311599987961299501210179615619443916881386730704082805297329446411862362398493471'+
|
|
688
|
-
'826680176950800344487654991092708947796616392537184126525313140738179830882678244141981560034679553'+
|
|
689
|
-
'975783364407913480224860273677558689624530555494789243375386735721249700734052057353034685422151396642'+
|
|
690
|
-
'918026922556798918041766876185384884777704756416389503981017717926985777672007862927270802670740330468020'+
|
|
691
|
-
'802233942408161027975787463864142754167881620056649731281986417206144622511945116440478852141832742043753412'+
|
|
692
|
-
'722079707428689254358366463206869962206219178342509475906640460010907598207195708896768921596249362559252745779'+
|
|
693
|
-
'251530796907715219008462775395896084216357246887696419435087591409683227539062500000000000000000000000000000000000'+
|
|
694
|
-
'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'+
|
|
695
|
-
'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'+
|
|
696
|
-
'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'+
|
|
697
|
-
'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'+
|
|
698
|
-
'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'+
|
|
699
|
-
'00000000000000000000000000000000000000000000000000000000000000000000000000000000'
|
|
700
|
-
);
|
|
701
|
-
expect(nerdamer("1000*(1+(0.06/365))^(365*3)").evaluate().text()).toEqual('1197.199652936753887236');
|
|
702
|
-
});
|
|
703
|
-
it('should compute factorials', function () {
|
|
704
|
-
// given
|
|
705
|
-
var testCases = [
|
|
706
|
-
{
|
|
707
|
-
given: '(1+x^2)!',
|
|
708
|
-
expected: 'factorial(1+x^2)',
|
|
709
|
-
expectedValue: '245.1516183677083'
|
|
710
|
-
},
|
|
711
|
-
{
|
|
712
|
-
given: '10!',
|
|
713
|
-
expected: 'factorial(10)',
|
|
714
|
-
expectedValue: '3628800'
|
|
715
|
-
},
|
|
716
|
-
{
|
|
717
|
-
given: 'x!',
|
|
718
|
-
expected: 'factorial(x)',
|
|
719
|
-
expectedValue: '2.197620278392476'
|
|
720
|
-
},
|
|
721
|
-
{
|
|
722
|
-
given: 'x!*x!',
|
|
723
|
-
expected: 'factorial(x)^2',
|
|
724
|
-
expectedValue: '4.829534888001823'
|
|
725
|
-
},
|
|
726
|
-
{
|
|
727
|
-
given: '3*(1+x!*x!)',
|
|
728
|
-
expected: '3*(1+factorial(x)^2)',
|
|
729
|
-
expectedValue: '17.488604664005468'
|
|
730
|
-
},
|
|
731
|
-
{
|
|
732
|
-
given: '3*(1+x!*x!)!',
|
|
733
|
-
expected: '3*factorial(1+factorial(x)^2)',
|
|
734
|
-
expectedValue: '1573.2041488172601'
|
|
735
|
-
}
|
|
736
|
-
];
|
|
737
|
-
|
|
738
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
739
|
-
// when
|
|
740
|
-
var parsed = nerdamer(testCases[i].given);
|
|
741
|
-
var value = parsed.evaluate(values).text('decimals');
|
|
742
|
-
|
|
743
|
-
// then
|
|
744
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
745
|
-
expect(round(value), 14).toEqual(round(testCases[i].expectedValue) ,14);
|
|
746
|
-
}
|
|
747
|
-
});
|
|
748
|
-
it('should compute symbolic factorials', function () {
|
|
749
|
-
// given
|
|
750
|
-
var testCases = [
|
|
751
|
-
{
|
|
752
|
-
given: '(-1/2)!',
|
|
753
|
-
expected: 'sqrt(pi)'
|
|
754
|
-
},
|
|
755
|
-
{
|
|
756
|
-
given: '(-7/2)!',
|
|
757
|
-
expected: '(-8/15)*sqrt(pi)'
|
|
758
|
-
},
|
|
759
|
-
{
|
|
760
|
-
given: '(-9/2)!',
|
|
761
|
-
expected: '(16/105)*sqrt(pi)'
|
|
762
|
-
},
|
|
763
|
-
{
|
|
764
|
-
given: '(9/2)!',
|
|
765
|
-
expected: '(945/32)*sqrt(pi)'
|
|
766
|
-
},
|
|
767
|
-
{
|
|
768
|
-
given: '(7/2)!',
|
|
769
|
-
expected: '(105/16)*sqrt(pi)'
|
|
770
|
-
},
|
|
771
|
-
{
|
|
772
|
-
given: '(1/2)!',
|
|
773
|
-
expected: '(1/2)*sqrt(pi)'
|
|
774
|
-
}
|
|
775
|
-
];
|
|
776
|
-
|
|
777
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
778
|
-
// when
|
|
779
|
-
var parsed = nerdamer(testCases[i].given);
|
|
780
|
-
|
|
781
|
-
// then
|
|
782
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
783
|
-
}
|
|
784
|
-
});
|
|
785
|
-
it('should handle square roots', function () {
|
|
786
|
-
// given
|
|
787
|
-
var testCases = [
|
|
788
|
-
{
|
|
789
|
-
given: 'sqrt(1+x)^(4*x)',
|
|
790
|
-
expected: '(1+x)^(2*x)',
|
|
791
|
-
expectedValue: '115.80281433592612'
|
|
792
|
-
},
|
|
793
|
-
{
|
|
794
|
-
given: 'sqrt(2*sqrt(5))',
|
|
795
|
-
expected: '5^(1/4)*sqrt(2)',
|
|
796
|
-
expectedValue: '2.114742526881128'
|
|
797
|
-
},
|
|
798
|
-
{
|
|
799
|
-
given: 'sqrt(2)*sqrt(2)',
|
|
800
|
-
expected: '2',
|
|
801
|
-
expectedValue: '2'
|
|
802
|
-
},
|
|
803
|
-
{
|
|
804
|
-
given: 'sqrt(1/2)',
|
|
805
|
-
expected: 'sqrt(2)^(-1)',
|
|
806
|
-
expectedValue: '0.7071067811865475'
|
|
807
|
-
},
|
|
808
|
-
{
|
|
809
|
-
given: 'sqrt(2)^2',
|
|
810
|
-
expected: '2',
|
|
811
|
-
expectedValue: '2'
|
|
812
|
-
},
|
|
813
|
-
{
|
|
814
|
-
given: '6*sqrt(2)^4',
|
|
815
|
-
expected: '24',
|
|
816
|
-
expectedValue: '24'
|
|
817
|
-
},
|
|
818
|
-
{
|
|
819
|
-
given: 'sqrt(x^2)*sqrt(x^4)',
|
|
820
|
-
expected: 'abs(x)*x^2',
|
|
821
|
-
expectedValue: '9.261'
|
|
822
|
-
},
|
|
823
|
-
{
|
|
824
|
-
given: 'sqrt((5/2)*x^10)',
|
|
825
|
-
expected: 'abs(x)*sqrt(2)^(-1)*sqrt(5)*x^4',
|
|
826
|
-
expectedValue: '64.5753067708567'
|
|
827
|
-
},
|
|
828
|
-
{
|
|
829
|
-
given: '(sqrt((5/2)*x^10))*-sqrt(2)',
|
|
830
|
-
expected: '-abs(x)*sqrt(5)*x^4',
|
|
831
|
-
expectedValue: '-91.3232746297487'
|
|
832
|
-
},
|
|
833
|
-
{
|
|
834
|
-
given: 'sqrt(9)',
|
|
835
|
-
expected: '3',
|
|
836
|
-
expectedValue: '3'
|
|
837
|
-
},
|
|
838
|
-
{
|
|
839
|
-
given: 'sqrt(-9)',
|
|
840
|
-
expected: '3*i',
|
|
841
|
-
expectedValue: '3*i'
|
|
842
|
-
},
|
|
843
|
-
{
|
|
844
|
-
given: 'sqrt(a/x)',
|
|
845
|
-
expected: 'sqrt(a)*sqrt(x)^(-1)',
|
|
846
|
-
expectedValue: '1.879716290649558'
|
|
847
|
-
},
|
|
848
|
-
{
|
|
849
|
-
given: 'sqrt(-x)',
|
|
850
|
-
expected: 'sqrt(-x)',
|
|
851
|
-
expectedValue: '1.4491376746189437*i'
|
|
852
|
-
},
|
|
853
|
-
{
|
|
854
|
-
given: 'sqrt(-x)*sqrt(-x)',
|
|
855
|
-
expected: '-x',
|
|
856
|
-
expectedValue: '-2.1'
|
|
857
|
-
},
|
|
858
|
-
{
|
|
859
|
-
given: 'sqrt(-x)*sqrt(-x)+4*x',
|
|
860
|
-
expected: '3*x',
|
|
861
|
-
expectedValue: '6.3'
|
|
862
|
-
},
|
|
863
|
-
{
|
|
864
|
-
given: 'sqrt((1/2*x)^(1/2))',
|
|
865
|
-
expected: '2^(-1/4)*x^(1/4)',
|
|
866
|
-
expectedValue: '1.0122722344290394'
|
|
867
|
-
},
|
|
868
|
-
{
|
|
869
|
-
given: 'sqrt(4*sqrt(2)^(-1)*x^(1/2))',
|
|
870
|
-
expected: '2^(3/4)*x^(1/4)',
|
|
871
|
-
expectedValue: '2.0245444688580787'
|
|
872
|
-
},
|
|
873
|
-
{
|
|
874
|
-
given: 'sqrt(4+x)',
|
|
875
|
-
expected: 'sqrt(4+x)',
|
|
876
|
-
expectedValue: '2.4698178070456938'
|
|
877
|
-
},
|
|
878
|
-
{
|
|
879
|
-
given: '(1/2)*x^(1/2)+sqrt(x)',
|
|
880
|
-
expected: '(3/2)*sqrt(x)',
|
|
881
|
-
expectedValue: '2.173706511928416'
|
|
882
|
-
},
|
|
883
|
-
{
|
|
884
|
-
given: 'sqrt((4+x)^2)',
|
|
885
|
-
expected: 'abs(4+x)',
|
|
886
|
-
expectedValue: '6.1'
|
|
887
|
-
},
|
|
888
|
-
{
|
|
889
|
-
given: '2*sqrt(3/4)',
|
|
890
|
-
expected: 'sqrt(3)',
|
|
891
|
-
expectedValue: '1.7320508075688772'
|
|
892
|
-
},
|
|
893
|
-
{
|
|
894
|
-
given: 'sqrt(2)*sqrt(8)',
|
|
895
|
-
expected: '4',
|
|
896
|
-
expectedValue: '4'
|
|
897
|
-
},
|
|
898
|
-
{
|
|
899
|
-
given: 'sqrt(242)',
|
|
900
|
-
expected: '11*sqrt(2)',
|
|
901
|
-
expectedValue: '15.556349186104047'
|
|
902
|
-
},
|
|
903
|
-
{
|
|
904
|
-
given: 'sqrt(4)^-1',
|
|
905
|
-
expected: '1/2',
|
|
906
|
-
expectedValue: '0.5'
|
|
907
|
-
},
|
|
908
|
-
{
|
|
909
|
-
given: 'sqrt(4*x^2)',
|
|
910
|
-
expected: '2*abs(x)',
|
|
911
|
-
expectedValue: '4.2'
|
|
912
|
-
},
|
|
913
|
-
{
|
|
914
|
-
given: '74689676.31109099*sqrt(5578547747455547)',
|
|
915
|
-
expected: '(824947474856/11045)*sqrt(5578547747455547)',
|
|
916
|
-
expectedValue: '5578547747455547'
|
|
917
|
-
},
|
|
918
|
-
{
|
|
919
|
-
given: 'sqrt(2/x)',
|
|
920
|
-
expected: 'sqrt(2)*sqrt(x)^(-1)',
|
|
921
|
-
expectedValue: '0.9759000729485331'
|
|
922
|
-
},
|
|
923
|
-
{
|
|
924
|
-
given: 'sqrt(3^x)',
|
|
925
|
-
expected: 'sqrt(3^x)',
|
|
926
|
-
expectedValue: '3.169401925649'
|
|
927
|
-
}
|
|
928
|
-
];
|
|
929
|
-
|
|
930
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
931
|
-
// when
|
|
932
|
-
var parsed = nerdamer(testCases[i].given);
|
|
933
|
-
var value = parsed.evaluate(values).text('decimals');
|
|
934
|
-
|
|
935
|
-
// then
|
|
936
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
937
|
-
expect(round(value, 12)).toEqual(round(testCases[i].expectedValue ,12));
|
|
938
|
-
}
|
|
939
|
-
});
|
|
940
|
-
it('should simplify square roots', function() {
|
|
941
|
-
expect(nerdamer('sqrt(128/49)').toString()).toEqual('(8/7)*sqrt(2)');
|
|
942
|
-
expect(nerdamer('sqrt(2)-2/(sqrt(2))').toString()).toEqual('0');
|
|
943
|
-
expect(nerdamer('expand((sqrt(7)+3sqrt(2))(sqrt(7)-3sqrt(2)))').toString()).toEqual('-11');
|
|
944
|
-
expect(nerdamer('3sqrt(2)*2sqrt(6)').toString()).toEqual('12*sqrt(3)');
|
|
945
|
-
});
|
|
946
|
-
it('should handle square roots of negative values', function() {
|
|
947
|
-
expect(nerdamer('sqrt(-x)').evaluate().text()).toEqual('sqrt(-x)');
|
|
948
|
-
expect(nerdamer('sqrt(-0.5*x)').evaluate().text()).toEqual('0.7071067811865475*sqrt(-x)');
|
|
949
|
-
expect(nerdamer('sqrt(-4)').evaluate().text()).toEqual('2*i');
|
|
950
|
-
expect(nerdamer('sqrt(-pi)').evaluate().text()).toEqual('1.7724538509055163*i');
|
|
951
|
-
});
|
|
952
|
-
it('should expand square roots', function () {
|
|
953
|
-
// given
|
|
954
|
-
var testCases = [
|
|
955
|
-
{
|
|
956
|
-
given: '(sqrt(7)+3sqrt(2))*(sqrt(7)-3sqrt(2))',
|
|
957
|
-
expected: '-11'
|
|
958
|
-
},
|
|
959
|
-
{
|
|
960
|
-
given: 'sqrt(33)*sqrt(11)',
|
|
961
|
-
expected: '11*sqrt(3)'
|
|
962
|
-
}
|
|
963
|
-
];
|
|
964
|
-
|
|
965
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
966
|
-
// when
|
|
967
|
-
var parsed = nerdamer(testCases[i].given).expand();
|
|
968
|
-
|
|
969
|
-
// then
|
|
970
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
971
|
-
}
|
|
972
|
-
});
|
|
973
|
-
it('should correctly test for squareness', function() {
|
|
974
|
-
expect(nerdamer('16x^2*y^2').symbol.isSquare()).toBe(true);
|
|
975
|
-
expect(nerdamer('16x^2*y^2-1').symbol.isSquare()).toBe(false);
|
|
976
|
-
expect(nerdamer('9').symbol.isSquare()).toBe(true);
|
|
977
|
-
expect(nerdamer('(5+x)^6').symbol.isSquare()).toBe(true);
|
|
978
|
-
expect(nerdamer('(x+y)^2').symbol.isSquare()).toBe(true);
|
|
979
|
-
expect(nerdamer('9^(1/4)').symbol.isSquare()).toBe(false);
|
|
980
|
-
expect(nerdamer('x^(1/2)').symbol.isSquare()).toBe(false);
|
|
981
|
-
});
|
|
982
|
-
it('should correctly test for cubeness', function() {
|
|
983
|
-
expect(nerdamer('64x^3*y^3').symbol.isCube()).toBe(true);
|
|
984
|
-
expect(nerdamer('64x^3*y^3-1').symbol.isCube()).toBe(false);
|
|
985
|
-
expect(nerdamer('7').symbol.isCube()).toBe(false);
|
|
986
|
-
expect(nerdamer('27').symbol.isCube()).toBe(true);
|
|
987
|
-
expect(nerdamer('(5+x)^6').symbol.isCube()).toBe(true);
|
|
988
|
-
expect(nerdamer('(x+y)^2').symbol.isCube()).toBe(false);
|
|
989
|
-
expect(nerdamer('9^(1/4)').symbol.isCube()).toBe(false);
|
|
990
|
-
expect(nerdamer('x^(1/2)').symbol.isCube()).toBe(false);
|
|
991
|
-
expect(nerdamer('216*z^6').symbol.isCube()).toBe(true);
|
|
992
|
-
});
|
|
993
|
-
it('should support the imaginary number i', function () {
|
|
994
|
-
// given
|
|
995
|
-
var testCases = [
|
|
996
|
-
{
|
|
997
|
-
given: 'i*i',
|
|
998
|
-
expected: '-1',
|
|
999
|
-
expectedValue: '-1'
|
|
1000
|
-
},
|
|
1001
|
-
{
|
|
1002
|
-
given: 'i*8*i',
|
|
1003
|
-
expected: '-8',
|
|
1004
|
-
expectedValue: '-8'
|
|
1005
|
-
},
|
|
1006
|
-
{
|
|
1007
|
-
given: 'i^(2/3)',
|
|
1008
|
-
expected: '-1',
|
|
1009
|
-
expectedValue: '-1'
|
|
1010
|
-
},
|
|
1011
|
-
{
|
|
1012
|
-
given: '(256*i)^(1/8)',
|
|
1013
|
-
expected: '2*(-1)^(1/16)',
|
|
1014
|
-
expectedValue: '0.39018064403225655*i+1.9615705608064609'
|
|
1015
|
-
},
|
|
1016
|
-
{
|
|
1017
|
-
given: 'i/i',
|
|
1018
|
-
expected: '1',
|
|
1019
|
-
expectedValue: '1'
|
|
1020
|
-
},
|
|
1021
|
-
{
|
|
1022
|
-
given: '(1/i)*i',
|
|
1023
|
-
expected: '1',
|
|
1024
|
-
expectedValue: '1'
|
|
1025
|
-
},
|
|
1026
|
-
{
|
|
1027
|
-
given: 'i^(-1)',
|
|
1028
|
-
expected: '-i',
|
|
1029
|
-
expectedValue: '-i'
|
|
1030
|
-
},
|
|
1031
|
-
{
|
|
1032
|
-
given: 'i^(2)',
|
|
1033
|
-
expected: '-1',
|
|
1034
|
-
expectedValue: '-1'
|
|
1035
|
-
},
|
|
1036
|
-
{
|
|
1037
|
-
given: 'i^(-2)',
|
|
1038
|
-
expected: '-1',
|
|
1039
|
-
expectedValue: '-1'
|
|
1040
|
-
},
|
|
1041
|
-
{
|
|
1042
|
-
given: 'i^(-1)',
|
|
1043
|
-
expected: '-i',
|
|
1044
|
-
expectedValue: '-i'
|
|
1045
|
-
},
|
|
1046
|
-
// Euler's identity
|
|
1047
|
-
{
|
|
1048
|
-
given: 'e^(i*pi)+e^(2*i*pi)',
|
|
1049
|
-
expected: '0',
|
|
1050
|
-
expectedValue: '0'
|
|
1051
|
-
},
|
|
1052
|
-
{
|
|
1053
|
-
given: 'exp(i + x pi)',
|
|
1054
|
-
expected: 'e^(i+pi*x)',
|
|
1055
|
-
expectedValue: '396.1203590827245535+616.9209071285088*i'
|
|
1056
|
-
}
|
|
1057
|
-
];
|
|
1058
|
-
|
|
1059
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1060
|
-
// when
|
|
1061
|
-
var parsed = nerdamer(testCases[i].given);
|
|
1062
|
-
var value = parsed.evaluate(values).text('decimals', 17);
|
|
1063
|
-
|
|
1064
|
-
// then
|
|
1065
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
1066
|
-
expect(value).toEqual(testCases[i].expectedValue);
|
|
1067
|
-
}
|
|
1068
|
-
});
|
|
1069
|
-
it('should handle powers with results using i', function () {
|
|
1070
|
-
// given
|
|
1071
|
-
var testCases = [
|
|
1072
|
-
{
|
|
1073
|
-
given: '(-2/3*x)^x',
|
|
1074
|
-
expected: '(-x)^x*2^x*3^(-x)',
|
|
1075
|
-
//TODO: Evaluates to NaN somewhere
|
|
1076
|
-
expectedValue: '2.0270706004935852*(-1)^2.1'
|
|
1077
|
-
}
|
|
1078
|
-
];
|
|
1079
|
-
|
|
1080
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1081
|
-
// when
|
|
1082
|
-
var parsed = nerdamer(testCases[i].given);
|
|
1083
|
-
var value = parsed.evaluate(values).text('decimals');
|
|
1084
|
-
|
|
1085
|
-
// then
|
|
1086
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
1087
|
-
expect(value).toEqual(testCases[i].expectedValue);
|
|
1088
|
-
}
|
|
1089
|
-
});
|
|
1090
|
-
it('should compute logarithms correctly', function () {
|
|
1091
|
-
// given
|
|
1092
|
-
var testCases = [
|
|
1093
|
-
{
|
|
1094
|
-
given: 'log(e)',
|
|
1095
|
-
expected: '1',
|
|
1096
|
-
expectedValue: '1'
|
|
1097
|
-
},
|
|
1098
|
-
{
|
|
1099
|
-
given: 'log(e^e)',
|
|
1100
|
-
expected: 'e',
|
|
1101
|
-
expectedValue: '2.718281828459045'
|
|
1102
|
-
},
|
|
1103
|
-
{
|
|
1104
|
-
given: 'log(1/e^e)',
|
|
1105
|
-
expected: '-e',
|
|
1106
|
-
expectedValue: '-2.718281828459045'
|
|
1107
|
-
},
|
|
1108
|
-
{
|
|
1109
|
-
given: 'log(1/sqrt(2))',
|
|
1110
|
-
expected: '(-1/2)*log(2)',
|
|
1111
|
-
expectedValue: '-0.34657359027997'
|
|
1112
|
-
}
|
|
1113
|
-
];
|
|
1114
|
-
|
|
1115
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1116
|
-
// when
|
|
1117
|
-
var parsed = nerdamer(testCases[i].given);
|
|
1118
|
-
var value = parsed.evaluate().text('decimals');
|
|
1119
|
-
|
|
1120
|
-
// then
|
|
1121
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
1122
|
-
expect(round(value, 14)).toEqual(round(testCases[i].expectedValue), 14);
|
|
1123
|
-
}
|
|
1124
|
-
});
|
|
1125
|
-
it('should check for equality', function () {
|
|
1126
|
-
var a, b, c, d, e, f, g;
|
|
1127
|
-
a = nerdamer("2sqrt(5)");
|
|
1128
|
-
b = nerdamer("2sqrt(5)");
|
|
1129
|
-
c = nerdamer("sqrt(13)");
|
|
1130
|
-
d = nerdamer("sqrt(21)");
|
|
1131
|
-
e = nerdamer("sqrt(20)");
|
|
1132
|
-
f = nerdamer("sqrt(5) + sqrt(3)");
|
|
1133
|
-
g = nerdamer("sqrt(5) + sqrt(7)");
|
|
1134
|
-
expect(a.lt(g)).toBe(true);
|
|
1135
|
-
expect(a.lt(f)).toBe(false);
|
|
1136
|
-
expect(a.gt(c)).toBe(true);
|
|
1137
|
-
expect(a.gt(d)).toBe(false);
|
|
1138
|
-
expect(a.gt(e)).toBe(false);
|
|
1139
|
-
expect(a.lt(e)).toBe(false);
|
|
1140
|
-
expect(a.eq(e)).toBe(true);
|
|
1141
|
-
expect(b.gte(a)).toBe(true);
|
|
1142
|
-
expect(c.gte(a)).toBe(false);
|
|
1143
|
-
expect(e.lte(d)).toBe(true);
|
|
1144
|
-
expect(f.lte(g)).toBe(true);
|
|
1145
|
-
|
|
1146
|
-
});
|
|
1147
|
-
/** Based on commit cf8c0f8. */
|
|
1148
|
-
it('should not cause infinite recursion', function () {
|
|
1149
|
-
// given
|
|
1150
|
-
var formula = '1/(1+x)+(1+x)';
|
|
1151
|
-
|
|
1152
|
-
// when
|
|
1153
|
-
var parsed = nerdamer(formula);
|
|
1154
|
-
var result = parsed.evaluate().toString();
|
|
1155
|
-
|
|
1156
|
-
// then
|
|
1157
|
-
expect(result).toBe('(1+x)^(-1)+1+x');
|
|
1158
|
-
});
|
|
1159
|
-
it('should support ceil and floor', function () {
|
|
1160
|
-
// given
|
|
1161
|
-
var testCases = [
|
|
1162
|
-
{
|
|
1163
|
-
given: 'floor(204)',
|
|
1164
|
-
expected: '204'
|
|
1165
|
-
},
|
|
1166
|
-
{
|
|
1167
|
-
given: 'floor(10.893)',
|
|
1168
|
-
expected: '10'
|
|
1169
|
-
},
|
|
1170
|
-
{
|
|
1171
|
-
given: 'floor(-10.3)',
|
|
1172
|
-
expected: '-11'
|
|
1173
|
-
},
|
|
1174
|
-
{
|
|
1175
|
-
given: 'ceil(204)',
|
|
1176
|
-
expected: '204'
|
|
1177
|
-
},
|
|
1178
|
-
{
|
|
1179
|
-
given: 'ceil(10.893)',
|
|
1180
|
-
expected: '11'
|
|
1181
|
-
},
|
|
1182
|
-
{
|
|
1183
|
-
given: 'ceil(-10.9)',
|
|
1184
|
-
expected: '-10'
|
|
1185
|
-
}
|
|
1186
|
-
];
|
|
1187
|
-
|
|
1188
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1189
|
-
// when
|
|
1190
|
-
var parsed = nerdamer(testCases[i].given);
|
|
1191
|
-
var value = parsed.evaluate().text('decimals');
|
|
1192
|
-
|
|
1193
|
-
// then
|
|
1194
|
-
expect(value).toEqual(testCases[i].expected);
|
|
1195
|
-
}
|
|
1196
|
-
});
|
|
1197
|
-
it('should round', function () {
|
|
1198
|
-
// given
|
|
1199
|
-
var testCases = [
|
|
1200
|
-
{
|
|
1201
|
-
given: 'round(204)',
|
|
1202
|
-
expected: '204'
|
|
1203
|
-
},
|
|
1204
|
-
{
|
|
1205
|
-
given: 'round(10.893)',
|
|
1206
|
-
expected: '11'
|
|
1207
|
-
},
|
|
1208
|
-
{
|
|
1209
|
-
given: 'round(10.893, 1)',
|
|
1210
|
-
expected: '10.9'
|
|
1211
|
-
},
|
|
1212
|
-
{
|
|
1213
|
-
given: 'round(-10.3)',
|
|
1214
|
-
expected: '-10'
|
|
1215
|
-
},
|
|
1216
|
-
{
|
|
1217
|
-
given: 'round(204)',
|
|
1218
|
-
expected: '204'
|
|
1219
|
-
},
|
|
1220
|
-
{
|
|
1221
|
-
given: 'round(10.1)',
|
|
1222
|
-
expected: '10'
|
|
1223
|
-
},
|
|
1224
|
-
{
|
|
1225
|
-
given: 'round(1.23423534e-12,-2)',
|
|
1226
|
-
expected: '0.00000000000123'
|
|
1227
|
-
},
|
|
1228
|
-
{
|
|
1229
|
-
given: 'round(1.23423534e12,-2)',
|
|
1230
|
-
expected: '1230000000000'
|
|
1231
|
-
}
|
|
1232
|
-
];
|
|
1233
|
-
|
|
1234
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1235
|
-
// when
|
|
1236
|
-
var parsed = nerdamer(testCases[i].given);
|
|
1237
|
-
var value = parsed.evaluate().text('decimals');
|
|
1238
|
-
|
|
1239
|
-
// then
|
|
1240
|
-
expect(value).toEqual(testCases[i].expected);
|
|
1241
|
-
}
|
|
1242
|
-
});
|
|
1243
|
-
it('should support trunc()', function () {
|
|
1244
|
-
// given
|
|
1245
|
-
var testCases = [
|
|
1246
|
-
{
|
|
1247
|
-
given: 'trunc(0)',
|
|
1248
|
-
expected: '0'
|
|
1249
|
-
},
|
|
1250
|
-
{
|
|
1251
|
-
given: 'trunc(10.234)',
|
|
1252
|
-
expected: '10'
|
|
1253
|
-
},
|
|
1254
|
-
{
|
|
1255
|
-
given: 'trunc(-9.99)',
|
|
1256
|
-
expected: '-9'
|
|
1257
|
-
},
|
|
1258
|
-
{
|
|
1259
|
-
given: 'trunc(0.99)',
|
|
1260
|
-
expected: '0'
|
|
1261
|
-
},
|
|
1262
|
-
{
|
|
1263
|
-
given: 'trunc(-0.7555)',
|
|
1264
|
-
expected: '0'
|
|
1265
|
-
},
|
|
1266
|
-
{
|
|
1267
|
-
given: 'trunc(8.9 * -4.9)',
|
|
1268
|
-
expected: '-43'
|
|
1269
|
-
},
|
|
1270
|
-
{
|
|
1271
|
-
given: 'trunc(8.9) * trunc(-4.9)',
|
|
1272
|
-
expected: '-32'
|
|
1273
|
-
}
|
|
1274
|
-
];
|
|
1275
|
-
|
|
1276
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1277
|
-
// when
|
|
1278
|
-
var parsed = nerdamer(testCases[i].given);
|
|
1279
|
-
var value = parsed.evaluate().text('decimals');
|
|
1280
|
-
|
|
1281
|
-
// then
|
|
1282
|
-
expect(value).toEqual(testCases[i].expected);
|
|
1283
|
-
}
|
|
1284
|
-
});
|
|
1285
|
-
it('should support continued fractions', function () {
|
|
1286
|
-
// given
|
|
1287
|
-
var testCases = [
|
|
1288
|
-
{
|
|
1289
|
-
given: 'continued_fraction(2.145474, 11)',
|
|
1290
|
-
expected: '[1,2,[6,1,6,1,16,8,2,1,3,2]]'
|
|
1291
|
-
},
|
|
1292
|
-
{
|
|
1293
|
-
given: 'continued_fraction(-6/7)',
|
|
1294
|
-
expected: '[-1,0,[1,6]]'
|
|
1295
|
-
},
|
|
1296
|
-
{
|
|
1297
|
-
given: 'continued_fraction(sqrt(2), 5)',
|
|
1298
|
-
expected: '[1,1,[2,2,2,2,2]]'
|
|
1299
|
-
}
|
|
1300
|
-
];
|
|
1301
|
-
|
|
1302
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1303
|
-
// when
|
|
1304
|
-
var parsed = nerdamer(testCases[i].given);
|
|
1305
|
-
|
|
1306
|
-
// then
|
|
1307
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
1308
|
-
}
|
|
1309
|
-
});
|
|
1310
|
-
/** #35 #76: Support multiple minus signs and brackets */
|
|
1311
|
-
it('should support prefix operator with parantheses', function () {
|
|
1312
|
-
// given
|
|
1313
|
-
var testCases = [
|
|
1314
|
-
{
|
|
1315
|
-
given: '(a+x)--(x+a)',
|
|
1316
|
-
expected: '2*a+2*x'
|
|
1317
|
-
},
|
|
1318
|
-
{
|
|
1319
|
-
given: '(3)---(3)',
|
|
1320
|
-
expected: '0'
|
|
1321
|
-
},
|
|
1322
|
-
{
|
|
1323
|
-
given: '-(1)--(1-1--1)',
|
|
1324
|
-
expected: '0'
|
|
1325
|
-
},
|
|
1326
|
-
{
|
|
1327
|
-
given: '-(-(1))-(--1)',
|
|
1328
|
-
expected: '0'
|
|
1329
|
-
}
|
|
1330
|
-
];
|
|
1331
|
-
|
|
1332
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1333
|
-
// when
|
|
1334
|
-
var parsed = nerdamer(testCases[i].given);
|
|
1335
|
-
var value = parsed.evaluate().text('decimals');
|
|
1336
|
-
|
|
1337
|
-
// then
|
|
1338
|
-
expect(value).toEqual(testCases[i].expected);
|
|
1339
|
-
}
|
|
1340
|
-
});
|
|
1341
|
-
//#78
|
|
1342
|
-
it('should substitute variables', function () {
|
|
1343
|
-
// given
|
|
1344
|
-
var testCases = [
|
|
1345
|
-
{
|
|
1346
|
-
given: '2*(x+1)^2',
|
|
1347
|
-
sub: 'x+1',
|
|
1348
|
-
sub_with: 'u',
|
|
1349
|
-
expected: '2*u^2'
|
|
1350
|
-
},
|
|
1351
|
-
{
|
|
1352
|
-
given: '2*(x+1+a)^2',
|
|
1353
|
-
sub: 'x+1',
|
|
1354
|
-
sub_with: 'u',
|
|
1355
|
-
expected: '2*(1+a+x)^2'
|
|
1356
|
-
},
|
|
1357
|
-
{
|
|
1358
|
-
given: '2*(x+1)^(x+1)',
|
|
1359
|
-
sub: 'x+1',
|
|
1360
|
-
sub_with: 'u',
|
|
1361
|
-
expected: '2*u^u'
|
|
1362
|
-
},
|
|
1363
|
-
{
|
|
1364
|
-
given: '2*(x+1)^2',
|
|
1365
|
-
sub: '(x+1)^2',
|
|
1366
|
-
sub_with: 'u^x',
|
|
1367
|
-
expected: '2*u^x'
|
|
1368
|
-
},
|
|
1369
|
-
{
|
|
1370
|
-
given: '2*(x+1)^2',
|
|
1371
|
-
sub: 'x+1',
|
|
1372
|
-
sub_with: 'u^x',
|
|
1373
|
-
expected: '2*u^(2*x)'
|
|
1374
|
-
},
|
|
1375
|
-
{
|
|
1376
|
-
given: '(2*(x+1)^2+a)^2',
|
|
1377
|
-
sub: '(x+1)^2',
|
|
1378
|
-
sub_with: 'u^x',
|
|
1379
|
-
expected: '(2*u^x+a)^2'
|
|
1380
|
-
},
|
|
1381
|
-
{
|
|
1382
|
-
given: '(x^x+y)^(x^x-t)',
|
|
1383
|
-
sub: 'x^x',
|
|
1384
|
-
sub_with: '4',
|
|
1385
|
-
expected: '(4+y)^(-t+4)'
|
|
1386
|
-
},
|
|
1387
|
-
{
|
|
1388
|
-
given: '(cos(x)+cos(x)^2)',
|
|
1389
|
-
sub: 'cos(x)',
|
|
1390
|
-
sub_with: '4',
|
|
1391
|
-
expected: '20'
|
|
1392
|
-
},
|
|
1393
|
-
{
|
|
1394
|
-
given: '(cos(x)+cos(x)^2)',
|
|
1395
|
-
sub: '(cos(x)+cos(x)^2)',
|
|
1396
|
-
sub_with: '4',
|
|
1397
|
-
expected: '4'
|
|
1398
|
-
},
|
|
1399
|
-
{
|
|
1400
|
-
given: '(cos(x)+cos(x^6)^2)',
|
|
1401
|
-
sub: '(cos(x)+cos(x)^2)',
|
|
1402
|
-
sub_with: '4',
|
|
1403
|
-
expected: 'cos(x)+cos(x^6)^2'
|
|
1404
|
-
},
|
|
1405
|
-
{
|
|
1406
|
-
given: '(cos(x)+cos(x^6)^2)',
|
|
1407
|
-
sub: 'cos(x)',
|
|
1408
|
-
sub_with: '4',
|
|
1409
|
-
expected: '4+cos(x^6)^2'
|
|
1410
|
-
},
|
|
1411
|
-
{
|
|
1412
|
-
given: '(cos(x)+cos(x^6)^2)',
|
|
1413
|
-
sub: '2',
|
|
1414
|
-
sub_with: '4',
|
|
1415
|
-
expected: 'error'
|
|
1416
|
-
}
|
|
1417
|
-
];
|
|
1418
|
-
|
|
1419
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1420
|
-
var testCase = testCases[i];
|
|
1421
|
-
|
|
1422
|
-
var parsed;
|
|
1423
|
-
// when
|
|
1424
|
-
try {
|
|
1425
|
-
parsed = nerdamer(testCase.given).sub(testCase.sub, testCase.sub_with).toString();
|
|
1426
|
-
}
|
|
1427
|
-
catch(e){
|
|
1428
|
-
parsed = 'error';
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
// then
|
|
1432
|
-
expect(parsed).toEqual(testCases[i].expected);
|
|
1433
|
-
}
|
|
1434
|
-
});
|
|
1435
|
-
it('should ignore constants and special values', function() {
|
|
1436
|
-
var core = nerdamer.getCore();
|
|
1437
|
-
expect(nerdamer('e').variables()).toEqual([]);
|
|
1438
|
-
expect(nerdamer('pi').variables()).toEqual([]);
|
|
1439
|
-
expect(nerdamer(core.Settings.IMAGINARY).variables()).toEqual([]);
|
|
1440
|
-
});
|
|
1441
|
-
/** #44: a+b - (a+b) not evaluated as 0 */
|
|
1442
|
-
it('should perform subtraction of terms', function () {
|
|
1443
|
-
// given
|
|
1444
|
-
var formula = 'a+b - (a+b)';
|
|
1445
|
-
|
|
1446
|
-
// when
|
|
1447
|
-
var result = nerdamer(formula).toString();
|
|
1448
|
-
|
|
1449
|
-
// then
|
|
1450
|
-
expect(result).toBe('0');
|
|
1451
|
-
});
|
|
1452
|
-
/** #46: (x^(1/2)*x^(1/3))-x^(5/6) should be 0 */
|
|
1453
|
-
it('should result in 0', function () {
|
|
1454
|
-
// given
|
|
1455
|
-
var formula = '(x^(1/2)*x^(1/3))-x^(5/6)';
|
|
1456
|
-
|
|
1457
|
-
// when
|
|
1458
|
-
var result = nerdamer(formula).toString();
|
|
1459
|
-
|
|
1460
|
-
// then
|
|
1461
|
-
expect(result).toBe('0');
|
|
1462
|
-
});
|
|
1463
|
-
/** #47: (a^2)/(a*b) should be a/b */
|
|
1464
|
-
it('should simplify correctly', function () {
|
|
1465
|
-
// given
|
|
1466
|
-
var formula = '(a^2)/(a*b)';
|
|
1467
|
-
|
|
1468
|
-
// when
|
|
1469
|
-
var result = nerdamer(formula).toString();
|
|
1470
|
-
|
|
1471
|
-
// then
|
|
1472
|
-
// TODO jiggzson: Result is correct but a/b would be simpler
|
|
1473
|
-
expect(result).toBe('a*b^(-1)');
|
|
1474
|
-
});
|
|
1475
|
-
/** #56: x/sqrt(x) = x^(3/2) */
|
|
1476
|
-
it('should calculate x/sqrt(x) correctly', function () {
|
|
1477
|
-
// given
|
|
1478
|
-
var formula = 'x/sqrt(x)';
|
|
1479
|
-
|
|
1480
|
-
// when
|
|
1481
|
-
var result = nerdamer(formula).toString();
|
|
1482
|
-
|
|
1483
|
-
// then
|
|
1484
|
-
expect(result).toBe('x^(1/2)');
|
|
1485
|
-
});
|
|
1486
|
-
/** #60: sin(x) looks like sin(abs(x)) */
|
|
1487
|
-
it('should respect the sign of argument for sin(x)', function () {
|
|
1488
|
-
// given
|
|
1489
|
-
var halfSqrt2 = '0.7071067811865475'; // sqrt(2)/2
|
|
1490
|
-
var halfSqrt3 = '0.8660254037844385'; // sqrt(3)/2
|
|
1491
|
-
var testCases = [
|
|
1492
|
-
{
|
|
1493
|
-
given: '-pi',
|
|
1494
|
-
expected: '0'
|
|
1495
|
-
},
|
|
1496
|
-
{
|
|
1497
|
-
given: '-3/4*pi',
|
|
1498
|
-
expected: '-' + halfSqrt2
|
|
1499
|
-
},
|
|
1500
|
-
{
|
|
1501
|
-
given: '-2/3*pi',
|
|
1502
|
-
expected: '-' + halfSqrt3
|
|
1503
|
-
},
|
|
1504
|
-
{
|
|
1505
|
-
given: '-1/2*pi',
|
|
1506
|
-
expected: '-1'
|
|
1507
|
-
},
|
|
1508
|
-
{
|
|
1509
|
-
given: '-1/6*pi',
|
|
1510
|
-
expected: '-0.5'
|
|
1511
|
-
},
|
|
1512
|
-
{
|
|
1513
|
-
given: '0',
|
|
1514
|
-
expected: '0'
|
|
1515
|
-
},
|
|
1516
|
-
{
|
|
1517
|
-
given: '1/4*pi',
|
|
1518
|
-
expected: halfSqrt2
|
|
1519
|
-
},
|
|
1520
|
-
{
|
|
1521
|
-
given: '1/2*pi',
|
|
1522
|
-
expected: '1'
|
|
1523
|
-
},
|
|
1524
|
-
{
|
|
1525
|
-
given: '3/4*pi',
|
|
1526
|
-
expected: halfSqrt2
|
|
1527
|
-
},
|
|
1528
|
-
{
|
|
1529
|
-
given: 'pi',
|
|
1530
|
-
expected: '0'
|
|
1531
|
-
},
|
|
1532
|
-
{
|
|
1533
|
-
given: '3/2*pi',
|
|
1534
|
-
expected: '-1'
|
|
1535
|
-
},
|
|
1536
|
-
{
|
|
1537
|
-
given: '2*pi',
|
|
1538
|
-
expected: '0'
|
|
1539
|
-
},
|
|
1540
|
-
{
|
|
1541
|
-
given: '2.25 * pi',
|
|
1542
|
-
expected: halfSqrt2
|
|
1543
|
-
}
|
|
1544
|
-
];
|
|
1545
|
-
|
|
1546
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1547
|
-
// when
|
|
1548
|
-
var result = nerdamer('sin(' + testCases[i].given + ')').evaluate().text('decimals');
|
|
1549
|
-
|
|
1550
|
-
// then
|
|
1551
|
-
expect(round(result, 14)).toEqual(round(testCases[i].expected),14);
|
|
1552
|
-
}
|
|
1553
|
-
});
|
|
1554
|
-
it('should compute complex numbers', function() {
|
|
1555
|
-
var testCases = [
|
|
1556
|
-
//SYMBOLIC
|
|
1557
|
-
{
|
|
1558
|
-
given: 'cos(3*i+a)',
|
|
1559
|
-
expected: 'cos(3*i+a)'
|
|
1560
|
-
},
|
|
1561
|
-
{
|
|
1562
|
-
given: 'sin(3*i+a)',
|
|
1563
|
-
expected: 'sin(3*i+a)'
|
|
1564
|
-
},
|
|
1565
|
-
{
|
|
1566
|
-
given: 'tan(3*i+a)',
|
|
1567
|
-
expected: 'tan(3*i+a)'
|
|
1568
|
-
},
|
|
1569
|
-
{
|
|
1570
|
-
given: 'sec(3*i+a)',
|
|
1571
|
-
expected: 'sec(3*i+a)'
|
|
1572
|
-
},
|
|
1573
|
-
{
|
|
1574
|
-
given: 'csc(3*i+a)',
|
|
1575
|
-
expected: 'csc(3*i+a)'
|
|
1576
|
-
},
|
|
1577
|
-
{
|
|
1578
|
-
given: 'cot(3*i+a)',
|
|
1579
|
-
expected: 'cot(3*i+a)'
|
|
1580
|
-
},
|
|
1581
|
-
{
|
|
1582
|
-
given: 'acos(3*i+a)',
|
|
1583
|
-
expected: 'acos(3*i+a)'
|
|
1584
|
-
},
|
|
1585
|
-
{
|
|
1586
|
-
given: 'asin(3*i+a)',
|
|
1587
|
-
expected: 'asin(3*i+a)'
|
|
1588
|
-
},
|
|
1589
|
-
{
|
|
1590
|
-
given: 'atan(3*i+a)',
|
|
1591
|
-
expected: 'atan(3*i+a)'
|
|
1592
|
-
},
|
|
1593
|
-
{
|
|
1594
|
-
given: 'asec(3*i+a)',
|
|
1595
|
-
expected: 'asec(3*i+a)'
|
|
1596
|
-
},
|
|
1597
|
-
{
|
|
1598
|
-
given: 'acsc(3*i+a)',
|
|
1599
|
-
expected: 'acsc(3*i+a)'
|
|
1600
|
-
},
|
|
1601
|
-
{
|
|
1602
|
-
given: 'acot(3*i+a)',
|
|
1603
|
-
expected: 'acot(3*i+a)'
|
|
1604
|
-
},
|
|
1605
|
-
{
|
|
1606
|
-
given: 'cosh(3*i+a)',
|
|
1607
|
-
expected: 'cosh(3*i+a)'
|
|
1608
|
-
},
|
|
1609
|
-
|
|
1610
|
-
//NUMERIC
|
|
1611
|
-
{
|
|
1612
|
-
given: 'cos(3*i+5)',
|
|
1613
|
-
expected: '2.855815004227387+9.606383448432581*i'
|
|
1614
|
-
},
|
|
1615
|
-
{
|
|
1616
|
-
given: 'sin(3*i+5)',
|
|
1617
|
-
expected: '-2.841692295606352*i-9.654125476854839'
|
|
1618
|
-
},
|
|
1619
|
-
{
|
|
1620
|
-
given: 'tan(3*i+5)',
|
|
1621
|
-
expected: '-0.002708235836224119+1.0041647106948153*i'
|
|
1622
|
-
},
|
|
1623
|
-
{
|
|
1624
|
-
given: 'sec(3*i+5)',
|
|
1625
|
-
expected: '-0.0956446409552863*i+0.028433530909971663'
|
|
1626
|
-
},
|
|
1627
|
-
{
|
|
1628
|
-
given: 'csc(3*i+5)',
|
|
1629
|
-
expected: '-0.02805851642308007*i-0.09532363467417838'
|
|
1630
|
-
},
|
|
1631
|
-
{
|
|
1632
|
-
given: 'cot(3*i+5)',
|
|
1633
|
-
expected: '-0.0026857984057586373-0.995845318575854*i'
|
|
1634
|
-
},
|
|
1635
|
-
{
|
|
1636
|
-
given: 'acos(3*i+5)',
|
|
1637
|
-
expected: '-2.452913742502812*i+0.5469745802831137'
|
|
1638
|
-
},
|
|
1639
|
-
{
|
|
1640
|
-
given: 'asin(3*i+5)',
|
|
1641
|
-
expected: '1.023821746511783+2.452913742502812*i'
|
|
1642
|
-
},
|
|
1643
|
-
{
|
|
1644
|
-
given: 'atan(3*i+5)',
|
|
1645
|
-
expected: '0.08656905917945859*i+1.4236790442393028'
|
|
1646
|
-
},
|
|
1647
|
-
{
|
|
1648
|
-
given: 'asec(3*i+5)',
|
|
1649
|
-
expected: '0.08907951708809479*i+1.4237901324243536'
|
|
1650
|
-
},
|
|
1651
|
-
{
|
|
1652
|
-
given: 'acsc(3*i+5)',
|
|
1653
|
-
expected: '-0.08907951708809479*i+0.14700619437054302'
|
|
1654
|
-
},
|
|
1655
|
-
{
|
|
1656
|
-
given: 'acot(3*i+5)',
|
|
1657
|
-
expected: '-0.08656905917945851*i+0.1471172825555939'
|
|
1658
|
-
},
|
|
1659
|
-
{
|
|
1660
|
-
given: 'cosh(3*i+5)',
|
|
1661
|
-
expected: '-73.46729221264526+10.471557674805572*i'
|
|
1662
|
-
},
|
|
1663
|
-
{
|
|
1664
|
-
given: 'sinh(3*i+5)',
|
|
1665
|
-
expected: '-73.46062169567367+10.472508533940392*i'
|
|
1666
|
-
},
|
|
1667
|
-
{
|
|
1668
|
-
given: 'tanh(3*i+5)',
|
|
1669
|
-
expected: '0.000025368676207684*i+0.9999128201513535'
|
|
1670
|
-
},
|
|
1671
|
-
{
|
|
1672
|
-
given: 'sech(3*i+5)',
|
|
1673
|
-
expected: '-0.0019014661516951708*i-0.013340476530549645'
|
|
1674
|
-
},
|
|
1675
|
-
{
|
|
1676
|
-
given: 'csch(3*i+5)',
|
|
1677
|
-
expected: '-0.0019019704237010977*i-0.013341591397996653'
|
|
1678
|
-
},
|
|
1679
|
-
{
|
|
1680
|
-
given: 'coth(3*i+5)',
|
|
1681
|
-
expected: '0.0000253731000445137*i+1.000087186805897'
|
|
1682
|
-
},
|
|
1683
|
-
{
|
|
1684
|
-
given: 'acosh(3*i+5)',
|
|
1685
|
-
expected: '0.5469745802831136*i+2.452913742502812'
|
|
1686
|
-
},
|
|
1687
|
-
{
|
|
1688
|
-
given: 'asinh(3*i+5)',
|
|
1689
|
-
expected: '0.5339990695941687*i+2.4598315216234345'
|
|
1690
|
-
},
|
|
1691
|
-
{
|
|
1692
|
-
given: 'atanh(3*i+5)',
|
|
1693
|
-
expected: '0.14694666622552974+1.4808695768986575*i'
|
|
1694
|
-
},
|
|
1695
|
-
{
|
|
1696
|
-
given: 'asech(3*i+5)',
|
|
1697
|
-
expected: '-1.4237901324243494*i+0.08907951708807783'
|
|
1698
|
-
},
|
|
1699
|
-
{
|
|
1700
|
-
given: 'acsch(3*i+5)',
|
|
1701
|
-
expected: '-0.08740053182394636*i+0.14709131539545411'
|
|
1702
|
-
},
|
|
1703
|
-
{
|
|
1704
|
-
given: 'acoth(3*i+5)',
|
|
1705
|
-
expected: '-0.08992674989623915*i+0.14694666622552965'
|
|
1706
|
-
}
|
|
1707
|
-
];
|
|
1708
|
-
|
|
1709
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1710
|
-
var result = nerdamer(testCases[i].given, null, 'numer').text();
|
|
1711
|
-
expect(round(result, 14)).toEqual(round(testCases[i].expected),14);
|
|
1712
|
-
}
|
|
1713
|
-
});
|
|
1714
|
-
it('should correctly get the numerator', function() {
|
|
1715
|
-
var testCases = [
|
|
1716
|
-
{
|
|
1717
|
-
given: '3/4*a',
|
|
1718
|
-
expected: '3*a'
|
|
1719
|
-
},
|
|
1720
|
-
{
|
|
1721
|
-
given: '8*a*b/(x*(x+1))',
|
|
1722
|
-
expected: '8*a*b'
|
|
1723
|
-
},
|
|
1724
|
-
{
|
|
1725
|
-
given: 'x+1/x',
|
|
1726
|
-
expected: 'x+x^(-1)'
|
|
1727
|
-
},
|
|
1728
|
-
{
|
|
1729
|
-
given: 'a*b/x',
|
|
1730
|
-
expected: 'a*b'
|
|
1731
|
-
},
|
|
1732
|
-
{
|
|
1733
|
-
given: 'x^2/(2*x+2)',
|
|
1734
|
-
expected: 'x^2'
|
|
1735
|
-
},
|
|
1736
|
-
{
|
|
1737
|
-
given: '1/3*x^2/(2*x+2)',
|
|
1738
|
-
expected: 'x^2'
|
|
1739
|
-
},
|
|
1740
|
-
{
|
|
1741
|
-
given: '2/a',
|
|
1742
|
-
expected: '2'
|
|
1743
|
-
},
|
|
1744
|
-
];
|
|
1745
|
-
|
|
1746
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1747
|
-
var result = nerdamer(testCases[i].given).numerator().text();
|
|
1748
|
-
expect(result.toString()).toEqual(testCases[i].expected);
|
|
1749
|
-
}
|
|
1750
|
-
});
|
|
1751
|
-
it('should correctly get the denominator', function() {
|
|
1752
|
-
var testCases = [
|
|
1753
|
-
{
|
|
1754
|
-
given: '3/4*a',
|
|
1755
|
-
expected: '4'
|
|
1756
|
-
},
|
|
1757
|
-
{
|
|
1758
|
-
given: '8*a*b/(x*(x+1))',
|
|
1759
|
-
expected: '(1+x)*x'
|
|
1760
|
-
},
|
|
1761
|
-
{
|
|
1762
|
-
given: 'x+1/x',
|
|
1763
|
-
expected: '1'
|
|
1764
|
-
},
|
|
1765
|
-
{
|
|
1766
|
-
given: 'a*b/x',
|
|
1767
|
-
expected: 'x'
|
|
1768
|
-
},
|
|
1769
|
-
{
|
|
1770
|
-
given: 'x^2/(2*x+2)',
|
|
1771
|
-
expected: '2+2*x'
|
|
1772
|
-
},
|
|
1773
|
-
{
|
|
1774
|
-
given: '1/3*x^2/(2*x+2)',
|
|
1775
|
-
expected: '3*(2+2*x)'
|
|
1776
|
-
},
|
|
1777
|
-
{
|
|
1778
|
-
given: '2/a',
|
|
1779
|
-
expected: 'a'
|
|
1780
|
-
},
|
|
1781
|
-
];
|
|
1782
|
-
|
|
1783
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
1784
|
-
var result = nerdamer(testCases[i].given).denominator().text();
|
|
1785
|
-
expect(result.toString()).toEqual(testCases[i].expected);
|
|
1786
|
-
}
|
|
1787
|
-
});
|
|
1788
|
-
it('should add vectors correctly', function() {
|
|
1789
|
-
expect(nerdamer('1+[a,b]').toString()).toEqual('[1+a,1+b]');
|
|
1790
|
-
expect(nerdamer('[a,b]+1').toString()).toEqual('[1+a,1+b]');
|
|
1791
|
-
expect(nerdamer('[a,b]+[a,b]').toString()).toEqual('[2*a,2*b]');
|
|
1792
|
-
});
|
|
1793
|
-
it('should subtract vectors correctly', function() {
|
|
1794
|
-
expect(nerdamer('1-[a,b]').toString()).toEqual('[-a+1,-b+1]');
|
|
1795
|
-
expect(nerdamer('[a,b]-1').toString()).toEqual('[-1+a,-1+b]');
|
|
1796
|
-
expect(nerdamer('[a,b]-[a,b]').toString()).toEqual('[0,0]');
|
|
1797
|
-
});
|
|
1798
|
-
it('should multiply vectors correctly', function() {
|
|
1799
|
-
expect(nerdamer('3*[a,b]').toString()).toEqual('[3*a,3*b]');
|
|
1800
|
-
expect(nerdamer('[a,b]*x').toString()).toEqual('[a*x,b*x]');
|
|
1801
|
-
expect(nerdamer('[a,b]*[a,b]').toString()).toEqual('[a^2,b^2]');
|
|
1802
|
-
});
|
|
1803
|
-
it('should divide vectors correctly', function() {
|
|
1804
|
-
expect(nerdamer('12/[3,4]').toString()).toEqual('[4,3]');
|
|
1805
|
-
expect(nerdamer('[21,15]/3').toString()).toEqual('[7,5]');
|
|
1806
|
-
expect(nerdamer('[a^2, b^2]/[a,b]').toString()).toEqual('[a,b]');
|
|
1807
|
-
});
|
|
1808
|
-
it('should get slices correctly', function() {
|
|
1809
|
-
expect(nerdamer('[1,2,3][0:2]').toString()).toEqual('[1,2]');
|
|
1810
|
-
});
|
|
1811
|
-
it('should get elements correctly', function() {
|
|
1812
|
-
expect(nerdamer('[1,2,3][1]').toString()).toEqual('2');
|
|
1813
|
-
});
|
|
1814
|
-
it('should remove near duplicates from vectors', function() {
|
|
1815
|
-
expect(nerdamer('vectrim([cos(0), 1, 1.000000000000001])').toString()).toEqual('[1]');
|
|
1816
|
-
expect(nerdamer('vectrim([cos(0), 1, 1.000000000000001], 0)').text()).toEqual('[1,1.000000000000001]');
|
|
1817
|
-
});
|
|
1818
|
-
it('should convert degrees to radians', function() {
|
|
1819
|
-
expect(nerdamer('radians(45)').toString()).toEqual('(1/4)*pi');
|
|
1820
|
-
});
|
|
1821
|
-
it('should convert radians to degrees', function() {
|
|
1822
|
-
expect(nerdamer('degrees(pi/4)').toString()).toEqual('45');
|
|
1823
|
-
});
|
|
1824
|
-
it('should rationalize correctly', function() {
|
|
1825
|
-
expect(nerdamer('rationalize(a/b+c/d+e/f)').toString()).toEqual('(a*d*f+b*c*f+b*d*e)*(b*d*f)^(-1)');
|
|
1826
|
-
expect(nerdamer('rationalize(1/x+x)').toString()).toEqual('(1+x^2)*x^(-1)');
|
|
1827
|
-
expect(nerdamer('rationalize((x+1)/x-1)').toString()).toEqual('x^(-1)');
|
|
1828
|
-
expect(nerdamer('rationalize((a*x^2+b)/x^2-1)').toString()).toEqual('(-x^2+a*x^2+b)*x^(-2)');
|
|
1829
|
-
});
|
|
1830
|
-
it('should handle matrix operations', function() {
|
|
1831
|
-
expect(nerdamer('matrix([3,4])^2').toString()).toEqual('matrix([9,16])');
|
|
1832
|
-
expect(nerdamer('2^matrix([3,4])').toString()).toEqual('matrix([8,16])');
|
|
1833
|
-
expect(nerdamer('2^matrix([3,4])').toString()).toEqual('matrix([8,16])');
|
|
1834
|
-
expect(nerdamer('2*matrix([3,4])').toString()).toEqual('matrix([6,8])');
|
|
1835
|
-
expect(nerdamer('matrix([1,2])+matrix([8,4])').toString()).toEqual('matrix([9,6])');
|
|
1836
|
-
expect(nerdamer('2+matrix([3,4])').toString()).toEqual('matrix([5,6])');
|
|
1837
|
-
expect(nerdamer('2-matrix([3,4])').toString()).toEqual('matrix([-1,-2])');
|
|
1838
|
-
expect(nerdamer('matrix([1,2])-matrix([8,4])').toString()).toEqual('matrix([-7,-2])');
|
|
1839
|
-
expect(nerdamer('matrix([3,4])-2').toString()).toEqual('matrix([1,2])');
|
|
1840
|
-
expect(nerdamer('matrix([8,4])/2').toString()).toEqual('matrix([4,2])');
|
|
1841
|
-
expect(nerdamer('matrix([1,2])/matrix([8,4])').toString()).toEqual('matrix([1/8,1/2])');
|
|
1842
|
-
expect(nerdamer('16/matrix([8,4])').toString()).toEqual('matrix([2,4])');
|
|
1843
|
-
});
|
|
1844
|
-
it('should perform scientific rounding', function() {
|
|
1845
|
-
expect(nerdamer('12/7*x+cos(33333333333333333)-11/17').text('scientific')).toEqual('-6.47058823529412e-1+1.71428571428571*x+cos(3.33333333333333e16)');
|
|
1846
|
-
expect(nerdamer('7/(11*x-24*x^2)+cos(13/44)^(300/21)').text('scientific')).toEqual('7*(-2.4e1*x^2+1.1e1*x)^(-1)+cos(2.95454545454545e-1)^1.42857142857143e1');
|
|
1847
|
-
});
|
|
1848
|
-
it('should throw for even negative powers in nthroots', function() {
|
|
1849
|
-
expect(function() {nerdamer('nthroot(-9, 2)').evaluate(); }).toThrowError();
|
|
1850
|
-
});
|
|
1851
|
-
it('should throw for zero powers in nthroots', function() {
|
|
1852
|
-
expect(function() {nerdamer('nthroot(-9, 0)').evaluate(); }).toThrowError();
|
|
1853
|
-
});
|
|
1854
|
-
it('should calculate nthroots', function() {
|
|
1855
|
-
expect(nerdamer('nthroot(-8, 3)').evaluate().text()).toEqual('-2');
|
|
1856
|
-
expect(nerdamer('nthroot(sqrt(64), sqrt(9))').evaluate().text()).toEqual('2');
|
|
1857
|
-
expect(nerdamer('nthroot(-1, 3)').evaluate().text()).toEqual('-1');
|
|
1858
|
-
expect(nerdamer('nthroot(-7, 3)').evaluate().text()).toEqual('-1.912931182772388873');
|
|
1859
|
-
expect(nerdamer('nthroot(-x*8, 3)').evaluate().text()).toEqual('nthroot(-8*x,3)');
|
|
1860
|
-
});
|
|
1861
|
-
it('should calculate cube roots', function () {
|
|
1862
|
-
expect(nerdamer('cbrt(8)').evaluate().text()).toEqual('2');
|
|
1863
|
-
expect(nerdamer('cbrt(x)').evaluate().text()).toEqual('cbrt(x)');
|
|
1864
|
-
expect(nerdamer('cbrt(27*x^3)').evaluate().text()).toEqual('3*x');
|
|
1865
|
-
expect(nerdamer('cbrt((y^3*x^3))').evaluate().text()).toEqual('x*y');
|
|
1866
|
-
});
|
|
1867
|
-
it('should correctly build a JS function', function () {
|
|
1868
|
-
expect(nerdamer('acos((-x)^(1/6))').buildFunction()(0)).toEqual(1.5707963267948966);
|
|
1869
|
-
//factorials
|
|
1870
|
-
expect(nerdamer('x^2+x!').buildFunction()(4)).toEqual(40);
|
|
1871
|
-
});
|
|
1872
|
-
it('should correctly build for a nerdamer defined function', function () {
|
|
1873
|
-
//Note: this may break at some point when big numbers are implemented
|
|
1874
|
-
expect(nerdamer('Ci(x)+x').buildFunction()(4)).toEqual(3.8590183021130704);
|
|
1875
|
-
});
|
|
1876
|
-
it('should handle nested functions', function() {
|
|
1877
|
-
nerdamer.setFunction("a", ["x"], "2*x")
|
|
1878
|
-
nerdamer.setFunction("b", ["x"], "x^2")
|
|
1879
|
-
|
|
1880
|
-
expect(nerdamer("a(b(x))").text()).toEqual('2*x^2');
|
|
1881
|
-
});
|
|
1882
|
-
it('should handle percent', function() {
|
|
1883
|
-
expect(nerdamer('10%+20%').toString()).toEqual('3/10');
|
|
1884
|
-
expect(nerdamer('a%/10%').toString()).toEqual('(1/10)*a');
|
|
1885
|
-
expect(nerdamer('x%-x%').toString()).toEqual('0');
|
|
1886
|
-
expect(nerdamer('x%*x%').toString()).toEqual('(1/10000)*x^2');
|
|
1887
|
-
});
|
|
1888
|
-
it('should recognize the mod and percent operator', function() {
|
|
1889
|
-
expect(nerdamer('3*(a%%b%)').toString()).toEqual('3*mod((1/100)*a,(1/100)*b)')
|
|
1890
|
-
});
|
|
1891
|
-
it('should rewrite e as exp', function() {
|
|
1892
|
-
block('E_TO_EXP', function() {
|
|
1893
|
-
expect(nerdamer('(3*e^(e^(x))+tan(-e^x))+a').toString()).toEqual('3*exp(exp(x))+a+tan(-exp(x))');
|
|
1894
|
-
});
|
|
1895
|
-
});
|
|
1896
|
-
it('should unwrap even abs', function() {
|
|
1897
|
-
expect(nerdamer('(3*abs(x))^2').toString()).toEqual('3*x^2');
|
|
1898
|
-
});
|
|
1899
|
-
});
|
|
1900
|
-
|
|
1901
|
-
describe('Further arithmetic test cases', function () {
|
|
1902
|
-
it('Batch 1', function () {
|
|
1903
|
-
// given
|
|
1904
|
-
var testCases = [
|
|
1905
|
-
{
|
|
1906
|
-
given: '(x+x^2)+x',
|
|
1907
|
-
expected: '2*x+x^2',
|
|
1908
|
-
expectedValue: '8.61'
|
|
1909
|
-
},
|
|
1910
|
-
{
|
|
1911
|
-
given: '(x+1)+4',
|
|
1912
|
-
expected: '5+x',
|
|
1913
|
-
expectedValue: '7.1'
|
|
1914
|
-
},
|
|
1915
|
-
{
|
|
1916
|
-
given: 'x+x+1+x',
|
|
1917
|
-
expected: '1+3*x',
|
|
1918
|
-
expectedValue: '7.3'
|
|
1919
|
-
},
|
|
1920
|
-
{
|
|
1921
|
-
given: '(x+1)+(8+y)',
|
|
1922
|
-
expected: '9+x+y',
|
|
1923
|
-
expectedValue: '14.4'
|
|
1924
|
-
},
|
|
1925
|
-
{
|
|
1926
|
-
given: '(x+1)+(a+y)',
|
|
1927
|
-
expected: '1+a+x+y',
|
|
1928
|
-
expectedValue: '13.82'
|
|
1929
|
-
},
|
|
1930
|
-
{
|
|
1931
|
-
given: '(x+x^2)+(x^3+x)',
|
|
1932
|
-
expected: '2*x+x^2+x^3',
|
|
1933
|
-
expectedValue: '17.871000000000002'
|
|
1934
|
-
},
|
|
1935
|
-
{
|
|
1936
|
-
given: '3*(x+x^2)+5*(x^3+x)',
|
|
1937
|
-
expected: '3*x^2+5*x^3+8*x',
|
|
1938
|
-
expectedValue: '76.33500000000001'
|
|
1939
|
-
},
|
|
1940
|
-
|
|
1941
|
-
{
|
|
1942
|
-
given: '2*(1+x)*3*(z+x)^x*8',
|
|
1943
|
-
expected: '48*(1+x)*(x+z)^x',
|
|
1944
|
-
expectedValue: '1601.2623349876335'
|
|
1945
|
-
},
|
|
1946
|
-
{
|
|
1947
|
-
given: '(x+x^2)*(x+x^2)',
|
|
1948
|
-
expected: '(x+x^2)^2',
|
|
1949
|
-
expectedValue: '42.3801'
|
|
1950
|
-
},
|
|
1951
|
-
{
|
|
1952
|
-
given: '(x+x^2)*2*(x+x^2)',
|
|
1953
|
-
expected: '2*(x+x^2)^2',
|
|
1954
|
-
expectedValue: '84.7602'
|
|
1955
|
-
},
|
|
1956
|
-
{
|
|
1957
|
-
given: '(x*y)*(x*y)',
|
|
1958
|
-
expected: '(x*y)^2',
|
|
1959
|
-
expectedValue: '48.024899999999995'
|
|
1960
|
-
},
|
|
1961
|
-
{
|
|
1962
|
-
given: '(x*y)*(x*z)',
|
|
1963
|
-
expected: 'x^2*y*z',
|
|
1964
|
-
expectedValue: '14.553'
|
|
1965
|
-
},
|
|
1966
|
-
{
|
|
1967
|
-
given: '(x+y)*(x+y)',
|
|
1968
|
-
expected: '(x+y)^2',
|
|
1969
|
-
expectedValue: '29.160000000000004'
|
|
1970
|
-
},
|
|
1971
|
-
{
|
|
1972
|
-
given: '(x+y)*(y+x)',
|
|
1973
|
-
expected: '(x+y)^2',
|
|
1974
|
-
expectedValue: '29.160000000000004'
|
|
1975
|
-
},
|
|
1976
|
-
{
|
|
1977
|
-
given: '(1+x)*(x+y)',
|
|
1978
|
-
expected: '(1+x)*(x+y)',
|
|
1979
|
-
expectedValue: '16.74'
|
|
1980
|
-
},
|
|
1981
|
-
{
|
|
1982
|
-
given: 'x*y*x',
|
|
1983
|
-
expected: 'x^2*y',
|
|
1984
|
-
expectedValue: '14.553'
|
|
1985
|
-
},
|
|
1986
|
-
{
|
|
1987
|
-
given: 'x*y*x/x',
|
|
1988
|
-
expected: 'x*y',
|
|
1989
|
-
expectedValue: '6.93'
|
|
1990
|
-
},
|
|
1991
|
-
{
|
|
1992
|
-
given: 'x*y*x/x/x/y',
|
|
1993
|
-
expected: '1',
|
|
1994
|
-
expectedValue: '1'
|
|
1995
|
-
},
|
|
1996
|
-
{
|
|
1997
|
-
given: '(x+1)^x*(z+1)^z*(x+1)',
|
|
1998
|
-
expected: '(1+x)^(1+x)*(1+z)^z',
|
|
1999
|
-
expectedValue: '66.71926395781806'
|
|
2000
|
-
},
|
|
2001
|
-
{
|
|
2002
|
-
given: '3*(x^2+1)^x*(2*(x^2+1))',
|
|
2003
|
-
expected: '6*(1+x^2)^(1+x)',
|
|
2004
|
-
expectedValue: '1124.7675342780879'
|
|
2005
|
-
},
|
|
2006
|
-
{
|
|
2007
|
-
given: '2*(x+x^2)+1',
|
|
2008
|
-
expected: '1+2*x+2*x^2',
|
|
2009
|
-
expectedValue: '14.02'
|
|
2010
|
-
},
|
|
2011
|
-
{
|
|
2012
|
-
given: '2*(x+x^2)+3*(x^2+x^3)',
|
|
2013
|
-
expected: '2*x+3*x^3+5*x^2',
|
|
2014
|
-
expectedValue: '54.033'
|
|
2015
|
-
},
|
|
2016
|
-
{
|
|
2017
|
-
given: '2*(x+x^2)+3*(x^2+x^3)^2',
|
|
2018
|
-
expected: '2*x+2*x^2+3*(x^2+x^3)^2',
|
|
2019
|
-
expectedValue: '573.7087230000001'
|
|
2020
|
-
},
|
|
2021
|
-
{
|
|
2022
|
-
given: '2*(x+x^2)+3*(x^2+x^3)^2+x',
|
|
2023
|
-
expected: '2*x^2+3*x+3*(x^2+x^3)^2',
|
|
2024
|
-
expectedValue: '575.8087230000001'
|
|
2025
|
-
},
|
|
2026
|
-
{
|
|
2027
|
-
given: '2*(x+x^2)+3*(x^2+x^3)^2+(x^2+x)',
|
|
2028
|
-
expected: '3*(x^2+x^3)^2+3*x+3*x^2',
|
|
2029
|
-
expectedValue: '580.218723'
|
|
2030
|
-
}
|
|
2031
|
-
];
|
|
2032
|
-
|
|
2033
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
2034
|
-
// when
|
|
2035
|
-
var parsed = nerdamer(testCases[i].given);
|
|
2036
|
-
var value = parsed.evaluate(values).text('decimals');
|
|
2037
|
-
|
|
2038
|
-
// then
|
|
2039
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
2040
|
-
expect(round(value, 14)).toEqual(round(testCases[i].expectedValue),14);
|
|
2041
|
-
}
|
|
2042
|
-
});
|
|
2043
|
-
it('Batch 2', function () {
|
|
2044
|
-
// given
|
|
2045
|
-
var testCases = [
|
|
2046
|
-
{
|
|
2047
|
-
given: '2*(x+x^2)^2+3*(x^2+x)^2',
|
|
2048
|
-
expected: '5*(x+x^2)^2',
|
|
2049
|
-
expectedValue: '211.9005'
|
|
2050
|
-
},
|
|
2051
|
-
{
|
|
2052
|
-
given: '2*(x+x^2)^2+2*(x+x^2)^3+4*(x+x^2)^2',
|
|
2053
|
-
expected: '2*(x+x^2)^3+6*(x+x^2)^2',
|
|
2054
|
-
expectedValue: '806.069502'
|
|
2055
|
-
},
|
|
2056
|
-
{
|
|
2057
|
-
given: '2*x^2+3*x+y+y^2',
|
|
2058
|
-
expected: '2*x^2+3*x+y+y^2',
|
|
2059
|
-
expectedValue: '29.31'
|
|
2060
|
-
},
|
|
2061
|
-
{
|
|
2062
|
-
given: '(y+y^2)^6+y',
|
|
2063
|
-
expected: '(y+y^2)^6+y',
|
|
2064
|
-
expectedValue: '8163841.198203677'
|
|
2065
|
-
},
|
|
2066
|
-
{
|
|
2067
|
-
given: '2*(x+x^2)+(y+y^2)^6+y',
|
|
2068
|
-
expected: '(y+y^2)^6+2*x+2*x^2+y',
|
|
2069
|
-
expectedValue: '8163854.218203676'
|
|
2070
|
-
},
|
|
2071
|
-
{
|
|
2072
|
-
given: '2*(x+x^2)+4',
|
|
2073
|
-
expected: '2*x+2*x^2+4',
|
|
2074
|
-
expectedValue: '17.02'
|
|
2075
|
-
},
|
|
2076
|
-
{
|
|
2077
|
-
given: '2*(x+x^2)+48*x*y',
|
|
2078
|
-
expected: '2*(x+x^2)+48*x*y',
|
|
2079
|
-
expectedValue: '345.66'
|
|
2080
|
-
},
|
|
2081
|
-
{
|
|
2082
|
-
given: '2*(x+x^2)+(48+x+2*y)',
|
|
2083
|
-
expected: '2*x^2+3*x+2*y+48',
|
|
2084
|
-
expectedValue: '69.72'
|
|
2085
|
-
},
|
|
2086
|
-
{
|
|
2087
|
-
given: '(x^2+1)-1',
|
|
2088
|
-
expected: 'x^2',
|
|
2089
|
-
expectedValue: '4.41'
|
|
2090
|
-
},
|
|
2091
|
-
{
|
|
2092
|
-
given: '(x^2+1)-1+x+x^3+x',
|
|
2093
|
-
expected: '2*x+x^2+x^3',
|
|
2094
|
-
expectedValue: '17.871000000000002'
|
|
2095
|
-
},
|
|
2096
|
-
{
|
|
2097
|
-
given: '5+(x^2+y+1)+(x+y+15)',
|
|
2098
|
-
expected: '2*y+21+x+x^2',
|
|
2099
|
-
expectedValue: '34.11'
|
|
2100
|
-
},
|
|
2101
|
-
{
|
|
2102
|
-
given: '(x^2+y+1)+(x+y+15)+(x^2+y+1)',
|
|
2103
|
-
expected: '17+2*x^2+x+3*y',
|
|
2104
|
-
expectedValue: '37.82'
|
|
2105
|
-
},
|
|
2106
|
-
{
|
|
2107
|
-
given: '(x^2+y+1)+(x+x^2)',
|
|
2108
|
-
expected: '1+2*x^2+x+y',
|
|
2109
|
-
expectedValue: '15.22'
|
|
2110
|
-
},
|
|
2111
|
-
{
|
|
2112
|
-
given: '(1+(1+x)^2)',
|
|
2113
|
-
expected: '(1+x)^2+1',
|
|
2114
|
-
expectedValue: '10.610000000000001'
|
|
2115
|
-
},
|
|
2116
|
-
{
|
|
2117
|
-
given: '(x+x)^x',
|
|
2118
|
-
expected: '2^x*x^x',
|
|
2119
|
-
expectedValue: '20.36214425352342'
|
|
2120
|
-
},
|
|
2121
|
-
{
|
|
2122
|
-
given: '1/4*2^x*x^x',
|
|
2123
|
-
expected: '(1/4)*2^x*x^x',
|
|
2124
|
-
expectedValue: '5.090536063380855'
|
|
2125
|
-
},
|
|
2126
|
-
{
|
|
2127
|
-
given: 'x^2+x-x^y+x',
|
|
2128
|
-
expected: '-x^y+2*x+x^2',
|
|
2129
|
-
expectedValue: '-2.9597419502414644'
|
|
2130
|
-
},
|
|
2131
|
-
{
|
|
2132
|
-
given: 'x^x+x^x-1-2*x^x',
|
|
2133
|
-
expected: '-1',
|
|
2134
|
-
expectedValue: '-1'
|
|
2135
|
-
},
|
|
2136
|
-
{
|
|
2137
|
-
given: 'x^x+x^x-1-2*x^x+2*y+1-2*y',
|
|
2138
|
-
expected: '0',
|
|
2139
|
-
expectedValue: '0'
|
|
2140
|
-
},
|
|
2141
|
-
{
|
|
2142
|
-
given: '(x+1)-x*y-5+2*x*y',
|
|
2143
|
-
expected: '-4+x+x*y',
|
|
2144
|
-
expectedValue: '5.03'
|
|
2145
|
-
},
|
|
2146
|
-
{
|
|
2147
|
-
given: '(2*x-y+7-x+y-x-5)*2+15/3',
|
|
2148
|
-
expected: '9',
|
|
2149
|
-
expectedValue: '9'
|
|
2150
|
-
},
|
|
2151
|
-
{
|
|
2152
|
-
given: '(x+x^2)^x*x',
|
|
2153
|
-
expected: '(x+x^2)^x*x',
|
|
2154
|
-
expectedValue: '107.33450820142282'
|
|
2155
|
-
},
|
|
2156
|
-
{
|
|
2157
|
-
given: '(x+x^2)^x*(x+x^x)',
|
|
2158
|
-
expected: '(x+x^2)^x*(x+x^x)',
|
|
2159
|
-
expectedValue: '350.09644568327894'
|
|
2160
|
-
},
|
|
2161
|
-
{
|
|
2162
|
-
given: '(x+x^2)^2*x',
|
|
2163
|
-
expected: '(x+x^2)^2*x',
|
|
2164
|
-
expectedValue: '88.99821'
|
|
2165
|
-
},
|
|
2166
|
-
{
|
|
2167
|
-
given: '(z+z^2)^x*(x+y^2+1)',
|
|
2168
|
-
expected: '(1+x+y^2)*(z+z^2)^x',
|
|
2169
|
-
expectedValue: '59.976442963530964'
|
|
2170
|
-
},
|
|
2171
|
-
{
|
|
2172
|
-
given: '(x+1)/(x+1)',
|
|
2173
|
-
expected: '1',
|
|
2174
|
-
expectedValue: '1'
|
|
2175
|
-
},
|
|
2176
|
-
{
|
|
2177
|
-
given: 'x*y*z/(x*y*z)',
|
|
2178
|
-
expected: '1',
|
|
2179
|
-
expectedValue: '1'
|
|
2180
|
-
},
|
|
2181
|
-
{
|
|
2182
|
-
given: 'x^y/x^y',
|
|
2183
|
-
expected: '1',
|
|
2184
|
-
expectedValue: '1'
|
|
2185
|
-
},
|
|
2186
|
-
{
|
|
2187
|
-
given: '4*x^2',
|
|
2188
|
-
expected: '4*x^2',
|
|
2189
|
-
expectedValue: '17.64'
|
|
2190
|
-
},
|
|
2191
|
-
{
|
|
2192
|
-
given: '5*x^y/x^y',
|
|
2193
|
-
expected: '5',
|
|
2194
|
-
expectedValue: '5'
|
|
2195
|
-
},
|
|
2196
|
-
{
|
|
2197
|
-
given: '(x+x^6)^y/(x+x^6)^y',
|
|
2198
|
-
expected: '1',
|
|
2199
|
-
expectedValue: '1'
|
|
2200
|
-
},
|
|
2201
|
-
{
|
|
2202
|
-
given: '2^y*2^y',
|
|
2203
|
-
expected: '2^(2*y)',
|
|
2204
|
-
expectedValue: '97.00586025666546'
|
|
2205
|
-
},
|
|
2206
|
-
{
|
|
2207
|
-
given: '2^x',
|
|
2208
|
-
expected: '2^x',
|
|
2209
|
-
expectedValue: '4.2870938501451725'
|
|
2210
|
-
},
|
|
2211
|
-
{
|
|
2212
|
-
given: '((x^3+x)^x*(x^2+x)^x+1)*x',
|
|
2213
|
-
expected: '((x+x^2)^x*(x+x^3)^x+1)*x',
|
|
2214
|
-
expectedValue: '17667.12052556627'
|
|
2215
|
-
}
|
|
2216
|
-
];
|
|
2217
|
-
|
|
2218
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
2219
|
-
// when
|
|
2220
|
-
var parsed = nerdamer(testCases[i].given);
|
|
2221
|
-
var value = parsed.evaluate(values).text('decimals');
|
|
2222
|
-
|
|
2223
|
-
// then
|
|
2224
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
2225
|
-
expect(round(value, 8)).toEqual(round(testCases[i].expectedValue ,8));
|
|
2226
|
-
}
|
|
2227
|
-
});
|
|
2228
|
-
it('Batch 3', function () {
|
|
2229
|
-
var testCases = [
|
|
2230
|
-
{
|
|
2231
|
-
given: '(8*x)^(2/3)',
|
|
2232
|
-
expected: '4*x^(2/3)',
|
|
2233
|
-
expectedValue: '6.559531991200272'
|
|
2234
|
-
},
|
|
2235
|
-
{
|
|
2236
|
-
given: '(y^3+2)/(z^4*(y^3/2))^2*cos(x)*sqrt(x)',
|
|
2237
|
-
expected: '4*(2+y^3)*(y^3*z^4)^(-2)*cos(x)*sqrt(x)',
|
|
2238
|
-
expectedValue: '-0.08596229340057991'
|
|
2239
|
-
},
|
|
2240
|
-
{
|
|
2241
|
-
given: '2*x^4*(1+log(x)^2)-(-x^4)',
|
|
2242
|
-
expected: '2*(1+log(x)^2)*x^4+x^4',
|
|
2243
|
-
expectedValue: '79.75553102441935'
|
|
2244
|
-
},
|
|
2245
|
-
{
|
|
2246
|
-
given: '(x^6)^(1/4)',
|
|
2247
|
-
expected: 'abs(x)^(3/2)',
|
|
2248
|
-
expectedValue: '3.043189116699782'
|
|
2249
|
-
},
|
|
2250
|
-
{
|
|
2251
|
-
given: '2*x*(4^(1/3))^3',
|
|
2252
|
-
expected: '8*x',
|
|
2253
|
-
expectedValue: '16.8'
|
|
2254
|
-
},
|
|
2255
|
-
{
|
|
2256
|
-
given: '6*(4^(1/3)*4^(2/3))',
|
|
2257
|
-
expected: '24',
|
|
2258
|
-
expectedValue: '24'
|
|
2259
|
-
},
|
|
2260
|
-
{
|
|
2261
|
-
given: '(5*(4^(1/3)))^3',
|
|
2262
|
-
expected: '500',
|
|
2263
|
-
expectedValue: '500'
|
|
2264
|
-
},
|
|
2265
|
-
{
|
|
2266
|
-
given: '2*x*(5*(4^(1/3)))^3',
|
|
2267
|
-
expected: '1000*x',
|
|
2268
|
-
expectedValue: '2100'
|
|
2269
|
-
},
|
|
2270
|
-
{
|
|
2271
|
-
given: 'y^y^y',
|
|
2272
|
-
expected: 'y^y^y',
|
|
2273
|
-
expectedValue: '456848755025637200000000000'
|
|
2274
|
-
},
|
|
2275
|
-
{
|
|
2276
|
-
given: '(x^4)^(1/4)',
|
|
2277
|
-
expected: 'abs(x)',
|
|
2278
|
-
expectedValue: '2.1'
|
|
2279
|
-
},
|
|
2280
|
-
{
|
|
2281
|
-
given: '(-2*x)^2',
|
|
2282
|
-
expected: '4*x^2',
|
|
2283
|
-
expectedValue: '17.64'
|
|
2284
|
-
},
|
|
2285
|
-
{
|
|
2286
|
-
given: '-4*x^3--x^3+x^2-(-2*x)^2+y',
|
|
2287
|
-
expected: '-3*x^2-3*x^3+y',
|
|
2288
|
-
expectedValue: '-37.713'
|
|
2289
|
-
},
|
|
2290
|
-
{
|
|
2291
|
-
given: '2*x/x',
|
|
2292
|
-
expected: '2',
|
|
2293
|
-
expectedValue: '2'
|
|
2294
|
-
},
|
|
2295
|
-
{
|
|
2296
|
-
given: '(x^2*y)^2',
|
|
2297
|
-
expected: 'x^4*y^2',
|
|
2298
|
-
expectedValue: '211.78980899999996'
|
|
2299
|
-
},
|
|
2300
|
-
{
|
|
2301
|
-
given: '(x+1)^(z+1)*(1+x)^(1+z)',
|
|
2302
|
-
expected: '(1+x)^(2+2*z)',
|
|
2303
|
-
expectedValue: '92.35210000000002'
|
|
2304
|
-
},
|
|
2305
|
-
{
|
|
2306
|
-
given: '(x+1)^(z+1)*(1+x)^4',
|
|
2307
|
-
expected: '(1+x)^(5+z)',
|
|
2308
|
-
expectedValue: '887.5036810000004'
|
|
2309
|
-
},
|
|
2310
|
-
{
|
|
2311
|
-
given: '(-1)^x',
|
|
2312
|
-
expected: '(-1)^x',
|
|
2313
|
-
expectedValue: '(-1)^2.1'
|
|
2314
|
-
},
|
|
2315
|
-
{
|
|
2316
|
-
given: '(-25)^(1/5)',
|
|
2317
|
-
expected: '(-1)^(1/5)*5^(2/5)',
|
|
2318
|
-
expectedValue: '-1.9036539387158786'
|
|
2319
|
-
},
|
|
2320
|
-
{
|
|
2321
|
-
given: '-24.160787001838543^1.3^(-1)',
|
|
2322
|
-
expected: '-108007829^(-10/13)*2609554151^(10/13)',
|
|
2323
|
-
expectedValue: '-11.585948599615737'
|
|
2324
|
-
},
|
|
2325
|
-
{
|
|
2326
|
-
given: '(x+y)--(x+y)',
|
|
2327
|
-
expected: '2*x+2*y',
|
|
2328
|
-
expectedValue: '10.8'
|
|
2329
|
-
},
|
|
2330
|
-
{
|
|
2331
|
-
given: '-z-(r+x)--(r+x)',
|
|
2332
|
-
expected: '-z',
|
|
2333
|
-
expectedValue: '-1'
|
|
2334
|
-
},
|
|
2335
|
-
{
|
|
2336
|
-
given: '+-z-(r+x)+--+(r+x)',
|
|
2337
|
-
expected: '-z',
|
|
2338
|
-
expectedValue: '-1'
|
|
2339
|
-
},
|
|
2340
|
-
{
|
|
2341
|
-
given: '(x)^(3-x)',
|
|
2342
|
-
expected: 'x^(-x+3)',
|
|
2343
|
-
expectedValue: '1.9498327706486203'
|
|
2344
|
-
},
|
|
2345
|
-
{
|
|
2346
|
-
given: '(1/2*x)^(1/2)',
|
|
2347
|
-
expected: 'sqrt(2)^(-1)*sqrt(x)',
|
|
2348
|
-
expectedValue: '1.02469507659596'
|
|
2349
|
-
},
|
|
2350
|
-
{
|
|
2351
|
-
given: '256^(1/8)',
|
|
2352
|
-
expected: '2',
|
|
2353
|
-
expectedValue: '2'
|
|
2354
|
-
},
|
|
2355
|
-
{
|
|
2356
|
-
given: '-2*256^(1/8)',
|
|
2357
|
-
expected: '-4',
|
|
2358
|
-
expectedValue: '-4'
|
|
2359
|
-
},
|
|
2360
|
-
{
|
|
2361
|
-
given: '(81*(x*y)^2+9*x*y)+(9*x*y)',
|
|
2362
|
-
expected: '18*x*y+81*x^2*y^2',
|
|
2363
|
-
expectedValue: '4014.7568999999994'
|
|
2364
|
-
},
|
|
2365
|
-
{
|
|
2366
|
-
given: '((x)^(1/2)*x^(1/3))-x^(5/6)',
|
|
2367
|
-
expected: '0',
|
|
2368
|
-
expectedValue: '0'
|
|
2369
|
-
},
|
|
2370
|
-
{
|
|
2371
|
-
given: '(9*y*x+1)^3',
|
|
2372
|
-
expected: '(1+9*x*y)^3',
|
|
2373
|
-
expectedValue: '254478.51475299997'
|
|
2374
|
-
},
|
|
2375
|
-
{
|
|
2376
|
-
given: '(81*(x*y)^2+9*x*y)*(9*x*y)',
|
|
2377
|
-
expected: '9*(81*x^2*y^2+9*x*y)*x*y',
|
|
2378
|
-
expectedValue: '246510.37095299995'
|
|
2379
|
-
},
|
|
2380
|
-
{
|
|
2381
|
-
given: '2*((81*(x*y)^2+9*x*y))*(5*(9*x*y))',
|
|
2382
|
-
expected: '90*(81*x^2*y^2+9*x*y)*x*y',
|
|
2383
|
-
expectedValue: '2465103.7095299996'
|
|
2384
|
-
}
|
|
2385
|
-
];
|
|
2386
|
-
|
|
2387
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
2388
|
-
// when
|
|
2389
|
-
var parsed = nerdamer(testCases[i].given);
|
|
2390
|
-
var value = parsed.evaluate(values).text('decimals', 18);
|
|
2391
|
-
|
|
2392
|
-
// then
|
|
2393
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
2394
|
-
expect(round(value, 12)).toEqual(round(testCases[i].expectedValue ,12));
|
|
2395
|
-
}
|
|
2396
|
-
});
|
|
2397
|
-
it('Batch 4', function() {
|
|
2398
|
-
var testCases = [
|
|
2399
|
-
{
|
|
2400
|
-
given: '5*(x+x^2)*(2*(x+x^2)^x)',
|
|
2401
|
-
expected: '10*(x+x^2)^(1+x)',
|
|
2402
|
-
expectedValue: '3327.3697542441078'
|
|
2403
|
-
},
|
|
2404
|
-
{
|
|
2405
|
-
given: '(x+x^2)^x*(x+x^2)',
|
|
2406
|
-
expected: '(x+x^2)^(1+x)',
|
|
2407
|
-
expectedValue: '332.7369754244108'
|
|
2408
|
-
}
|
|
2409
|
-
];
|
|
2410
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
2411
|
-
// when
|
|
2412
|
-
var parsed = nerdamer(testCases[i].given);
|
|
2413
|
-
var value = parsed.evaluate(values).text('decimals');
|
|
2414
|
-
|
|
2415
|
-
// then
|
|
2416
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
2417
|
-
expect(_(value, 10)).toEqual(_(testCases[i].expectedValue, 10));
|
|
2418
|
-
}
|
|
2419
|
-
})
|
|
2420
|
-
});
|
|
2421
|
-
|
|
2422
|
-
describe('trigonometric functions', function () {
|
|
2423
|
-
it('should be computed properly', function () {
|
|
2424
|
-
// given
|
|
2425
|
-
var testCases = [
|
|
2426
|
-
{
|
|
2427
|
-
given: 'cos(pi)',
|
|
2428
|
-
expected: '-1',
|
|
2429
|
-
expectedValue: '-1'
|
|
2430
|
-
},
|
|
2431
|
-
{
|
|
2432
|
-
given: 'cos(2*pi)',
|
|
2433
|
-
expected: '1',
|
|
2434
|
-
expectedValue: '1'
|
|
2435
|
-
},
|
|
2436
|
-
{
|
|
2437
|
-
given: 'cos(2*pi/3)',
|
|
2438
|
-
expected: '-1/2',
|
|
2439
|
-
expectedValue: '-0.5'
|
|
2440
|
-
},
|
|
2441
|
-
{
|
|
2442
|
-
given: 'cos(3*pi/4)',
|
|
2443
|
-
expected: '-sqrt(2)^(-1)',
|
|
2444
|
-
expectedValue: '-0.7071067811865475'
|
|
2445
|
-
},
|
|
2446
|
-
{
|
|
2447
|
-
given: 'sin(pi)',
|
|
2448
|
-
expected: '0',
|
|
2449
|
-
expectedValue: '0'
|
|
2450
|
-
},
|
|
2451
|
-
{
|
|
2452
|
-
given: 'sin(pi/2)',
|
|
2453
|
-
expected: '1',
|
|
2454
|
-
expectedValue: '1'
|
|
2455
|
-
},
|
|
2456
|
-
{
|
|
2457
|
-
given: 'sin(-pi/2)',
|
|
2458
|
-
expected: '-1',
|
|
2459
|
-
expectedValue: '-1'
|
|
2460
|
-
},
|
|
2461
|
-
{
|
|
2462
|
-
given: 'sin(3*pi/4)',
|
|
2463
|
-
expected: 'sqrt(2)^(-1)',
|
|
2464
|
-
expectedValue: '0.7071067811865475'
|
|
2465
|
-
},
|
|
2466
|
-
{
|
|
2467
|
-
given: 'tan(3*pi/4)',
|
|
2468
|
-
expected: '-1',
|
|
2469
|
-
expectedValue: '-1'
|
|
2470
|
-
},
|
|
2471
|
-
{
|
|
2472
|
-
given: 'tan(2*pi/3)',
|
|
2473
|
-
expected: '-sqrt(3)',
|
|
2474
|
-
expectedValue: '-1.7320508075688772'
|
|
2475
|
-
},
|
|
2476
|
-
{
|
|
2477
|
-
given: 'tan(4*pi/3)',
|
|
2478
|
-
expected: 'sqrt(3)',
|
|
2479
|
-
expectedValue: '1.7320508075688772'
|
|
2480
|
-
},
|
|
2481
|
-
{
|
|
2482
|
-
given: 'tan(pi/3)',
|
|
2483
|
-
expected: 'sqrt(3)',
|
|
2484
|
-
expectedValue: '1.7320508075688772'
|
|
2485
|
-
},
|
|
2486
|
-
{
|
|
2487
|
-
given: 'tan(pi)',
|
|
2488
|
-
expected: '0',
|
|
2489
|
-
expectedValue: '0'
|
|
2490
|
-
},
|
|
2491
|
-
{
|
|
2492
|
-
given: 'sec(pi)',
|
|
2493
|
-
expected: '-1',
|
|
2494
|
-
expectedValue: '-1'
|
|
2495
|
-
},
|
|
2496
|
-
{
|
|
2497
|
-
given: 'sec(2*pi/3)',
|
|
2498
|
-
expected: '-2',
|
|
2499
|
-
expectedValue: '-2'
|
|
2500
|
-
},
|
|
2501
|
-
{
|
|
2502
|
-
given: 'sec(4*pi/3)',
|
|
2503
|
-
expected: '-2',
|
|
2504
|
-
expectedValue: '-2'
|
|
2505
|
-
},
|
|
2506
|
-
{
|
|
2507
|
-
given: 'sec(5*pi/3)',
|
|
2508
|
-
expected: '2',
|
|
2509
|
-
expectedValue: '2'
|
|
2510
|
-
},
|
|
2511
|
-
{
|
|
2512
|
-
given: 'sec(pi/6)',
|
|
2513
|
-
expected: '2*sqrt(3)^(-1)',
|
|
2514
|
-
expectedValue: '1.1547005383792517'
|
|
2515
|
-
},
|
|
2516
|
-
{
|
|
2517
|
-
given: 'csc(5*pi/3)',
|
|
2518
|
-
expected: '-2*sqrt(3)^(-1)',
|
|
2519
|
-
expectedValue: '-1.1547005383792517'
|
|
2520
|
-
},
|
|
2521
|
-
{
|
|
2522
|
-
given: 'cot(pi/2)',
|
|
2523
|
-
expected: '0',
|
|
2524
|
-
expectedValue: '0'
|
|
2525
|
-
},
|
|
2526
|
-
{
|
|
2527
|
-
given: 'cot(2*pi/3)',
|
|
2528
|
-
expected: '-sqrt(3)^(-1)',
|
|
2529
|
-
expectedValue: '-0.5773502691896258'
|
|
2530
|
-
},
|
|
2531
|
-
{
|
|
2532
|
-
given: 'cot(4*pi/3)',
|
|
2533
|
-
expected: 'sqrt(3)^(-1)',
|
|
2534
|
-
expectedValue: '0.5773502691896258'
|
|
2535
|
-
},
|
|
2536
|
-
{
|
|
2537
|
-
given: 'cot(5*pi/6)',
|
|
2538
|
-
expected: '-sqrt(3)',
|
|
2539
|
-
expectedValue: '-1.7320508075688772'
|
|
2540
|
-
},
|
|
2541
|
-
{
|
|
2542
|
-
given: 'acot(0)',
|
|
2543
|
-
expected: 'acot(0)',
|
|
2544
|
-
expectedValue: '1.5707963267948966'
|
|
2545
|
-
},
|
|
2546
|
-
];
|
|
2547
|
-
|
|
2548
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
2549
|
-
// when
|
|
2550
|
-
var parsed = nerdamer(testCases[i].given);
|
|
2551
|
-
var value = parsed.evaluate().text('decimals');
|
|
2552
|
-
|
|
2553
|
-
// then
|
|
2554
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
2555
|
-
expect(round(value, 14)).toEqual(round(testCases[i].expectedValue),14);
|
|
2556
|
-
}
|
|
2557
|
-
});
|
|
2558
|
-
it('should handle inverse trig in complex domain', function() {
|
|
2559
|
-
expect(nerdamer('asin(2)').evaluate().text()).toEqual('-1.3169578969248164*i+1.570796326794896580');
|
|
2560
|
-
expect(nerdamer('asin(2.19549352839451962743423602992)').evaluate().text()).toEqual('-1.423114269539483*i+1.570796326794896580');
|
|
2561
|
-
expect(nerdamer('acos(2)').evaluate().text()).toEqual('1.3169578969248164*i');
|
|
2562
|
-
expect(nerdamer('atan(i)').evaluate().text()).toEqual('Infinity*i');
|
|
2563
|
-
|
|
2564
|
-
expect(nerdamer('asec(0.89)').evaluate().text()).toEqual('0.000000000000000250+0.4921996534425188*i'); // Has rounding errors
|
|
2565
|
-
expect(nerdamer('acsc(0.23)').evaluate().text()).toEqual('-2.1493278111894223*i+1.570796326794897197'); // Has rounding errors
|
|
2566
|
-
});
|
|
2567
|
-
it('should throw for wrong trigonometric arguments', function () {
|
|
2568
|
-
// given
|
|
2569
|
-
var testCases = [
|
|
2570
|
-
'tan(pi/2)',
|
|
2571
|
-
'sec(pi/2)',
|
|
2572
|
-
'csc(pi)',
|
|
2573
|
-
'csc(2*pi)',
|
|
2574
|
-
'cot(pi)',
|
|
2575
|
-
'cot(2*pi)'
|
|
2576
|
-
];
|
|
2577
|
-
|
|
2578
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
2579
|
-
var threwError = false;
|
|
2580
|
-
try {
|
|
2581
|
-
nerdamer(testCases[i]);
|
|
2582
|
-
} catch (e) {
|
|
2583
|
-
threwError = true;
|
|
2584
|
-
}
|
|
2585
|
-
expect(threwError).toBe(true);
|
|
2586
|
-
}
|
|
2587
|
-
});
|
|
2588
|
-
it('should throw for malformed expression', function () {
|
|
2589
|
-
expect(function(){nerdamer('+');}).toThrowError();
|
|
2590
|
-
expect(function(){nerdamer('(+)');}).toThrowError();
|
|
2591
|
-
expect(function(){nerdamer('cos(');}).toThrowError();
|
|
2592
|
-
expect(function(){nerdamer('(x+1))');}).toThrowError();
|
|
2593
|
-
expect(function(){nerdamer('/2');}).toThrowError();
|
|
2594
|
-
expect(function(){nerdamer('()');}).toThrowError();
|
|
2595
|
-
expect(function(){nerdamer('5+');}).toThrowError();
|
|
2596
|
-
});
|
|
2597
|
-
it('should calculate correctly with variables', function () {
|
|
2598
|
-
// given
|
|
2599
|
-
var testCases = [
|
|
2600
|
-
{
|
|
2601
|
-
given: 'cos(x)',
|
|
2602
|
-
expected: 'cos(x)',
|
|
2603
|
-
expectedValue: '-0.5048461045998576'
|
|
2604
|
-
},
|
|
2605
|
-
{
|
|
2606
|
-
given: 'sin(x)',
|
|
2607
|
-
expected: 'sin(x)',
|
|
2608
|
-
expectedValue: '0.8632093666488737'
|
|
2609
|
-
},
|
|
2610
|
-
{
|
|
2611
|
-
given: 'tan(x)',
|
|
2612
|
-
expected: 'tan(x)',
|
|
2613
|
-
expectedValue: '-1.7098465429045073'
|
|
2614
|
-
},
|
|
2615
|
-
{
|
|
2616
|
-
given: 'y*tan(x)*tan(x)',
|
|
2617
|
-
expected: 'tan(x)^2*y',
|
|
2618
|
-
expectedValue: '9.647798160932235'
|
|
2619
|
-
},
|
|
2620
|
-
{
|
|
2621
|
-
given: '2*cos(x)+cos(x)',
|
|
2622
|
-
expected: '3*cos(x)',
|
|
2623
|
-
expectedValue: '-1.514538313799573'
|
|
2624
|
-
},
|
|
2625
|
-
{
|
|
2626
|
-
given: '2*cos(x)+cos(x+8+5*x)',
|
|
2627
|
-
expected: '2*cos(x)+cos(6*x+8)',
|
|
2628
|
-
expectedValue: '-1.18837521422445'
|
|
2629
|
-
},
|
|
2630
|
-
{
|
|
2631
|
-
given: 'x^2+2*cos(x)+cos(x+8+5*x)+4*x^2',
|
|
2632
|
-
expected: '2*cos(x)+5*x^2+cos(6*x+8)',
|
|
2633
|
-
expectedValue: '20.86162478577555'
|
|
2634
|
-
},
|
|
2635
|
-
{
|
|
2636
|
-
given: 'cos(x)*cos(x)',
|
|
2637
|
-
expected: 'cos(x)^2',
|
|
2638
|
-
expectedValue: '0.25486958932965037'
|
|
2639
|
-
},
|
|
2640
|
-
{
|
|
2641
|
-
given: 'x^x*cos(x)*sin(x)/x',
|
|
2642
|
-
expected: 'cos(x)*sin(x)*x^(-1+x)',
|
|
2643
|
-
expectedValue: '-0.985635592498868'
|
|
2644
|
-
},
|
|
2645
|
-
{
|
|
2646
|
-
given: '2*cos(x)+5*cos(2*x)',
|
|
2647
|
-
expected: '2*cos(x)+5*cos(2*x)',
|
|
2648
|
-
expectedValue: '-3.460996315903212'
|
|
2649
|
-
},
|
|
2650
|
-
{
|
|
2651
|
-
given: '2*cos(x)*5*cos(2*x)',
|
|
2652
|
-
expected: '10*cos(2*x)*cos(x)',
|
|
2653
|
-
expectedValue: '2.4750626589177886'
|
|
2654
|
-
},
|
|
2655
|
-
{
|
|
2656
|
-
given: 'cos(x)+(x+x^2+x)',
|
|
2657
|
-
expected: '2*x+x^2+cos(x)',
|
|
2658
|
-
expectedValue: '8.105153895400143'
|
|
2659
|
-
},
|
|
2660
|
-
{
|
|
2661
|
-
given: 'cos(x)+(x+x^2+7)',
|
|
2662
|
-
expected: '7+cos(x)+x+x^2',
|
|
2663
|
-
expectedValue: '13.005153895400143'
|
|
2664
|
-
},
|
|
2665
|
-
{
|
|
2666
|
-
given: 'x/cos(x)*cos(x)',
|
|
2667
|
-
expected: 'x',
|
|
2668
|
-
expectedValue: '2.1'
|
|
2669
|
-
},
|
|
2670
|
-
{
|
|
2671
|
-
given: 'tan(x)*tan(x)',
|
|
2672
|
-
expected: 'tan(x)^2',
|
|
2673
|
-
expectedValue: '2.923575200282495'
|
|
2674
|
-
},
|
|
2675
|
-
{
|
|
2676
|
-
given: '2*(tan(x)+tan(2*x)+7)-6*tan(x)',
|
|
2677
|
-
expected: '-4*tan(x)+14+2*tan(2*x)',
|
|
2678
|
-
expectedValue: '24.39494572063571'
|
|
2679
|
-
},
|
|
2680
|
-
{
|
|
2681
|
-
given: '((3+y)*2-(cos(x)*4+z))',
|
|
2682
|
-
expected: '-4*cos(x)-z+2*y+6',
|
|
2683
|
-
expectedValue: '13.61938441839943'
|
|
2684
|
-
},
|
|
2685
|
-
{
|
|
2686
|
-
given: 'cos(x^2)*cos(x^2)^x',
|
|
2687
|
-
expected: 'cos(x^2)^(1+x)',
|
|
2688
|
-
expectedValue: '0.023397743182121563*(-1)^3.1'
|
|
2689
|
-
}
|
|
2690
|
-
];
|
|
2691
|
-
|
|
2692
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
2693
|
-
// when
|
|
2694
|
-
var parsed = nerdamer(testCases[i].given);
|
|
2695
|
-
var value = parsed.evaluate(values).text('decimals');
|
|
2696
|
-
|
|
2697
|
-
// then
|
|
2698
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
2699
|
-
expect(round(value, 14)).toEqual(round(testCases[i].expectedValue),14);
|
|
2700
|
-
}
|
|
2701
|
-
});
|
|
2702
|
-
it('should cancel inverses correctly', function () {
|
|
2703
|
-
// given
|
|
2704
|
-
var testCases = [
|
|
2705
|
-
{
|
|
2706
|
-
given: 'cos(x)*sec(x)',
|
|
2707
|
-
expected: '1'
|
|
2708
|
-
},
|
|
2709
|
-
{
|
|
2710
|
-
given: 'sin(x)*csc(x)',
|
|
2711
|
-
expected: '1'
|
|
2712
|
-
},
|
|
2713
|
-
{
|
|
2714
|
-
given: 'tan(x)*cot(x)',
|
|
2715
|
-
expected: '1'
|
|
2716
|
-
},
|
|
2717
|
-
{
|
|
2718
|
-
given: 'cosh(x)*sech(x)',
|
|
2719
|
-
expected: '1'
|
|
2720
|
-
},
|
|
2721
|
-
{
|
|
2722
|
-
given: 'sinh(x)*csch(x)',
|
|
2723
|
-
expected: '1'
|
|
2724
|
-
},
|
|
2725
|
-
{
|
|
2726
|
-
given: 'tanh(x)*coth(x)',
|
|
2727
|
-
expected: '1'
|
|
2728
|
-
}
|
|
2729
|
-
|
|
2730
|
-
];
|
|
2731
|
-
|
|
2732
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
2733
|
-
// when
|
|
2734
|
-
var parsed = nerdamer(testCases[i].given).evaluate();
|
|
2735
|
-
|
|
2736
|
-
// then
|
|
2737
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
2738
|
-
}
|
|
2739
|
-
});
|
|
2740
|
-
it('should handle known trig cases for `numer`', function() {
|
|
2741
|
-
expect(nerdamer('tan(pi)', {}, 'numer').text()).toEqual('0');
|
|
2742
|
-
expect(nerdamer('cot(90*pi/180)', {}, 'numer').text()).toEqual('0');
|
|
2743
|
-
});
|
|
2744
|
-
});
|
|
2745
|
-
|
|
2746
|
-
describe('hyperbolic trigonometric functions', function () {
|
|
2747
|
-
it('should be computed properly', function () {
|
|
2748
|
-
// given
|
|
2749
|
-
var testCases = [
|
|
2750
|
-
{
|
|
2751
|
-
given: 'acosh(1/23.12)',
|
|
2752
|
-
expected: 'acosh(25/578)',
|
|
2753
|
-
expectedValue: '-4.441e-16+1.5275302342078616*i'
|
|
2754
|
-
},
|
|
2755
|
-
{
|
|
2756
|
-
given: 'sech(0.1)',
|
|
2757
|
-
expected: 'sech(1/10)',
|
|
2758
|
-
expectedValue: '0.9950207489532267'
|
|
2759
|
-
},
|
|
2760
|
-
{
|
|
2761
|
-
given: 'csch(0.1)',
|
|
2762
|
-
expected: 'csch(1/10)',
|
|
2763
|
-
expectedValue: '9.98335275729611'
|
|
2764
|
-
},
|
|
2765
|
-
{
|
|
2766
|
-
given: 'tanh(0.1)',
|
|
2767
|
-
expected: 'tanh(1/10)',
|
|
2768
|
-
expectedValue: '0.09966799462495582'
|
|
2769
|
-
},
|
|
2770
|
-
{
|
|
2771
|
-
given: 'coth(0.1)',
|
|
2772
|
-
expected: 'coth(1/10)',
|
|
2773
|
-
expectedValue: '10.03331113225399'
|
|
2774
|
-
},
|
|
2775
|
-
{
|
|
2776
|
-
given: 'acosh(0.1)',
|
|
2777
|
-
expected: 'acosh(1/10)',
|
|
2778
|
-
expectedValue: '1.4706289056333368*i'
|
|
2779
|
-
},
|
|
2780
|
-
{
|
|
2781
|
-
given: 'asinh(0.1)',
|
|
2782
|
-
expected: 'asinh(1/10)',
|
|
2783
|
-
expectedValue: '0.0998340788992076'
|
|
2784
|
-
},
|
|
2785
|
-
{
|
|
2786
|
-
given: 'atanh(-5)',
|
|
2787
|
-
expected: 'atanh(-5)',
|
|
2788
|
-
expectedValue: '-0.20273255405408225+1.5707963267948966*i'
|
|
2789
|
-
},
|
|
2790
|
-
{
|
|
2791
|
-
given: 'asech(0.5)',
|
|
2792
|
-
expected: 'asech(1/2)',
|
|
2793
|
-
expectedValue: '1.3169578969248166'
|
|
2794
|
-
},
|
|
2795
|
-
{
|
|
2796
|
-
given: 'acsch(1.1)',
|
|
2797
|
-
expected: 'acsch(11/10)',
|
|
2798
|
-
expectedValue: '0.8156089004401478'
|
|
2799
|
-
},
|
|
2800
|
-
{
|
|
2801
|
-
given: 'acoth(1.2)',
|
|
2802
|
-
expected: 'acoth(6/5)',
|
|
2803
|
-
expectedValue: '1.1989476363991853'
|
|
2804
|
-
}
|
|
2805
|
-
];
|
|
2806
|
-
|
|
2807
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
2808
|
-
// when
|
|
2809
|
-
var parsed = nerdamer(testCases[i].given);
|
|
2810
|
-
var value = parsed.evaluate().text('decimals');
|
|
2811
|
-
|
|
2812
|
-
// then
|
|
2813
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
2814
|
-
expect(round(value, 14)).toEqual(round(testCases[i].expectedValue),14);
|
|
2815
|
-
}
|
|
2816
|
-
});
|
|
2817
|
-
xit('should throw for wrong trigonometric arguments', function () {
|
|
2818
|
-
// given
|
|
2819
|
-
var testCases = [
|
|
2820
|
-
'csch(0)',
|
|
2821
|
-
'coth(0)'
|
|
2822
|
-
];
|
|
2823
|
-
|
|
2824
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
2825
|
-
var threwError = false;
|
|
2826
|
-
try {
|
|
2827
|
-
nerdamer(testCases[i]).evaluate();
|
|
2828
|
-
} catch (e) {
|
|
2829
|
-
threwError = true;
|
|
2830
|
-
}
|
|
2831
|
-
expect(threwError).toBe(true);
|
|
2832
|
-
}
|
|
2833
|
-
});
|
|
2834
|
-
it('should calculate correctly with variables', function () {
|
|
2835
|
-
// given
|
|
2836
|
-
var testCases = [
|
|
2837
|
-
{
|
|
2838
|
-
given: 'cosh(x)',
|
|
2839
|
-
expected: 'cosh(x)',
|
|
2840
|
-
expectedValue: '4.1443131704103155'
|
|
2841
|
-
},
|
|
2842
|
-
{
|
|
2843
|
-
given: 'sinh(x)',
|
|
2844
|
-
expected: 'sinh(x)',
|
|
2845
|
-
expectedValue: '4.021856742157334'
|
|
2846
|
-
},
|
|
2847
|
-
{
|
|
2848
|
-
given: 'tanh(x)',
|
|
2849
|
-
expected: 'tanh(x)',
|
|
2850
|
-
expectedValue: '0.9704519366134539'
|
|
2851
|
-
},
|
|
2852
|
-
{
|
|
2853
|
-
given: 'y*tanh(x)*tanh(x)',
|
|
2854
|
-
expected: 'tanh(x)^2*y',
|
|
2855
|
-
expectedValue: '3.1078639722134502'
|
|
2856
|
-
},
|
|
2857
|
-
{
|
|
2858
|
-
given: '2*cosh(x)+cosh(x)',
|
|
2859
|
-
expected: '3*cosh(x)',
|
|
2860
|
-
expectedValue: '12.432939511230947'
|
|
2861
|
-
},
|
|
2862
|
-
{
|
|
2863
|
-
given: '2*cosh(x)+cosh(x+8+5*x)',
|
|
2864
|
-
expected: '2*cosh(x)+cosh(6*x+8)',
|
|
2865
|
-
expectedValue: '442014320.214284'
|
|
2866
|
-
},
|
|
2867
|
-
{
|
|
2868
|
-
given: 'x^2+2*cosh(x)+cosh(x+8+5*x)+4*x^2',
|
|
2869
|
-
expected: '2*cosh(x)+5*x^2+cosh(6*x+8)',
|
|
2870
|
-
expectedValue: '442014342.264283977631810'
|
|
2871
|
-
},
|
|
2872
|
-
{
|
|
2873
|
-
given: 'cosh(x)*cosh(x)',
|
|
2874
|
-
expected: 'cosh(x)^2',
|
|
2875
|
-
expectedValue: '17.17533165443640'
|
|
2876
|
-
},
|
|
2877
|
-
{
|
|
2878
|
-
given: 'x^x*cosh(x)*sinh(x)/x',
|
|
2879
|
-
expected: 'cosh(x)*sinh(x)*x^(-1+x)',
|
|
2880
|
-
expectedValue: '37.69818030329012'
|
|
2881
|
-
},
|
|
2882
|
-
{
|
|
2883
|
-
given: '2*cosh(x)+5*cosh(2*x)',
|
|
2884
|
-
expected: '2*cosh(x)+5*cosh(2*x)',
|
|
2885
|
-
expectedValue: '175.04194288518471'
|
|
2886
|
-
},
|
|
2887
|
-
{
|
|
2888
|
-
given: '2*cosh(x)*5*cosh(2*x)',
|
|
2889
|
-
expected: '10*cosh(2*x)*cosh(x)',
|
|
2890
|
-
expectedValue: '1382.15593192881703'
|
|
2891
|
-
},
|
|
2892
|
-
{
|
|
2893
|
-
given: 'cosh(x)+(x+x^2+x)',
|
|
2894
|
-
expected: '2*x+x^2+cosh(x)',
|
|
2895
|
-
expectedValue: '12.75431317041032'
|
|
2896
|
-
},
|
|
2897
|
-
{
|
|
2898
|
-
given: 'cosh(x)+(x+x^2+7)',
|
|
2899
|
-
expected: '7+cosh(x)+x+x^2',
|
|
2900
|
-
expectedValue: '17.65431317041032'
|
|
2901
|
-
},
|
|
2902
|
-
{
|
|
2903
|
-
given: 'x/cosh(x)*cosh(x)',
|
|
2904
|
-
expected: 'x',
|
|
2905
|
-
expectedValue: '2.1'
|
|
2906
|
-
},
|
|
2907
|
-
{
|
|
2908
|
-
given: 'tanh(x)*tanh(x)',
|
|
2909
|
-
expected: 'tanh(x)^2',
|
|
2910
|
-
expectedValue: '0.94177696127680'
|
|
2911
|
-
},
|
|
2912
|
-
{
|
|
2913
|
-
given: '2*(tanh(x)+tanh(2*x)+7)-6*tanh(x)',
|
|
2914
|
-
expected: '-4*tanh(x)+14+2*tanh(2*x)',
|
|
2915
|
-
expectedValue: '12.11729298646525'
|
|
2916
|
-
},
|
|
2917
|
-
{
|
|
2918
|
-
given: '((3+y)*2-(cosh(x)*4+z))',
|
|
2919
|
-
expected: '-4*cosh(x)-z+2*y+6',
|
|
2920
|
-
expectedValue: '-4.97725268164126'
|
|
2921
|
-
},
|
|
2922
|
-
{
|
|
2923
|
-
given: 'cosh(x^2)*cosh(x^2)^x',
|
|
2924
|
-
expected: 'cosh(x^2)^(1+x)',
|
|
2925
|
-
expectedValue: '100982.42051309341241'
|
|
2926
|
-
}
|
|
2927
|
-
];
|
|
2928
|
-
|
|
2929
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
2930
|
-
// when
|
|
2931
|
-
var parsed = nerdamer(testCases[i].given);
|
|
2932
|
-
var value = parsed.evaluate(values).text('decimals', 15);
|
|
2933
|
-
|
|
2934
|
-
// then
|
|
2935
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
2936
|
-
expect(round(value, 14)).toEqual(round(testCases[i].expectedValue),14);
|
|
2937
|
-
}
|
|
2938
|
-
});
|
|
2939
|
-
it('should not overflow', function() {
|
|
2940
|
-
expect(nerdamer('(x+1)+((x+1)^2+(x+1)^3)').toString()).toEqual('(1+x)^2+(1+x)^3+1+x');
|
|
2941
|
-
});
|
|
2942
|
-
});
|
|
2943
|
-
|
|
2944
|
-
describe('omit brackets for functions', function() {
|
|
2945
|
-
it('should add functions with coefficients', function() {
|
|
2946
|
-
expect(nerdamer('2 sin x + 4 sin x').toString()).toEqual('6*sin(x)');
|
|
2947
|
-
});
|
|
2948
|
-
it('should add functions without coefficients', function() {
|
|
2949
|
-
expect(nerdamer('sin x + sin x').toString()).toEqual('2*sin(x)');
|
|
2950
|
-
});
|
|
2951
|
-
it('should multiply and divide functions with "random" spaces', function() {
|
|
2952
|
-
expect(nerdamer('3sin x /6+sin x').toString()).toEqual('(3/2)*sin(x)');
|
|
2953
|
-
});
|
|
2954
|
-
it('should recognize functions with multiple arguments', function() {
|
|
2955
|
-
expect(nerdamer('2 max 1,2,3 +1').toString()).toEqual('7');
|
|
2956
|
-
});
|
|
2957
|
-
it('should recognize functions with arguments containing coefficients', function() {
|
|
2958
|
-
expect(nerdamer('sin 2x').toString()).toEqual('sin(2*x)');
|
|
2959
|
-
});
|
|
2960
|
-
it('should recognize functions with arguments containing coefficients', function() {
|
|
2961
|
-
expect(nerdamer('sin 2x').toString()).toEqual('sin(2*x)');
|
|
2962
|
-
expect(nerdamer('sin a x').toString()).toEqual('sin(a)*x');
|
|
2963
|
-
});
|
|
2964
|
-
it('should multiply functions without brackets', function() {
|
|
2965
|
-
expect(nerdamer('sin 2a cos 2b').toString()).toEqual('cos(2*b)*sin(2*a)');
|
|
2966
|
-
expect(nerdamer('sin x + sin x + 1 ').toString()).toEqual('1+2*sin(x)');
|
|
2967
|
-
expect(nerdamer('5 x y sin x').toString()).toEqual('5*sin(x)*x*y');
|
|
2968
|
-
});
|
|
2969
|
-
});
|
|
2970
|
-
|