1+ package com .thealgorithms .others ;
2+
3+ import org .junit .jupiter .api .Test ;
4+
5+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
6+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
7+
8+ class IterativeFloodFillTest {
9+
10+ @ Test
11+ void testForEmptyImage () {
12+ int [][] image = {};
13+ int [][] expected = {};
14+
15+ IterativeFloodFill .floodFill (image , 4 , 5 , 3 , 2 );
16+ assertArrayEquals (expected , image );
17+ }
18+
19+ @ Test
20+ void testForSingleElementImage () {
21+ int [][] image = {{1 }};
22+ int [][] expected = {{3 }};
23+
24+ IterativeFloodFill .floodFill (image , 0 , 0 , 3 , 1 );
25+ assertArrayEquals (expected , image );
26+ }
27+
28+ @ Test
29+ void testForImageOne () {
30+ int [][] image = {
31+ {0 , 0 , 0 , 0 , 0 , 0 , 0 },
32+ {0 , 3 , 3 , 3 , 3 , 0 , 0 },
33+ {0 , 3 , 1 , 1 , 5 , 0 , 0 },
34+ {0 , 3 , 1 , 1 , 5 , 5 , 3 },
35+ {0 , 3 , 5 , 5 , 1 , 1 , 3 },
36+ {0 , 0 , 0 , 5 , 1 , 1 , 3 },
37+ {0 , 0 , 0 , 3 , 3 , 3 , 3 },
38+ };
39+
40+ int [][] expected = {
41+ {0 , 0 , 0 , 0 , 0 , 0 , 0 },
42+ {0 , 3 , 3 , 3 , 3 , 0 , 0 },
43+ {0 , 3 , 2 , 2 , 5 , 0 , 0 },
44+ {0 , 3 , 2 , 2 , 5 , 5 , 3 },
45+ {0 , 3 , 5 , 5 , 2 , 2 , 3 },
46+ {0 , 0 , 0 , 5 , 2 , 2 , 3 },
47+ {0 , 0 , 0 , 3 , 3 , 3 , 3 },
48+ };
49+
50+ IterativeFloodFill .floodFill (image , 2 , 2 , 2 , 1 );
51+ assertArrayEquals (expected , image );
52+ }
53+
54+ @ Test
55+ void testForImageTwo () {
56+ int [][] image = {
57+ {0 , 0 , 1 , 1 , 0 , 0 , 0 },
58+ {1 , 1 , 3 , 3 , 3 , 0 , 0 },
59+ {1 , 3 , 1 , 1 , 5 , 0 , 0 },
60+ {0 , 3 , 1 , 1 , 5 , 5 , 3 },
61+ {0 , 3 , 5 , 5 , 1 , 1 , 3 },
62+ {0 , 0 , 0 , 5 , 1 , 1 , 3 },
63+ {0 , 0 , 0 , 1 , 3 , 1 , 3 },
64+ };
65+
66+ int [][] expected = {
67+ {0 , 0 , 2 , 2 , 0 , 0 , 0 },
68+ {2 , 2 , 3 , 3 , 3 , 0 , 0 },
69+ {2 , 3 , 2 , 2 , 5 , 0 , 0 },
70+ {0 , 3 , 2 , 2 , 5 , 5 , 3 },
71+ {0 , 3 , 5 , 5 , 2 , 2 , 3 },
72+ {0 , 0 , 0 , 5 , 2 , 2 , 3 },
73+ {0 , 0 , 0 , 2 , 3 , 2 , 3 },
74+ };
75+
76+ IterativeFloodFill .floodFill (image , 2 , 2 , 2 , 1 );
77+ assertArrayEquals (expected , image );
78+ }
79+
80+ @ Test
81+ void testForImageThree () {
82+ int [][] image = {
83+ {1 , 1 , 2 , 3 , 1 , 1 , 1 },
84+ {1 , 0 , 0 , 1 , 0 , 0 , 1 },
85+ {1 , 1 , 1 , 0 , 3 , 1 , 2 },
86+ };
87+
88+ int [][] expected = {
89+ {4 , 4 , 2 , 3 , 4 , 4 , 4 },
90+ {4 , 0 , 0 , 4 , 0 , 0 , 4 },
91+ {4 , 4 , 4 , 0 , 3 , 4 , 2 },
92+ };
93+
94+ IterativeFloodFill .floodFill (image , 0 , 1 , 4 , 1 );
95+ assertArrayEquals (expected , image );
96+ }
97+
98+ @ Test
99+ void testForSameNewAndOldColor () {
100+ int [][] image = {{1 , 1 , 2 }, {1 , 0 , 0 }, {1 , 1 , 1 }};
101+
102+ int [][] expected = {{1 , 1 , 2 }, {1 , 0 , 0 }, {1 , 1 , 1 }};
103+
104+ IterativeFloodFill .floodFill (image , 0 , 1 , 1 , 1 );
105+ assertArrayEquals (expected , image );
106+ }
107+
108+ @ Test
109+ void testForBigImage () {
110+ int [][] image = new int [100 ][100 ];
111+
112+ assertDoesNotThrow (() -> IterativeFloodFill .floodFill (image , 0 , 0 , 1 , 0 ));
113+ }
114+ }
0 commit comments