|
@@ -1,4 +1,8 @@
|
|
|
-import {evaluate, sampleFunction} from "../src";
|
|
|
+import {
|
|
|
+ evaluate,
|
|
|
+ Expression,
|
|
|
+ sampleFunction,
|
|
|
+} from "../src";
|
|
|
|
|
|
describe("This is a simple test", () => {
|
|
|
test("Check the sampleFunction function", () => {
|
|
@@ -12,4 +16,68 @@ describe("Simple expression tests", () => {
|
|
|
test("Check literal value", () => {
|
|
|
expect(evaluate({ type: "literal", value: 5 })).toBeCloseTo(5);
|
|
|
});
|
|
|
+
|
|
|
+ test("Check addition", () => {
|
|
|
+ const expr: Expression = {
|
|
|
+ left: {
|
|
|
+ type: "literal",
|
|
|
+ value: 5,
|
|
|
+ },
|
|
|
+ operator: "+",
|
|
|
+ right: {
|
|
|
+ type: "literal",
|
|
|
+ value: 10,
|
|
|
+ },
|
|
|
+ type: "binary",
|
|
|
+ };
|
|
|
+ expect(evaluate(expr)).toBeCloseTo(15);
|
|
|
+ });
|
|
|
+
|
|
|
+ test("Check subtraction", () => {
|
|
|
+ const expr: Expression = {
|
|
|
+ left: {
|
|
|
+ type: "literal",
|
|
|
+ value: 5,
|
|
|
+ },
|
|
|
+ operator: "-",
|
|
|
+ right: {
|
|
|
+ type: "literal",
|
|
|
+ value: 10,
|
|
|
+ },
|
|
|
+ type: "binary",
|
|
|
+ };
|
|
|
+ expect(evaluate(expr)).toBeCloseTo(-5);
|
|
|
+ });
|
|
|
+
|
|
|
+ test("Check multiplication", () => {
|
|
|
+ const expr: Expression = {
|
|
|
+ left: {
|
|
|
+ type: "literal",
|
|
|
+ value: 5,
|
|
|
+ },
|
|
|
+ operator: "*",
|
|
|
+ right: {
|
|
|
+ type: "literal",
|
|
|
+ value: 10,
|
|
|
+ },
|
|
|
+ type: "binary",
|
|
|
+ };
|
|
|
+ expect(evaluate(expr)).toBeCloseTo(50);
|
|
|
+ });
|
|
|
+
|
|
|
+ test("Check division", () => {
|
|
|
+ const expr: Expression = {
|
|
|
+ left: {
|
|
|
+ type: "literal",
|
|
|
+ value: 10,
|
|
|
+ },
|
|
|
+ operator: "/",
|
|
|
+ right: {
|
|
|
+ type: "literal",
|
|
|
+ value: 5,
|
|
|
+ },
|
|
|
+ type: "binary",
|
|
|
+ };
|
|
|
+ expect(evaluate(expr)).toBeCloseTo(2);
|
|
|
+ });
|
|
|
});
|