mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 06:23:08 +08:00
refactor: PostfixToInfix
(#5409)
* refactor: PostfixToInfix * checkstyle: fix formatting * refactor: add support for one character --------- Co-authored-by: alxkm <alx@alx.com>
This commit is contained in:
@ -0,0 +1,33 @@
|
||||
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 PostfixToInfixTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideValidPostfixToInfixTestCases")
|
||||
void testValidPostfixToInfixConversion(String postfix, String expectedInfix) {
|
||||
assertEquals(expectedInfix, PostfixToInfix.getPostfixToInfix(postfix));
|
||||
}
|
||||
|
||||
static Stream<Arguments> provideValidPostfixToInfixTestCases() {
|
||||
return Stream.of(Arguments.of("A", "A"), Arguments.of("ABC+/", "(A/(B+C))"), Arguments.of("AB+CD+*", "((A+B)*(C+D))"), Arguments.of("AB+C+D+", "(((A+B)+C)+D)"), Arguments.of("ABCDE^*/-", "(A-(B/(C*(D^E))))"), Arguments.of("AB+CD^/E*FGH+-^", "((((A+B)/(C^D))*E)^(F-(G+H)))"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmptyPostfixExpression() {
|
||||
assertEquals("", PostfixToInfix.getPostfixToInfix(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNullPostfixExpression() {
|
||||
assertThrows(NullPointerException.class, () -> PostfixToInfix.getPostfixToInfix(null));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user