Skip to content

Commit 4436d2c

Browse files
committed
test: add some edge tests
1 parent 1fb9023 commit 4436d2c

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/searching/saddleback_search.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ pub fn saddleback_search(
7272
element: isize,
7373
check_sorted: bool,
7474
) -> Result<Option<(usize, usize)>, MatrixError> {
75+
if check_sorted && !is_sorted(matrix) {
76+
return Err(MatrixError::NotSorted);
77+
}
78+
7579
if matrix.is_empty() || matrix.iter().all(|row| row.is_empty()) {
7680
return Ok(None);
7781
}
@@ -80,10 +84,6 @@ pub fn saddleback_search(
8084
return Err(MatrixError::NonRectangularInput);
8185
}
8286

83-
if check_sorted && !is_sorted(matrix) {
84-
return Err(MatrixError::NotSorted);
85-
}
86-
8787
let mut left_index = 0;
8888
let mut right_index = matrix[0].len() - 1;
8989

@@ -242,7 +242,7 @@ mod tests {
242242
1,
243243
Ok(None::<(usize, usize)>),
244244
),
245-
test_unsorted_matrix_with_check: (
245+
test_unsorted_matrix_row_wise: (
246246
vec![
247247
vec![1, 10, 100],
248248
vec![20, 200, 2],
@@ -251,5 +251,14 @@ mod tests {
251251
200,
252252
Err::<Option<(usize, usize)>, MatrixError>(MatrixError::NotSorted),
253253
),
254+
test_unsorted_matrix_column_wise: (
255+
vec![
256+
vec![1, 10, 100],
257+
vec![2, 20, 30],
258+
vec![3, 15, 300],
259+
],
260+
200,
261+
Err::<Option<(usize, usize)>, MatrixError>(MatrixError::NotSorted),
262+
),
254263
}
255264
}

0 commit comments

Comments
 (0)