mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 04:00:01 +00:00
Fix dimension mismatch assertion in zip method and add panic test for incompatible matrices
This commit is contained in:
parent
601dc66d7d
commit
2da1e9bf04
@ -189,18 +189,12 @@ impl SeriesOps for FloatMatrix {
|
|||||||
where
|
where
|
||||||
F: Fn(f64, f64) -> f64,
|
F: Fn(f64, f64) -> f64,
|
||||||
{
|
{
|
||||||
assert_eq!(
|
assert!(
|
||||||
|
self.rows() == other.rows() && self.cols() == other.cols(),
|
||||||
|
"Matrix dimensions mismatch: left is {}x{}, right is {}x{}",
|
||||||
self.rows(),
|
self.rows(),
|
||||||
|
self.cols(),
|
||||||
other.rows(),
|
other.rows(),
|
||||||
"Row count mismatch: {} vs {}",
|
|
||||||
self.rows(),
|
|
||||||
other.rows()
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
self.cols(),
|
|
||||||
other.cols(),
|
|
||||||
"Column count mismatch: {} vs {}",
|
|
||||||
self.cols(),
|
|
||||||
other.cols()
|
other.cols()
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -420,6 +414,15 @@ mod tests {
|
|||||||
assert_eq!(zipped_matrix, expected_matrix);
|
assert_eq!(zipped_matrix, expected_matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic(expected = "Matrix dimensions mismatch: left is 2x2, right is 3x2")]
|
||||||
|
fn test_series_ops_zip_panic() {
|
||||||
|
let a = FloatMatrix::from_vec(vec![1.0, 2.0, 3.0, 4.0], 2, 2); // 2x2 matrix
|
||||||
|
let b = FloatMatrix::from_vec(vec![5.0, 6.0, 7.0, 8.0, 9.0, 10.0], 3, 2); // 3x2 matrix
|
||||||
|
// This should panic due to dimension mismatch
|
||||||
|
a.zip(&b, |x, y| x + y);
|
||||||
|
}
|
||||||
|
|
||||||
// --- Edge Cases for SeriesOps ---
|
// --- Edge Cases for SeriesOps ---
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user