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