forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPrefixToInfixTest.java
44 lines (36 loc) · 1.55 KB
/
PrefixToInfixTest.java
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.thealgorithms.stacks;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class PrefixToInfixTest {
@ParameterizedTest
@MethodSource("provideValidPrefixToInfixTestCases")
void testValidPrefixToInfixConversion(String prefix, String expectedInfix) {
assertEquals(expectedInfix, PrefixToInfix.getPrefixToInfix(prefix));
}
static Stream<Arguments> provideValidPrefixToInfixTestCases() {
return Stream.of(Arguments.of("A", "A"), // Single operand
Arguments.of("+AB", "(A+B)"), // Addition
Arguments.of("*+ABC", "((A+B)*C)"), // Addition and multiplication
Arguments.of("-+A*BCD", "((A+(B*C))-D)"), // Mixed operators
Arguments.of("/-A*BC+DE", "((A-(B*C))/(D+E))"), // Mixed operators
Arguments.of("^+AB*CD", "((A+B)^(C*D))") // Mixed operators
);
}
@Test
void testEmptyPrefixExpression() {
assertEquals("", PrefixToInfix.getPrefixToInfix(""));
}
@Test
void testNullPrefixExpression() {
assertThrows(NullPointerException.class, () -> PrefixToInfix.getPrefixToInfix(null));
}
@Test
void testMalformedPrefixExpression() {
assertThrows(ArithmeticException.class, () -> PrefixToInfix.getPrefixToInfix("+ABC"));
}
}