Skip to content

Instantly share code, notes, and snippets.

@qunabu
Created November 26, 2020 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qunabu/b1daa6550c381d7a4a4ebfa48e6b63d4 to your computer and use it in GitHub Desktop.
Save qunabu/b1daa6550c381d7a4a4ebfa48e6b63d4 to your computer and use it in GitHub Desktop.
describe("The RPN expression evaluator", () => {
it("should return null when the expression is an empty string", () => {
const result = RPN("");
expect(result).toBeNull();
});
it("should return the same value when the expression holds a single value", () => {
const result = RPN("42");
expect(result).toBe(42);
});
it("should properly calculate an expression", () => {
const result = RPN("5 1 2 + 4 * - 10 /");
expect(result).toBe(-0.7);
});
it("should throw an error whenever an invalid expression is passed", () => {
const compute = () => RPN("1 + - 1");
expect(compute).toThrow();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment