mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 22:43:30 +08:00
Moved StackPostfixNotation.java from the Others section to the Stack section (#4372)
* Moved StackPostfixNotation.java from the Others section to the Stack section * Put all stack related algo in a separate stack directory in the algorithms directory. The stack directory under data-structures now only contains various implementations of the stack data structure. * formatted files
This commit is contained in:
@ -0,0 +1,57 @@
|
||||
package com.thealgorithms.stacks;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CalculateMaxOfMinTest {
|
||||
|
||||
@Test
|
||||
void testForOneElement() {
|
||||
int[] a = {10, 20, 30, 50, 10, 70, 30};
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertEquals(70, k);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForTwoElements() {
|
||||
int[] a = {5, 3, 2, 6, 3, 2, 6};
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertEquals(6, k);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements() {
|
||||
int[] a = {10, 10, 10, 10, 10, 10, 10};
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertEquals(10, k);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements() {
|
||||
int[] a = {70, 60, 50, 40, 30, 20};
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertEquals(70, k);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements() {
|
||||
int[] a = {50};
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertEquals(50, k);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSixElements() {
|
||||
int[] a = {1, 4, 7, 9, 2, 4, 6};
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertEquals(9, k);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements() {
|
||||
int[] a = {-1, -5, -7, -9, -12, -14};
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertEquals(-1, k);
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.thealgorithms.stacks;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class StackPostfixNotationTest {
|
||||
@Test
|
||||
public void testEvaluate() {
|
||||
final Map<String, Integer> testCases = Map.ofEntries(entry("1 1 +", 2), entry("2 3 *", 6), entry("6 2 /", 3), entry("-5 -2 -", -3), entry("5 2 + 3 *", 21), entry("-5", -5));
|
||||
for (final var tc : testCases.entrySet()) {
|
||||
assertEquals(tc.getValue(), StackPostfixNotation.postfixEvaluate(tc.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfEvaluateThrowsExceptionForEmptyInput() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StackPostfixNotation.postfixEvaluate(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfEvaluateThrowsExceptionForInproperInput() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StackPostfixNotation.postfixEvaluate("3 3 3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfEvaluateThrowsExceptionForInputWithUnknownOperation() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StackPostfixNotation.postfixEvaluate("3 3 !"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfEvaluateThrowsExceptionForInputWithTooFewArgsA() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StackPostfixNotation.postfixEvaluate("+"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfEvaluateThrowsExceptionForInputWithTooFewArgsB() {
|
||||
assertThrows(IllegalArgumentException.class, () -> StackPostfixNotation.postfixEvaluate("2 +"));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user