deno.land / x / masx200_leetcode_test@10.6.5 / basic-calculator / test.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { assertEquals } from "../deps.ts";import { buildExpression } from "./buildExpression.ts";import { evaluate } from "./evaluate.ts";import calculate from "./index.ts";import { tokenize } from "./tokenize.ts";
Deno.test("calculate-simple-expression", () => { assertEquals( -199 + 5998, evaluate({ type: "BinaryExpression", operator: "+", left: { operator: "-", type: "UnaryExpression", argument: { type: "NumericLiteral", value: 199 }, }, right: { type: "NumericLiteral", value: 5998, }, }), );});Deno.test("calculate-Parenthesized-expression", () => { assertEquals( -(-199 + 5998), evaluate({ type: "UnaryExpression", operator: "-", argument: { type: "ParenthesizedExpression", expression: { type: "BinaryExpression", operator: "+", left: { operator: "-", type: "UnaryExpression", argument: { type: "NumericLiteral", value: 199 }, }, right: { type: "NumericLiteral", value: 5998, }, }, }, }), );});Deno.test("simple-tokenize", () => { assertEquals(tokenize("-199+5998"), ["-", 199, "+", 5998]);});Deno.test("Parenthesized-tokenize", () => { assertEquals(tokenize("8+(-199+5998)+87"), [ 8, "+", ["-", 199, "+", 5998], "+", 87, ]);});Deno.test("simple-expression", () => { assertEquals(buildExpression(["-", 199, "+", 5998]), { type: "BinaryExpression", operator: "+", left: { operator: "-", type: "UnaryExpression", argument: { type: "NumericLiteral", value: 199 }, }, right: { type: "NumericLiteral", value: 5998, }, });});Deno.test("Parenthesized-expression", () => { assertEquals(buildExpression(["-", ["-", 199, "+", 5998]]), { operator: "-", type: "UnaryExpression", argument: { type: "ParenthesizedExpression", expression: { type: "BinaryExpression", operator: "+", left: { operator: "-", type: "UnaryExpression", argument: { type: "NumericLiteral", value: 199 }, }, right: { type: "NumericLiteral", value: 5998, }, }, }, });});Deno.test("simple-calculate", () => { assertEquals(calculate("-199+5998"), -199 + 5998);});Deno.test("Parenthesized-calculate", () => { assertEquals(calculate("-(-199+5998)+87"), -(-199 + 5998) + 87);});Deno.test("testcases-calculate", () => { assertEquals(calculate("1 + 1"), 2); assertEquals(calculate(" 2-1 + 2 "), 3); assertEquals(calculate("(1+(4+5+2)-3)+(6+8)"), 23);});
masx200_leetcode_test

Version Info

Tagged at
a year ago