|
4 | 4 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
5 | 5 |
|
6 | 6 | import java.util.EmptyStackException;
|
| 7 | +import org.junit.jupiter.api.DisplayName; |
7 | 8 | import org.junit.jupiter.api.Test;
|
| 9 | +import org.junit.jupiter.params.ParameterizedTest; |
| 10 | +import org.junit.jupiter.params.provider.CsvSource; |
8 | 11 |
|
9 | 12 | public class PrefixEvaluatorTest {
|
10 | 13 |
|
11 |
| - @Test |
12 |
| - public void testValidExpressions() { |
13 |
| - assertEquals(10, PrefixEvaluator.evaluatePrefix("+ * 2 3 4")); |
14 |
| - assertEquals(5, PrefixEvaluator.evaluatePrefix("- + 7 3 5")); |
15 |
| - assertEquals(6, PrefixEvaluator.evaluatePrefix("/ * 3 2 1")); |
| 14 | + @ParameterizedTest(name = "Expression: \"{0}\" → Result: {1}") |
| 15 | + @CsvSource({"'+ * 2 3 4', 10", "'- + 7 3 5', 5", "'/ * 3 2 1', 6"}) |
| 16 | + void testValidExpressions(String expression, int expected) { |
| 17 | + assertEquals(expected, PrefixEvaluator.evaluatePrefix(expression)); |
16 | 18 | }
|
17 | 19 |
|
18 | 20 | @Test
|
19 |
| - public void testInvalidExpression() { |
| 21 | + @DisplayName("Should throw EmptyStackException for incomplete expression") |
| 22 | + void testInvalidExpression() { |
20 | 23 | assertThrows(EmptyStackException.class, () -> PrefixEvaluator.evaluatePrefix("+ 3"));
|
21 | 24 | }
|
22 | 25 |
|
23 | 26 | @Test
|
24 |
| - public void testMoreThanOneStackSizeAfterEvaluation() { |
| 27 | + @DisplayName("Should throw IllegalArgumentException if stack not reduced to one result") |
| 28 | + void testMoreThanOneStackSizeAfterEvaluation() { |
25 | 29 | assertThrows(IllegalArgumentException.class, () -> PrefixEvaluator.evaluatePrefix("+ 3 4 5"));
|
26 | 30 | }
|
27 | 31 | }
|
0 commit comments