Skip to content

Commit 78e76ef

Browse files
committed
fix: update testing
1 parent 4c604b5 commit 78e76ef

10 files changed

+1102
-577
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createParser } from "..";
2+
import { ExampleInfix } from "../example";
3+
4+
const parser = createParser();
5+
const terms = {};
6+
7+
describe("test infix ops", () => {
8+
Object.entries(ExampleInfix).forEach(([key, prop]) => {
9+
it(`${key} | (${prop.expression} = ${prop.result})`, () => {
10+
expect(parser.expressionToValue(prop.expression, terms)).toEqual(prop.result);
11+
});
12+
});
13+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { createParser } from "..";
2+
import {
3+
ExampleBoolean,
4+
ExamplePrefixArray,
5+
ExamplePrefixDate,
6+
ExamplePrefixIsCondition,
7+
ExamplePrefixNumber,
8+
ExamplePrefixObject,
9+
ExamplePrefixString,
10+
ExampleTerms,
11+
} from "../example";
12+
// import { ExampleInfix } from "../example-infix";
13+
14+
const parser = createParser();
15+
16+
const TestGroup = [
17+
["is-condition", ExamplePrefixIsCondition],
18+
["date", ExamplePrefixDate],
19+
["string", ExamplePrefixString],
20+
["number", ExamplePrefixNumber],
21+
["boolean", ExampleBoolean],
22+
["array", ExamplePrefixArray],
23+
["object", ExamplePrefixObject],
24+
];
25+
26+
TestGroup.forEach(([group, reference]) => {
27+
describe(`test prefix ${group} ops`, () => {
28+
Object.entries(reference).forEach(([key, prop]: any) => {
29+
it(`${key} | (${prop.expression} = ${prop.result})`, () => {
30+
expect(parser.expressionToValue(prop.expression, ExampleTerms)).toEqual(prop.result);
31+
});
32+
});
33+
});
34+
});

src/v2/parser/__test__/expression.test.ts

+4-57
Original file line numberDiff line numberDiff line change
@@ -6,62 +6,9 @@ test("init expression", () => {
66
const expression = "2+3+4+55+2+(4 + 2) + -334 + 4 + x";
77
const terms = { x: 20 };
88

9-
// const tokenize = parser.tokenize(expression);
10-
// expect(tokenize).toEqual(
11-
// [
12-
// "2", "+", "3", "+", "4",
13-
// "+", "55", "+", "2", "+",
14-
// "(", "4", "+", "2", ")",
15-
// "+", "NEG", "334", "+", "4",
16-
// "+", "x",
17-
// ],
18-
// );
19-
20-
// const tokenToRpn = parser.tokensToRpn(tokenize);
21-
// expect(tokenToRpn).toEqual(
22-
// [
23-
// "2", "3", "+", "4",
24-
// "+", "55", "+", "2",
25-
// "+", "4", "2", "+",
26-
// "+", "334", "NEG", "+",
27-
// "4", "+", "x", "+",
28-
// ],
29-
// );
30-
31-
// const rpnToThunk = parser.rpnToThunk(tokenToRpn, terms);
32-
// console.log(rpnToThunk);
33-
34-
// const rpnToValue = parser.rpnToValue(tokenToRpn, terms);
35-
// expect(rpnToValue).toBe(-238);
36-
37-
// console.log(rpnToValue);
38-
// const range: any = [];
39-
// Array.from({ length: 9999 }).forEach(() => {
40-
// const start = performance.now();
41-
42-
// parser.tokensToRpn(tokenize);
43-
// parser.tokensToRpn(tokenize);
44-
// parser.tokensToRpn(tokenize);
45-
// parser.tokensToRpn(tokenize);
46-
// parser.tokensToRpn(tokenize);
47-
// parser.tokensToRpn(tokenize);
48-
// parser.tokensToRpn(tokenize);
49-
// parser.tokensToRpn(tokenize);
50-
// parser.tokensToRpn(tokenize);
51-
// parser.tokensToRpn(tokenize);
52-
// parser.tokensToRpn(tokenize);
53-
// parser.tokensToRpn(tokenize);
54-
// parser.tokensToRpn(tokenize);
55-
// parser.tokensToRpn(tokenize);
56-
// parser.tokensToRpn(tokenize);
57-
// const duration = performance.now() - start;
58-
// range.push(duration);
59-
// });
60-
// const avarage = range.reduce((acc: any, item: any) => {
61-
// if (!acc) return item;
62-
// return (acc + item) / 2;
63-
// }, 0);
64-
// console.log(avarage);
65-
669
expect(parser.expressionToValue(expression, terms)).toBe(-238);
10+
expect(parser.expressionToValue("20 > 10", terms)).toBe(true);
11+
expect(parser.expressionToValue("10 > 20", terms)).toBe(false);
12+
expect(parser.expressionToValue("10 < 20", terms)).toBe(true);
13+
expect(parser.expressionToValue("20 < 10", terms)).toBe(false);
6714
});

0 commit comments

Comments
 (0)