Skip to content

Commit 9bdf71e

Browse files
committed
[add] tests for 4x4 and 5x5 row swaps
1 parent 02c5cd5 commit 9bdf71e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

crates/lambda-rs/src/math/matrix.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,29 @@ mod tests {
572572
assert_eq!(m2.determinant(), Ok(-306.0));
573573
}
574574

575+
#[test]
576+
fn determinant_4x4_stack_path_handles_row_swap_sign() {
577+
let m = [
578+
[0.0, 2.0, 0.0, 0.0],
579+
[1.0, 0.0, 0.0, 0.0],
580+
[0.0, 0.0, 3.0, 0.0],
581+
[0.0, 0.0, 0.0, 4.0],
582+
];
583+
assert_eq!(m.determinant(), Ok(-24.0));
584+
}
585+
586+
#[test]
587+
fn determinant_5x5_dynamic_path_handles_row_swap_sign() {
588+
let m = [
589+
[0.0, 2.0, 0.0, 0.0, 0.0],
590+
[1.0, 0.0, 0.0, 0.0, 0.0],
591+
[0.0, 0.0, 3.0, 0.0, 0.0],
592+
[0.0, 0.0, 0.0, 4.0, 0.0],
593+
[0.0, 0.0, 0.0, 0.0, 5.0],
594+
];
595+
assert_eq!(m.determinant(), Ok(-120.0));
596+
}
597+
575598
#[test]
576599
fn determinant_preserves_small_non_zero_pivot_in_stack_path() {
577600
let m = [[1.0e-8, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0]];

0 commit comments

Comments
 (0)