import { evaluate, Expression, sampleFunction, } from "../src"; describe("This is a simple test", () => { test("Check the sampleFunction function", () => { const actual = sampleFunction("hello"); const expected = "hellohello"; expect(actual).toEqual(expected); }); }); 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); }); });