@pie-lib/math-evaluator 2.1.23 → 2.2.0-beta.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/CHANGELOG.md +12 -24
- package/NEXT.CHANGELOG.json +1 -0
- package/package.json +4 -3
- package/src/__tests__/index.test.js +413 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
# [2.2.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.1) (2025-07-20)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
# [2.2.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.0) (2025-07-20)
|
|
15
15
|
|
|
16
16
|
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
17
17
|
|
|
@@ -19,62 +19,50 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
# [2.3.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.3.0-beta.0) (2025-07-15)
|
|
23
23
|
|
|
24
24
|
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
25
25
|
|
|
26
|
+
# [2.2.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.0) (2025-07-15)
|
|
26
27
|
|
|
28
|
+
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
27
29
|
|
|
30
|
+
## [2.1.23](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.22...@pie-lib/math-evaluator@2.1.23) (2023-06-24)
|
|
28
31
|
|
|
32
|
+
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
29
33
|
|
|
30
|
-
## [2.1.
|
|
34
|
+
## [2.1.22](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.20...@pie-lib/math-evaluator@2.1.22) (2023-01-31)
|
|
31
35
|
|
|
32
36
|
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
33
37
|
|
|
38
|
+
## [2.1.20](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.19...@pie-lib/math-evaluator@2.1.20) (2023-01-31)
|
|
34
39
|
|
|
40
|
+
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
35
41
|
|
|
42
|
+
## [2.1.19](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.18...@pie-lib/math-evaluator@2.1.19) (2023-01-31)
|
|
36
43
|
|
|
44
|
+
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
37
45
|
|
|
38
46
|
## [2.1.18](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.17...@pie-lib/math-evaluator@2.1.18) (2023-01-31)
|
|
39
47
|
|
|
40
48
|
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
41
49
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
50
|
## [2.1.17](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.11...@pie-lib/math-evaluator@2.1.17) (2023-01-31)
|
|
47
51
|
|
|
48
52
|
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
54
|
## [2.1.11](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.9...@pie-lib/math-evaluator@2.1.11) (2023-01-31)
|
|
55
55
|
|
|
56
56
|
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
58
|
## [2.1.9](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.7...@pie-lib/math-evaluator@2.1.9) (2023-01-31)
|
|
63
59
|
|
|
64
60
|
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
65
61
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
62
|
## [2.1.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.6...@pie-lib/math-evaluator@2.1.7) (2022-11-23)
|
|
71
63
|
|
|
72
64
|
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
73
65
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
66
|
## [2.1.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.4...@pie-lib/math-evaluator@2.1.6) (2021-06-25)
|
|
79
67
|
|
|
80
68
|
**Note:** Version bump only for package @pie-lib/math-evaluator
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "2.1
|
|
6
|
+
"version": "2.2.0-beta.1",
|
|
7
7
|
"description": "Math evaluator tool for comparing expressions for equality",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"math",
|
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@pie-framework/math-expressions": "^3.0.0",
|
|
21
21
|
"jsesc": "^2.5.2",
|
|
22
|
+
"lodash": "^4.17.11",
|
|
22
23
|
"mathjs": "^7.0.1"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@pie-lib/test-utils": "
|
|
26
|
+
"@pie-lib/test-utils": "latest"
|
|
26
27
|
},
|
|
27
28
|
"scripts": {},
|
|
28
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "e2aa3ddac60f49bcb8c2562370f496323642f453"
|
|
29
30
|
}
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import areValuesEqual, { ave, latexToText } from '../index';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
|
|
4
|
+
describe('math-evaluator', () => {
|
|
5
|
+
describe('latexToText', () => {
|
|
6
|
+
const assertLatexToText = (input, expected) => {
|
|
7
|
+
it(`${input} => ${expected}`, () => {
|
|
8
|
+
const result = latexToText(input);
|
|
9
|
+
expect(result).toEqual(expected);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
assertLatexToText('\\frac{ \\frac{1}{3}}{3}', '(1/3)/3');
|
|
13
|
+
assertLatexToText('\\neq', '0 != 0');
|
|
14
|
+
assertLatexToText('10 \\neq 20', '10 != 20');
|
|
15
|
+
assertLatexToText('10 \\neq', '10 != 0');
|
|
16
|
+
assertLatexToText('\\neq 10', '0 != 10');
|
|
17
|
+
assertLatexToText('40%', 'percent(40)');
|
|
18
|
+
assertLatexToText('%', 'percent(0)');
|
|
19
|
+
assertLatexToText('12%', 'percent(12)');
|
|
20
|
+
assertLatexToText('12\\%', 'percent(12)');
|
|
21
|
+
assertLatexToText('-12.5%', '- percent(12.5)');
|
|
22
|
+
assertLatexToText('-12.5\\%', '- percent(12.5)');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const assert = (isEqual, opts) => (label) =>
|
|
26
|
+
function() {
|
|
27
|
+
const args = Array.from(arguments);
|
|
28
|
+
const pairs = _.chunk(args, 2);
|
|
29
|
+
|
|
30
|
+
describe(label, () => {
|
|
31
|
+
pairs.forEach(([a, b]) => {
|
|
32
|
+
it(`${a} === ${b} ? ${isEqual}`, () => {
|
|
33
|
+
expect(areValuesEqual(a, b, opts)).toBe(isEqual);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const assertEqual = assert(true);
|
|
40
|
+
const assertNotEqual = assert(false);
|
|
41
|
+
|
|
42
|
+
const assertLatexEqual = assert(true, { isLatex: true });
|
|
43
|
+
const assertLatexNotEqual = assert(false, { isLatex: true });
|
|
44
|
+
|
|
45
|
+
const _amjs = (only) => (a, b, equal) => {
|
|
46
|
+
const fn = only ? it.only : it;
|
|
47
|
+
fn(`${a} === ${b} => ${equal}`, () => {
|
|
48
|
+
const as = latexToText(a);
|
|
49
|
+
const bs = latexToText(b);
|
|
50
|
+
expect(ave(as, bs)).toEqual(equal);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const assertThroughMathJs = _amjs(false);
|
|
55
|
+
assertThroughMathJs.only = _amjs(true);
|
|
56
|
+
|
|
57
|
+
const _als = (only) => (input, expected) => {
|
|
58
|
+
const fn = only ? it.only : it;
|
|
59
|
+
fn(`${input} => ${expected}`, () => {
|
|
60
|
+
expect(latexToText(input)).toEqual(expected);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const assertLatexFromString = _als(false);
|
|
65
|
+
assertLatexFromString.only = _als(true);
|
|
66
|
+
|
|
67
|
+
describe('ch6456', () => {
|
|
68
|
+
assertEqual('percent')('-12.5%', '-12.5%');
|
|
69
|
+
assertEqual('percent')('-12.5\\%', '-12.5%');
|
|
70
|
+
assertNotEqual('percent')('-11.5%', '-12.5%');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('ch6456 - latex', () => {
|
|
74
|
+
assertLatexEqual('percent')('\\frac{1}{2} -12.5%', '\\frac{2}{4} -12.5%');
|
|
75
|
+
assertLatexEqual('percent')('\\frac{1}{2} -12.5%', '\\frac{2}{4} -12.5\\%');
|
|
76
|
+
assertLatexNotEqual('percent')('\\frac{4}{2} -12.5%', '\\frac{2}{4} -12.5\\%');
|
|
77
|
+
assertLatexNotEqual('percent')('\\frac{2}{2} -12.5%', '\\frac{2}{4} -12.5\\%');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('PIE-188-math-expressions', () => {
|
|
81
|
+
// it('parses expressions correctly', async () => {
|
|
82
|
+
|
|
83
|
+
// geometry
|
|
84
|
+
|
|
85
|
+
// MULTIPLY WITH VARIABLE BASED
|
|
86
|
+
assertThroughMathJs('\\parallel x', '\\parallel x', true);
|
|
87
|
+
assertThroughMathJs('\\parallel x', '\\parallel x', true);
|
|
88
|
+
assertThroughMathJs('\\parallel x', '\\parallel 0', false);
|
|
89
|
+
assertThroughMathJs('\\overrightarrow{x + 4}', '\\overrightarrow {4 + x}', true);
|
|
90
|
+
assertThroughMathJs('\\overrightarrow{4x^2 + 4}', '\\overrightarrow {4x^2 + 8 - 4}', true);
|
|
91
|
+
assertThroughMathJs('\\overrightarrow{21*2*x}', '\\overrightarrow {42x}', true);
|
|
92
|
+
assertLatexFromString('\\nparallel x', 'nparallel x');
|
|
93
|
+
assertLatexFromString('\\overrightarrow{x}', 'overrightarrow x');
|
|
94
|
+
assertLatexFromString('\\overleftrightarrow{x}', 'overleftrightarrow x');
|
|
95
|
+
assertLatexFromString('\\perp x', 'perp x');
|
|
96
|
+
assertLatexFromString('\\angle x', 'angle x');
|
|
97
|
+
assertLatexFromString('\\overarc x', 'overarc x');
|
|
98
|
+
assertLatexFromString('\\measuredangle x', 'measuredangle x');
|
|
99
|
+
assertLatexFromString('\\triangle x', 'triangle x');
|
|
100
|
+
assertLatexFromString('\\parallelogram x', 'parallelogram x');
|
|
101
|
+
assertLatexFromString('\\odot x', 'odot x');
|
|
102
|
+
assertLatexFromString('\\degree x', 'degree x');
|
|
103
|
+
assertLatexFromString('\\sim x', 'sim x');
|
|
104
|
+
assertLatexFromString('\\cong x', 'cong x');
|
|
105
|
+
assertLatexFromString('\\ncong x', 'ncong x');
|
|
106
|
+
assertLatexFromString('\\napprox x', 'napprox x'); // UNRECOGNIZED BY LEARNOSITY
|
|
107
|
+
assertLatexFromString('\\nim x', 'nim x'); // UNRECOGNIZED BY LEARNOSITY
|
|
108
|
+
assertLatexFromString('\\sim x', 'sim x');
|
|
109
|
+
expect(() => latexToText('\\sim 4', { unknownCommandBehavior: 'error' })).toThrow();
|
|
110
|
+
|
|
111
|
+
// comparisons
|
|
112
|
+
|
|
113
|
+
assertLatexFromString('1 \\lt 2', '1 < 2');
|
|
114
|
+
|
|
115
|
+
assertLatexFromString('1 \\gt 2', '1 > 2');
|
|
116
|
+
|
|
117
|
+
assertLatexFromString('1 \\le 2', '1 ≤ 2');
|
|
118
|
+
|
|
119
|
+
assertLatexFromString('1 \\ge 2', '1 ≥ 2');
|
|
120
|
+
|
|
121
|
+
// exponents
|
|
122
|
+
|
|
123
|
+
assertLatexFromString('2^2', '2^2');
|
|
124
|
+
|
|
125
|
+
assertLatexFromString('2^{3}', '2^3');
|
|
126
|
+
|
|
127
|
+
// roots
|
|
128
|
+
|
|
129
|
+
assertLatexFromString('\\sqrt{2}', 'sqrt(2)');
|
|
130
|
+
|
|
131
|
+
assertLatexFromString('\\sqrt[{3}]{3}', '3^(1/3)');
|
|
132
|
+
|
|
133
|
+
// fractions
|
|
134
|
+
|
|
135
|
+
assertLatexFromString('\\frac{3}{3}', '3/3');
|
|
136
|
+
|
|
137
|
+
assertLatexFromString('\\frac{x}{3}', 'x/3');
|
|
138
|
+
|
|
139
|
+
assertLatexFromString('x\\frac{5}{3}', 'x (5/3)');
|
|
140
|
+
|
|
141
|
+
// ACTUAL OPERATOR BASED
|
|
142
|
+
assertLatexFromString('\\overline{x}', 'overline x');
|
|
143
|
+
assertLatexFromString('\\pm', 'pm');
|
|
144
|
+
assertLatexFromString('\\approx x', 'approx x');
|
|
145
|
+
|
|
146
|
+
// logarithms
|
|
147
|
+
|
|
148
|
+
assertLatexFromString("4'", "4'");
|
|
149
|
+
assertLatexFromString('\\log 4', 'log(4)');
|
|
150
|
+
assertLatexFromString('\\log(4x)', 'log(4 x)');
|
|
151
|
+
assertLatexFromString('\\ln 4', 'ln(4)');
|
|
152
|
+
|
|
153
|
+
assertLatexFromString('|4|', '|4|');
|
|
154
|
+
assertLatexFromString('(4)', '4');
|
|
155
|
+
assertLatexFromString('(4 + x) * 5', '(4 + x) * 5');
|
|
156
|
+
assertLatexFromString('[4]', '4');
|
|
157
|
+
assertLatexFromString('\\mu', 'μ');
|
|
158
|
+
assertLatexFromString('\\Sigma', 'Σ');
|
|
159
|
+
assertLatexFromString('x^{15}', 'x^15');
|
|
160
|
+
assertLatexFromString('x_{15}', 'x_15');
|
|
161
|
+
|
|
162
|
+
// Trigo
|
|
163
|
+
|
|
164
|
+
assertLatexFromString('\\sin(x)', 'sin(x)');
|
|
165
|
+
assertLatexFromString('\\cos(x)', 'cos(x)');
|
|
166
|
+
assertLatexFromString('\\tan(x)', 'tan(x)');
|
|
167
|
+
assertLatexFromString('\\sec(x)', 'sec(x)');
|
|
168
|
+
assertLatexFromString('\\csc(x)', 'csc(x)');
|
|
169
|
+
assertLatexFromString('\\cot(x)', 'cot(x)');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// assertNotEqual('custom latex')('1530', `\\odot`);
|
|
173
|
+
assertNotEqual('evaluates simple expressions correctly')('0', 'x', '3x', '4x');
|
|
174
|
+
|
|
175
|
+
assertEqual('evaluates simple expressions correctly')('x', 'x', '2x', '2x');
|
|
176
|
+
|
|
177
|
+
describe('bad frac throws error', () => {
|
|
178
|
+
it('throws an error', () => {
|
|
179
|
+
expect(() => areValuesEqual('\\frac12', '\\frac34', { isLatex: true })).toThrow('Expecting {');
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
describe('7119', () => {
|
|
183
|
+
it.each`
|
|
184
|
+
v | isEqual
|
|
185
|
+
${'4.5'} | ${true}
|
|
186
|
+
${'3.2 + 1.3'} | ${true}
|
|
187
|
+
${'(4 - \\frac{4}{5}) + 1.3'} | ${true}
|
|
188
|
+
${'\\frac{9}{2}'} | ${true}
|
|
189
|
+
${'4 \\frac{1}{2}'} | ${true}
|
|
190
|
+
${'\\frac{10}{2} - 0.5'} | ${true}
|
|
191
|
+
${'4.55'} | ${false}
|
|
192
|
+
`('$a == $isEqual', ({ v, isEqual }) => {
|
|
193
|
+
const result = areValuesEqual('4 \\frac{1}{2}', v, { isLatex: true });
|
|
194
|
+
expect(result).toEqual(isEqual);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('?', () => {
|
|
198
|
+
expect(latexToText('4\\frac{1}{2}')).toEqual('4 + 1/2');
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
assertEqual('evaluates simple expressions correctly 2')(
|
|
203
|
+
'100',
|
|
204
|
+
'100',
|
|
205
|
+
'50 + 50',
|
|
206
|
+
'25 * 4',
|
|
207
|
+
'200 / 2',
|
|
208
|
+
'20 * 5',
|
|
209
|
+
'2.5 * 40',
|
|
210
|
+
'10 * 10',
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
assertNotEqual('evaluates simple expressions correctly 2')(
|
|
214
|
+
'100',
|
|
215
|
+
'0',
|
|
216
|
+
'0',
|
|
217
|
+
'50 * 2',
|
|
218
|
+
'44 + 57',
|
|
219
|
+
'100',
|
|
220
|
+
'44 + 57',
|
|
221
|
+
'50 * 3',
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
assertEqual('evaluates simple expressions correctly 3')(
|
|
225
|
+
'50 + 50',
|
|
226
|
+
'100',
|
|
227
|
+
'100 / 2 + 50',
|
|
228
|
+
'100',
|
|
229
|
+
'2 + 2',
|
|
230
|
+
'4',
|
|
231
|
+
'1/2 + .5',
|
|
232
|
+
'1',
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
assertNotEqual('evaluates simple expressions correctly 3')(
|
|
236
|
+
'50 + 51',
|
|
237
|
+
'100',
|
|
238
|
+
'25 * 2 + 51',
|
|
239
|
+
'100',
|
|
240
|
+
'1/2 + .5',
|
|
241
|
+
'1.9',
|
|
242
|
+
'1/2 + .5',
|
|
243
|
+
'1.1',
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
assertEqual('evaluates simple expressions correctly 4')(
|
|
247
|
+
'50 + 50',
|
|
248
|
+
'100',
|
|
249
|
+
'100 / 2 + 50',
|
|
250
|
+
'100',
|
|
251
|
+
'2 + 2',
|
|
252
|
+
'4',
|
|
253
|
+
'1/2 + .5',
|
|
254
|
+
'1',
|
|
255
|
+
'13/2',
|
|
256
|
+
'13/2',
|
|
257
|
+
'26/4',
|
|
258
|
+
'13/2',
|
|
259
|
+
'6 + 1/2',
|
|
260
|
+
'13/2',
|
|
261
|
+
'6.5',
|
|
262
|
+
'13/2',
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
assertNotEqual('evaluates simple expressions correctly 4')(
|
|
266
|
+
'50 + 51',
|
|
267
|
+
'100',
|
|
268
|
+
'25 * 2 + 51',
|
|
269
|
+
'100',
|
|
270
|
+
'1/2 + .5',
|
|
271
|
+
'1.9',
|
|
272
|
+
'1/2 + .5',
|
|
273
|
+
'1.1',
|
|
274
|
+
'14/2',
|
|
275
|
+
'13/2',
|
|
276
|
+
'6.6',
|
|
277
|
+
'13/2',
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
it.each`
|
|
281
|
+
a | b
|
|
282
|
+
${'((x^2 + x) / x) - 1'} | ${'x'}
|
|
283
|
+
`('$a == $b', ({ a, b }) => {
|
|
284
|
+
expect(areValuesEqual(a, b)).toBe(true);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
assertEqual('evaluates simple variable expressions correctly')(
|
|
288
|
+
'x',
|
|
289
|
+
'x',
|
|
290
|
+
'x + 0',
|
|
291
|
+
'x',
|
|
292
|
+
'(x-2) + 2',
|
|
293
|
+
'x',
|
|
294
|
+
'((x^2 + x) / x) - 1',
|
|
295
|
+
'x',
|
|
296
|
+
'2x/2',
|
|
297
|
+
'x',
|
|
298
|
+
'(x + 2)^2',
|
|
299
|
+
'(x + 2)^2',
|
|
300
|
+
'x^2 + 4x + 4',
|
|
301
|
+
'(x + 2)^2',
|
|
302
|
+
'x^2 + 4(x+1)',
|
|
303
|
+
'(x + 2)^2',
|
|
304
|
+
'x^2 + 8 ((x+1) / 2)',
|
|
305
|
+
'(x + 2)^2',
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
assertNotEqual('evaluates simple variable expressions correctly')(
|
|
309
|
+
'y',
|
|
310
|
+
'x',
|
|
311
|
+
'x + 1',
|
|
312
|
+
'x',
|
|
313
|
+
'x^3 + 4x + 4',
|
|
314
|
+
'(x + 2)^2',
|
|
315
|
+
'x^2 + 4(x+2)',
|
|
316
|
+
'(x + 2)^2',
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
assertEqual('evaluates simple variable expressions correctly 2')(
|
|
320
|
+
'(2 + x)^2',
|
|
321
|
+
'(x + 2)^2',
|
|
322
|
+
'x^2 + 4x + 4',
|
|
323
|
+
'(x + 2)^2',
|
|
324
|
+
'x^2 + 4(x+1)',
|
|
325
|
+
'(x + 2)^2',
|
|
326
|
+
'x^2 + 8 ((x+1) / 2)',
|
|
327
|
+
'(x + 2)^2',
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
assertEqual('evaluates expressions correctly with variable exponents')(
|
|
331
|
+
'(2 + x)^2x',
|
|
332
|
+
'(x + 2)^2x',
|
|
333
|
+
'y^(2 x)',
|
|
334
|
+
'y^(x+x)',
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
assertEqual('evaluates function expressions correctly with variable parameters')(
|
|
338
|
+
'sqrt(4x)',
|
|
339
|
+
'sqrt(2x+2x)',
|
|
340
|
+
'sqrt(x^2)',
|
|
341
|
+
'sqrt(((x+1)^2) - ((x+1)^2) + x^2)',
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
assertNotEqual('evaluates simple variable expressions correctly 2')(
|
|
345
|
+
'x^3 + 4x + 4',
|
|
346
|
+
'(x + 2)^2',
|
|
347
|
+
'x^2 + 4(x+2)',
|
|
348
|
+
'(x + 2)^2',
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
it('correctly consumes allowDecimals option', () => {
|
|
352
|
+
expect(areValuesEqual('123', '123', { allowDecimals: true })).toEqual(true);
|
|
353
|
+
expect(areValuesEqual('123', '123.0', { allowDecimals: true })).toEqual(true);
|
|
354
|
+
expect(areValuesEqual('123,0', '123.0', { allowDecimals: true })).toEqual(true);
|
|
355
|
+
expect(areValuesEqual('123,0', '123.0', { allowDecimals: false })).toEqual(false);
|
|
356
|
+
expect(areValuesEqual('123', '123.0', { allowDecimals: false })).toEqual(false);
|
|
357
|
+
expect(areValuesEqual('123', '123,0', { allowDecimals: false })).toEqual(false);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it('correctly consumes allowDecimals option for complex examples too', () => {
|
|
361
|
+
expect(areValuesEqual('1500000', '1500000', { allowDecimals: true })).toEqual(true);
|
|
362
|
+
expect(areValuesEqual('1,500,000', '1,500,000', { allowDecimals: true })).toEqual(true);
|
|
363
|
+
expect(areValuesEqual('1500000', '1,500,000', { allowDecimals: true })).toEqual(true);
|
|
364
|
+
expect(areValuesEqual('1500000', '1,500,000.00', { allowDecimals: true })).toEqual(true);
|
|
365
|
+
expect(areValuesEqual('1500000', '1,500,000.0', { allowDecimals: true })).toEqual(true);
|
|
366
|
+
expect(areValuesEqual('1,500,000.0', '1,500,000.00', { allowDecimals: true })).toEqual(true);
|
|
367
|
+
expect(areValuesEqual('1500000', '1,500000', { allowDecimals: true })).toEqual(false);
|
|
368
|
+
expect(areValuesEqual('1500000', '1500,000', { allowDecimals: true })).toEqual(false);
|
|
369
|
+
expect(areValuesEqual('1500000', '1,500,000.01', { allowDecimals: true })).toEqual(false);
|
|
370
|
+
expect(areValuesEqual('1500000', '1,500,00,0', { allowDecimals: true })).toEqual(false);
|
|
371
|
+
expect(areValuesEqual('1500000', '1500,000', { allowDecimals: true })).toEqual(false);
|
|
372
|
+
expect(areValuesEqual('1500000', ',1500,000', { allowDecimals: true })).toEqual(false);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('evaluates simple trigo expressions correctly', () => {
|
|
376
|
+
expect(areValuesEqual('sin(x)', 'sin(x)')).toEqual(true);
|
|
377
|
+
expect(areValuesEqual('tan(x)', 'tan(x)')).toEqual(true);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
it('correctly creates math expressions 1', () => {
|
|
381
|
+
expect(
|
|
382
|
+
areValuesEqual('f^{-1}\\left(x\\right)=\\sqrt{x-1}+3', 'f^{-1}\\left(x\\right)=\\sqrt{x-1}+3', {
|
|
383
|
+
allowDecimals: true,
|
|
384
|
+
isLatex: true,
|
|
385
|
+
}),
|
|
386
|
+
).toEqual(true);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it('correctly creates math expressions 2', () => {
|
|
390
|
+
expect(
|
|
391
|
+
areValuesEqual('72\\div12=6\\text{eggs}', '72\\div12=6\\text{eggs}', {
|
|
392
|
+
allowDecimals: true,
|
|
393
|
+
isLatex: true,
|
|
394
|
+
}),
|
|
395
|
+
).toEqual(true);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
describe('PD-3', () => {
|
|
399
|
+
it.each`
|
|
400
|
+
a | b
|
|
401
|
+
${'\\left(x\\right)^{ \\frac{1}{\\left(y + 3\\right)}}'} | ${'\\sqrt[\\left(y + 3\\right)]{x}'}
|
|
402
|
+
${'\\left(x\\right)^{\\frac{1}{3}}'} | ${'\\sqrt[3]{x}'}
|
|
403
|
+
${'\\left(x\\right)^{\\frac{1}{n}}'} | ${'\\sqrt[n]{x}'}
|
|
404
|
+
${'\\left(x\\right)^{\\frac{1}{2}}'} | ${'\\sqrt{x}'}
|
|
405
|
+
${'\\left(x-1\\right)^{\\frac{1}{2}}+3'} | ${'\\sqrt{x-1}+3'}
|
|
406
|
+
${'f^{-1}\\left(x\\right)=\\left(x-1\\right)^{\\frac{1}{2}}+3'}
|
|
407
|
+
${'f^{-1}\\left(x\\right)=\\sqrt{x-1}+3'}
|
|
408
|
+
`('$a == $b', ({ a, b }) => {
|
|
409
|
+
const opts = { allowDecimals: true, isLatex: true };
|
|
410
|
+
expect(areValuesEqual(a, b, opts)).toBeTruthy();
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
});
|