forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostfixEvaluatorTest.java
More file actions
27 lines (21 loc) · 888 Bytes
/
Copy pathPostfixEvaluatorTest.java
File metadata and controls
27 lines (21 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.thealgorithms.stacks;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.EmptyStackException;
import org.junit.jupiter.api.Test;
public class PostfixEvaluatorTest {
@Test
public void testValidExpressions() {
assertEquals(22, PostfixEvaluator.evaluatePostfix("5 6 + 2 *"));
assertEquals(27, PostfixEvaluator.evaluatePostfix("7 2 + 3 *"));
assertEquals(3, PostfixEvaluator.evaluatePostfix("10 5 / 1 +"));
}
@Test
public void testInvalidExpression() {
assertThrows(EmptyStackException.class, () -> PostfixEvaluator.evaluatePostfix("5 +"));
}
@Test
public void testMoreThanOneStackSizeAfterEvaluation() {
assertThrows(IllegalArgumentException.class, () -> PostfixEvaluator.evaluatePostfix("5 6 + 2 * 3"));
}
}