1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 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);
- });
- });
|