@@ -63,4 +63,36 @@ void testSearchInColWiseSortedMatrix() {
6363 int [] expected = {1 , 1 }; // Found at (1, 1)
6464 assertArrayEquals (expected , searcher .search (matrix , value ), "Value should be found in the column-wise sorted matrix" );
6565 }
66+
67+ @ Test
68+ void testSearchInNullMatrix () {
69+ assertArrayEquals (new int [] {-1 , -1 }, searcher .search (null , 5 ), "Should return {-1, -1} for null matrix" );
70+ }
71+
72+ @ Test
73+ void testSearchInMatrixWithEmptyRows () {
74+ int [][] matrix = {{}};
75+ assertArrayEquals (new int [] {-1 , -1 }, searcher .search (matrix , 5 ), "Should return {-1, -1} for matrix with empty first row" );
76+ }
77+
78+ @ Test
79+ void testSearchInRectangularMatrixMoreColsThanRowsFound () {
80+ int [][] matrix = {{1 , 3 , 5 , 7 , 9 }, {2 , 4 , 6 , 8 , 10 }};
81+ int [] expected = {0 , 4 }; // Value 9 is at row 0, col 4
82+ assertArrayEquals (expected , searcher .search (matrix , 9 ), "Value 9 should be found at row 0, col 4" );
83+ }
84+
85+ @ Test
86+ void testSearchInRectangularMatrixMoreRowsThanColsFound () {
87+ int [][] matrix = {{1 , 5 }, {2 , 6 }, {3 , 7 }, {4 , 8 }};
88+ int [] expected = {2 , 0 }; // Value 3 is at row 2, col 0
89+ assertArrayEquals (expected , searcher .search (matrix , 3 ), "Value 3 should be found at row 2, col 0" );
90+ }
91+
92+ @ Test
93+ void testSearchInRectangularMatrixNotFound () {
94+ int [][] matrix = {{1 , 3 , 5 }, {2 , 4 , 6 }, {7 , 8 , 9 }, {10 , 11 , 12 }};
95+ int [] expected = {-1 , -1 };
96+ assertArrayEquals (expected , searcher .search (matrix , 15 ), "Value 15 should not be found" );
97+ }
6698}
0 commit comments