Files
JavaScript/Data-Structures/Stack/test/EvaluateExpression.test.js
Gaurav Giri 52858f8a09 feat: add algorithm to evaluate postfix string (#1441)
* feat: add algorithm to evaluate postfix strings

* feat: add test case for evaluate expression

* update: add literature reference

* fix: import name in testcase

* fix: test case result

* Make clear that this is postfix

* Update tests

* add: see reference

* fixes mentioned issues

* Fix `default` case

---------

Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
2023-10-10 12:30:59 +05:30

23 lines
733 B
JavaScript

import { evaluatePostfixExpression } from '../EvaluateExpression.js';
describe('evaluatePostfixExpression', () => {
it('should evaluate a valid expression', () => {
const expression = '3 4 * 2 / 5 +'; // (3 * 4) / 2 + 5 = 11
const result = evaluatePostfixExpression(expression);
expect(result).toBe(11);
});
it('should handle division by zero', () => {
const expression = '3 0 /'; // Division by zero
const result = evaluatePostfixExpression(expression);
expect(result).toBe(null);
});
it('should handle an invalid expression', () => {
const expression = '3 * 4 2 / +'; // Invalid expression
const result = evaluatePostfixExpression(expression);
expect(result).toBe(null);
});
});