Skip to content

Commit fda0d6e

Browse files
authored
tests: add tests for edge cases
1 parent c3f43d8 commit fda0d6e

1 file changed

Lines changed: 52 additions & 2 deletions

File tree

src/test/java/com/thealgorithms/others/IterativeFloodFillTest.java

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.thealgorithms.others;
22

3-
import org.junit.jupiter.api.Test;
4-
53
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
64
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
75

6+
import org.junit.jupiter.api.Test;
7+
88
class IterativeFloodFillTest {
99

1010
@Test
@@ -25,6 +25,15 @@ void testForSingleElementImage() {
2525
assertArrayEquals(expected, image);
2626
}
2727

28+
@Test
29+
void testForEmptyRow() {
30+
int[][] image = {{}};
31+
int[][] expected = {{}};
32+
33+
IterativeFloodFill.floodFill(image, 4, 5, 3, 2);
34+
assertArrayEquals(expected, image);
35+
}
36+
2837
@Test
2938
void testForImageOne() {
3039
int[][] image = {
@@ -111,4 +120,45 @@ void testForBigImage() {
111120

112121
assertDoesNotThrow(() -> IterativeFloodFill.floodFill(image, 0, 0, 1, 0));
113122
}
123+
124+
@Test
125+
void testForBelowZeroX() {
126+
int[][] image = {{1, 1, 2}, {1, 0, 0}, {1, 1, 1}};
127+
128+
int[][] expected = {{1, 1, 2}, {1, 0, 0}, {1, 1, 1}};
129+
130+
IterativeFloodFill.floodFill(image, -1, 1, 1, 0);
131+
assertArrayEquals(expected, image);
132+
}
133+
134+
@Test
135+
void testForBelowZeroY() {
136+
int[][] image = {{1, 1, 2}, {1, 0, 0}, {1, 1, 1}};
137+
138+
int[][] expected = {{1, 1, 2}, {1, 0, 0}, {1, 1, 1}};
139+
140+
IterativeFloodFill.floodFill(image, 1, -1, 1, 0);
141+
assertArrayEquals(expected, image);
142+
}
143+
144+
@Test
145+
void testForAboveBoundaryX() {
146+
int[][] image = {{1, 1, 2}, {1, 0, 0}, {1, 1, 1}};
147+
148+
int[][] expected = {{1, 1, 2}, {1, 0, 0}, {1, 1, 1}};
149+
150+
IterativeFloodFill.floodFill(image, 100, 1, 1, 0);
151+
assertArrayEquals(expected, image);
152+
}
153+
154+
@Test
155+
void testForAboveBoundaryY() {
156+
int[][] image = {{1, 1, 2}, {1, 0, 0}, {1, 1, 1}};
157+
158+
int[][] expected = {{1, 1, 2}, {1, 0, 0}, {1, 1, 1}};
159+
160+
IterativeFloodFill.floodFill(image, 1, 100, 1, 0);
161+
assertArrayEquals(expected, image);
162+
}
163+
114164
}

0 commit comments

Comments
 (0)