Skip to content

Commit ceead5e

Browse files
testing: refactor to ParameterizedTest PrefixEvaluatorTest (#6415)
testing: refactor to ParameterizedTest PrefixEvaluatorTest Co-authored-by: Deniz Altunkapan <93663085+DenizAltunkapan@users.noreply.github.com>
1 parent cfd7841 commit ceead5e

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/test/java/com/thealgorithms/stacks/PrefixEvaluatorTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@
44
import static org.junit.jupiter.api.Assertions.assertThrows;
55

66
import java.util.EmptyStackException;
7+
import org.junit.jupiter.api.DisplayName;
78
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.params.ParameterizedTest;
10+
import org.junit.jupiter.params.provider.CsvSource;
811

912
public class PrefixEvaluatorTest {
1013

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));
1618
}
1719

1820
@Test
19-
public void testInvalidExpression() {
21+
@DisplayName("Should throw EmptyStackException for incomplete expression")
22+
void testInvalidExpression() {
2023
assertThrows(EmptyStackException.class, () -> PrefixEvaluator.evaluatePrefix("+ 3"));
2124
}
2225

2326
@Test
24-
public void testMoreThanOneStackSizeAfterEvaluation() {
27+
@DisplayName("Should throw IllegalArgumentException if stack not reduced to one result")
28+
void testMoreThanOneStackSizeAfterEvaluation() {
2529
assertThrows(IllegalArgumentException.class, () -> PrefixEvaluator.evaluatePrefix("+ 3 4 5"));
2630
}
2731
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy