@@ -82,4 +82,53 @@ void testFindSingleElementNotExists() {
8282 int [] result = SaddlebackSearch .find (arr , 0 , 0 , 10 );
8383 assertArrayEquals (new int [] {-1 , -1 }, result , "Element 10 should not be found in single element array" );
8484 }
85+
86+ /**
87+ * Test convenience method searching from the bottom-left corner automatically.
88+ */
89+ @ Test
90+ void testFindWithConvenienceMethod () {
91+ int [][] arr = {{-10 , -5 , -3 , 4 , 9 }, {-6 , -2 , 0 , 5 , 10 }, {-4 , -1 , 1 , 6 , 12 }, {2 , 3 , 7 , 8 , 13 }, {100 , 120 , 130 , 140 , 150 }};
92+ int [] result = SaddlebackSearch .find (arr , 4 );
93+ assertArrayEquals (new int [] {0 , 3 }, result , "Element 4 should be found at (0, 3) using convenience overload" );
94+ }
95+
96+ /**
97+ * Test searching in a null array throws IllegalArgumentException.
98+ */
99+ @ Test
100+ void testFindWithNullArray () {
101+ assertThrows (IllegalArgumentException .class , () -> SaddlebackSearch .find (null , 4 ));
102+ assertThrows (IllegalArgumentException .class , () -> SaddlebackSearch .find (null , 0 , 0 , 4 ));
103+ }
104+
105+ /**
106+ * Test row index out of bounds returns {-1, -1}.
107+ */
108+ @ Test
109+ void testFindWithRowOutOfBounds () {
110+ int [][] arr = {{1 , 2 }, {3 , 4 }};
111+ int [] result = SaddlebackSearch .find (arr , 5 , 0 , 3 );
112+ assertArrayEquals (new int [] {-1 , -1 }, result , "Row index out of bounds should return {-1, -1}" );
113+ }
114+
115+ /**
116+ * Test negative column index returns {-1, -1}.
117+ */
118+ @ Test
119+ void testFindWithNegativeColumn () {
120+ int [][] arr = {{1 , 2 }, {3 , 4 }};
121+ int [] result = SaddlebackSearch .find (arr , 1 , -1 , 3 );
122+ assertArrayEquals (new int [] {-1 , -1 }, result , "Negative column index should return {-1, -1}" );
123+ }
124+
125+ /**
126+ * Test null row in matrix returns {-1, -1} safely.
127+ */
128+ @ Test
129+ void testFindWithNullRowInMatrix () {
130+ int [][] arr = {{1 , 2 }, null , {5 , 6 }};
131+ int [] result = SaddlebackSearch .find (arr , 1 , 0 , 5 );
132+ assertArrayEquals (new int [] {-1 , -1 }, result , "Null row in matrix should safely return {-1, -1}" );
133+ }
85134}
0 commit comments