|
| 1 | +const { evaluatePostfixExpression } = require('.'); |
| 2 | + |
| 3 | +describe('Postfix expression evaluation', function () { |
| 4 | + it('should be a function', function () { |
| 5 | + expect(typeof evaluatePostfixExpression).toEqual('function'); |
| 6 | + }); |
| 7 | + |
| 8 | + it('should return a number', function () { |
| 9 | + const expression = '11+'; |
| 10 | + |
| 11 | + expect(typeof evaluatePostfixExpression(expression)).toEqual('number') |
| 12 | + }); |
| 13 | + |
| 14 | + it('should handle addition', function () { |
| 15 | + const expression = '23+'; |
| 16 | + const expected = 5; |
| 17 | + |
| 18 | + expect(evaluatePostfixExpression(expression)).toEqual(expected); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should handle subtraction', function () { |
| 22 | + const expression = '54-'; |
| 23 | + const expected = 1; |
| 24 | + |
| 25 | + expect(evaluatePostfixExpression(expression)).toEqual(expected); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should handle multiplication', function () { |
| 29 | + const expression = '34*'; |
| 30 | + const expected = 12; |
| 31 | + |
| 32 | + expect(evaluatePostfixExpression(expression)).toEqual(expected); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should handle division', function () { |
| 36 | + const expression = '62/'; |
| 37 | + const expected = 3; |
| 38 | + |
| 39 | + expect(evaluatePostfixExpression(expression)).toEqual(expected); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should handle negative numbers', function () { |
| 43 | + const expression = '25-'; |
| 44 | + const expected = -3; |
| 45 | + |
| 46 | + expect(evaluatePostfixExpression(expression)).toEqual(expected); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should handle multiple operators', function () { |
| 50 | + const expression = '123*+'; |
| 51 | + const expected = 7; |
| 52 | + |
| 53 | + expect(evaluatePostfixExpression(expression)).toEqual(expected); |
| 54 | + }); |
| 55 | +}); |
0 commit comments