Skip to content

Commit 2205f12

Browse files
committed
Changed: expand det_sign_exact tests for large matrices (internal)
Add unit tests for dimensions $D \ge 5$ to exercise the Bareiss algorithm path. Ensure non-finite entries trigger expected panics and verify pivoting logic when the fast filter is bypassed. Refs: #33
1 parent d911fcc commit 2205f12

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

src/exact.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,33 @@ mod tests {
386386
}
387387

388388
#[test]
389-
fn det_sign_exact_pivot_needed_in_first_column() {
390-
// First column has zero on diagonal but non-zero below → needs pivoting.
391-
let m = Matrix::<3>::from_rows([[0.0, 1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0]]);
389+
#[should_panic(expected = "non-finite matrix entry")]
390+
fn det_sign_exact_panics_on_nan_5x5() {
391+
// D ≥ 5 bypasses the fast filter, exercising the bareiss_det path.
392+
let mut m = Matrix::<5>::identity();
393+
m.set(2, 3, f64::NAN);
394+
let _ = m.det_sign_exact();
395+
}
396+
397+
#[test]
398+
#[should_panic(expected = "non-finite matrix entry")]
399+
fn det_sign_exact_panics_on_infinity_5x5() {
400+
let mut m = Matrix::<5>::identity();
401+
m.set(0, 0, f64::INFINITY);
402+
let _ = m.det_sign_exact();
403+
}
404+
405+
#[test]
406+
fn det_sign_exact_pivot_needed_5x5() {
407+
// D ≥ 5 skips the fast filter → exercises Bareiss pivoting.
408+
// Permutation matrix with a single swap (rows 0↔1) → det = −1.
409+
let m = Matrix::<5>::from_rows([
410+
[0.0, 1.0, 0.0, 0.0, 0.0],
411+
[1.0, 0.0, 0.0, 0.0, 0.0],
412+
[0.0, 0.0, 1.0, 0.0, 0.0],
413+
[0.0, 0.0, 0.0, 1.0, 0.0],
414+
[0.0, 0.0, 0.0, 0.0, 1.0],
415+
]);
392416
assert_eq!(m.det_sign_exact(), -1);
393417
}
394418

0 commit comments

Comments
 (0)