Files
JavaScript/Data-Structures/Stack/test/EvaluateExpression.test.js
Lars Müller 05e32481fa chore: format code (#1515)
* chore: format code

* Updated Documentation in README.md

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-10-12 06:32:18 +00:00

22 lines
718 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)
})
})