mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Add Trapping Rainwater problem implementation (Two Pointer Approach) (#6990)
* Add Trapping Rainwater problem implementation (Two Pointer Approach) * Add Wikipedia reference link for Trapping Rainwater problem * fix: format TrappingRainwater.java for CI check * fix: add package and resolve checkstyle errors for TrappingRainwater.java * fix: declare TrappingRainwater as final to pass Checkstyle * Add test cases for TrappingRainwater algorithm * Add test cases for TrappingRainwater algorithm * Move TrappingRainwater algorithm to stacks package * Fix: Move TrappingRainwater to stacks and normalize newline in JugglerSequence * Fix: Normalize newline in JugglerSequence to ensure test consistency * Fix: Normalize newline in JugglerSequence and remove return statement * Add JaCoCo plugin for code coverage reporting * Revert pom.xml to original version from master * Fix: Revert the pom.xml file --------- Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.thealgorithms.stacks;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TrappingRainwaterTest {
|
||||
|
||||
@Test
|
||||
public void testExampleCase() {
|
||||
int[] height = {4, 2, 0, 3, 2, 5};
|
||||
assertEquals(9, TrappingRainwater.trap(height));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTrapping() {
|
||||
int[] height = {1, 2, 3, 4, 5};
|
||||
assertEquals(0, TrappingRainwater.trap(height));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatSurface() {
|
||||
int[] height = {0, 0, 0, 0};
|
||||
assertEquals(0, TrappingRainwater.trap(height));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSymmetricPit() {
|
||||
int[] height = {3, 0, 2, 0, 3};
|
||||
assertEquals(7, TrappingRainwater.trap(height));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleBar() {
|
||||
int[] height = {5};
|
||||
assertEquals(0, TrappingRainwater.trap(height));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user