| 1 |
//! Tests for `matrixcompare` integration. |
| 2 |
//! |
| 3 |
//! The `matrixcompare` crate itself is responsible for testing the actual comparison. |
| 4 |
//! The tests here only check that the necessary trait implementations are correctly implemented, |
| 5 |
//! in addition to some sanity checks with example input. |
| 6 |
|
| 7 |
use matrixcompare::assert_matrix_eq; |
| 8 |
use nalgebra::{OMatrix, U4, U5}; |
| 9 |
|
| 10 |
#[cfg(feature = "proptest-support")] |
| 11 |
use { |
| 12 |
crate::proptest::*, |
| 13 |
matrixcompare::DenseAccess, |
| 14 |
nalgebra::DMatrix, |
| 15 |
proptest::{prop_assert_eq, proptest}, |
| 16 |
}; |
| 17 |
|
| 18 |
#[cfg(feature = "proptest-support")] |
| 19 |
proptest! { |
| 20 |
#[test] |
| 21 |
fn fetch_single_is_equivalent_to_index_f64(matrix in dmatrix()) { |
| 22 |
for i in 0 .. matrix.nrows() { |
| 23 |
for j in 0 .. matrix.ncols() { |
| 24 |
prop_assert_eq!(matrix.fetch_single(i, j), *matrix.index((i, j))); |
| 25 |
} |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
#[test] |
| 30 |
fn matrixcompare_shape_agrees_with_matrix(matrix in dmatrix()) { |
| 31 |
prop_assert_eq!(matrix.nrows(), <DMatrix<f64> as matrixcompare::Matrix<f64>>::rows(&matrix)); |
| 32 |
prop_assert_eq!(matrix.ncols(), <DMatrix<f64> as matrixcompare::Matrix<f64>>::cols(&matrix)); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
#[test] |
| 37 |
fn assert_matrix_eq_dense_positive_comparison() { |
| 38 |
#[rustfmt::skip] |
| 39 |
let a = OMatrix::<_, U4, U5>::from_row_slice(&[ |
| 40 |
1210, 1320, 1430, 1540, 1650, |
| 41 |
2310, 2420, 2530, 2640, 2750, |
| 42 |
3410, 3520, 3630, 3740, 3850, |
| 43 |
4510, 4620, 4730, 4840, 4950, |
| 44 |
]); |
| 45 |
|
| 46 |
#[rustfmt::skip] |
| 47 |
let b = OMatrix::<_, U4, U5>::from_row_slice(&[ |
| 48 |
1210, 1320, 1430, 1540, 1650, |
| 49 |
2310, 2420, 2530, 2640, 2750, |
| 50 |
3410, 3520, 3630, 3740, 3850, |
| 51 |
4510, 4620, 4730, 4840, 4950, |
| 52 |
]); |
| 53 |
|
| 54 |
// Test matrices of static size |
| 55 |
assert_matrix_eq!(a, b); |
| 56 |
assert_matrix_eq!(&a, b); |
| 57 |
assert_matrix_eq!(a, &b); |
| 58 |
assert_matrix_eq!(&a, &b); |
| 59 |
|
| 60 |
// Test matrices of dynamic size |
| 61 |
let a_dyn = a.index((0..4, 0..5)); |
| 62 |
let b_dyn = b.index((0..4, 0..5)); |
| 63 |
assert_matrix_eq!(a_dyn, b_dyn); |
| 64 |
assert_matrix_eq!(a_dyn, &b_dyn); |
| 65 |
assert_matrix_eq!(&a_dyn, b_dyn); |
| 66 |
assert_matrix_eq!(&a_dyn, &b_dyn); |
| 67 |
} |
| 68 |
|
| 69 |
#[test] |
| 70 |
#[should_panic] |
| 71 |
fn assert_matrix_eq_dense_negative_comparison() { |
| 72 |
#[rustfmt::skip] |
| 73 |
let a = OMatrix::<_, U4, U5>::from_row_slice(&[ |
| 74 |
1210, 1320, 1430, 1540, 1650, |
| 75 |
2310, 2420, 2530, 2640, 2750, |
| 76 |
3410, 3520, 3630, 3740, 3850, |
| 77 |
4510, 4620, -4730, 4840, 4950, |
| 78 |
]); |
| 79 |
|
| 80 |
#[rustfmt::skip] |
| 81 |
let b = OMatrix::<_, U4, U5>::from_row_slice(&[ |
| 82 |
1210, 1320, 1430, 1540, 1650, |
| 83 |
2310, 2420, 2530, 2640, 2750, |
| 84 |
3410, 3520, 3630, 3740, 3850, |
| 85 |
4510, 4620, 4730, 4840, 4950, |
| 86 |
]); |
| 87 |
|
| 88 |
assert_matrix_eq!(a, b); |
| 89 |
} |