11package com .thealgorithms .others ;
22
3- import org .junit .jupiter .api .Test ;
4-
53import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
64import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
75
6+ import org .junit .jupiter .api .Test ;
7+
88class 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