@jacksontian/equation-resolver 1.0.0

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.
@@ -0,0 +1,45 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert';
3
+ import { SemanticChecker } from '../lib/semantic-checker.js';
4
+ import { Lexer } from '../lib/lexer.js';
5
+ import { Parser } from '../lib/parser.js';
6
+
7
+ function check(input) {
8
+ const lexer = new Lexer(input);
9
+ const parser = new Parser(lexer);
10
+ const ast = parser.parse();
11
+ const checker = new SemanticChecker(ast);
12
+ checker.check();
13
+ }
14
+
15
+ describe('SemanticChecker', () => {
16
+ it('should allow single variable equation', () => {
17
+ assert.doesNotThrow(() => check('x = 5'));
18
+ });
19
+
20
+ it('should throw error when equation have 0 variables', () => {
21
+ assert.throws(
22
+ () => check('2 = 5'),
23
+ (error) => {
24
+ assert.strictEqual(error.message, 'Equation does not contain any variables');
25
+ return true;
26
+ }
27
+ );
28
+
29
+ assert.throws(
30
+ () => check('2 = 5; x = 3'),
31
+ (error) => {
32
+ assert.strictEqual(error.message, 'Equation does not contain any variables');
33
+ return true;
34
+ }
35
+ );
36
+
37
+ assert.throws(
38
+ () => check('2 * 3 + 4 - 5 = 5; x = 3'),
39
+ (error) => {
40
+ assert.strictEqual(error.message, 'Equation does not contain any variables');
41
+ return true;
42
+ }
43
+ );
44
+ });
45
+ });