Skip to content

Commit 09bd367

Browse files
committed
Add test cases for TrappingRainwater algorithm
1 parent 3b569d6 commit 09bd367

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.thealgorithms.searches;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class TrappingRainwaterTest {
7+
8+
@Test
9+
public void testExampleCase() {
10+
int[] height = {4, 2, 0, 3, 2, 5};
11+
assertEquals(9, TrappingRainwater.trap(height));
12+
}
13+
14+
@Test
15+
public void testNoTrapping() {
16+
int[] height = {1, 2, 3, 4, 5};
17+
assertEquals(0, TrappingRainwater.trap(height));
18+
}
19+
20+
@Test
21+
public void testFlatSurface() {
22+
int[] height = {0, 0, 0, 0};
23+
assertEquals(0, TrappingRainwater.trap(height));
24+
}
25+
26+
@Test
27+
public void testSymmetricPit() {
28+
int[] height = {3, 0, 2, 0, 3};
29+
assertEquals(7, TrappingRainwater.trap(height));
30+
}
31+
32+
@Test
33+
public void testSingleBar() {
34+
int[] height = {5};
35+
assertEquals(0, TrappingRainwater.trap(height));
36+
}
37+
}

0 commit comments

Comments
 (0)