diff --git a/src/test/java/com/thealgorithms/stacks/PrefixEvaluatorTest.java b/src/test/java/com/thealgorithms/stacks/PrefixEvaluatorTest.java index e2faa61955b3..ba67163fd49e 100644 --- a/src/test/java/com/thealgorithms/stacks/PrefixEvaluatorTest.java +++ b/src/test/java/com/thealgorithms/stacks/PrefixEvaluatorTest.java @@ -4,24 +4,28 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.EmptyStackException; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; public class PrefixEvaluatorTest { - @Test - public void testValidExpressions() { - assertEquals(10, PrefixEvaluator.evaluatePrefix("+ * 2 3 4")); - assertEquals(5, PrefixEvaluator.evaluatePrefix("- + 7 3 5")); - assertEquals(6, PrefixEvaluator.evaluatePrefix("/ * 3 2 1")); + @ParameterizedTest(name = "Expression: \"{0}\" → Result: {1}") + @CsvSource({"'+ * 2 3 4', 10", "'- + 7 3 5', 5", "'/ * 3 2 1', 6"}) + void testValidExpressions(String expression, int expected) { + assertEquals(expected, PrefixEvaluator.evaluatePrefix(expression)); } @Test - public void testInvalidExpression() { + @DisplayName("Should throw EmptyStackException for incomplete expression") + void testInvalidExpression() { assertThrows(EmptyStackException.class, () -> PrefixEvaluator.evaluatePrefix("+ 3")); } @Test - public void testMoreThanOneStackSizeAfterEvaluation() { + @DisplayName("Should throw IllegalArgumentException if stack not reduced to one result") + void testMoreThanOneStackSizeAfterEvaluation() { assertThrows(IllegalArgumentException.class, () -> PrefixEvaluator.evaluatePrefix("+ 3 4 5")); } }