| 1 |
#![cfg(feature = "proptest-support")] |
| 2 |
|
| 3 |
macro_rules! gen_tests( |
| 4 |
($module: ident, $scalar: expr) => { |
| 5 |
mod $module { |
| 6 |
use na::{Matrix4, ComplexField}; |
| 7 |
#[allow(unused_imports)] |
| 8 |
use crate::core::helper::{RandScalar, RandComplex}; |
| 9 |
use crate::proptest::*; |
| 10 |
use proptest::{prop_assert, proptest}; |
| 11 |
|
| 12 |
fn unzero_diagonal<T: ComplexField>(a: &mut Matrix4<T>) { |
| 13 |
for i in 0..4 { |
| 14 |
if a[(i, i)].clone().norm1() < na::convert(1.0e-7) { |
| 15 |
a[(i, i)] = T::one(); |
| 16 |
} |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
proptest! { |
| 21 |
#[test] |
| 22 |
fn solve_lower_triangular(a in matrix4_($scalar), b in matrix4x5_($scalar)) { |
| 23 |
let mut a = a; |
| 24 |
unzero_diagonal(&mut a); |
| 25 |
let tri = a.lower_triangle(); |
| 26 |
let x = a.solve_lower_triangular(&b).unwrap(); |
| 27 |
|
| 28 |
prop_assert!(relative_eq!(tri * x, b, epsilon = 1.0e-7)) |
| 29 |
} |
| 30 |
|
| 31 |
#[test] |
| 32 |
fn solve_upper_triangular(a in matrix4_($scalar), b in matrix4x5_($scalar)) { |
| 33 |
let mut a = a; |
| 34 |
unzero_diagonal(&mut a); |
| 35 |
let tri = a.upper_triangle(); |
| 36 |
let x = a.solve_upper_triangular(&b).unwrap(); |
| 37 |
|
| 38 |
prop_assert!(relative_eq!(tri * x, b, epsilon = 1.0e-7)) |
| 39 |
} |
| 40 |
|
| 41 |
#[test] |
| 42 |
fn tr_solve_lower_triangular(a in matrix4_($scalar), b in matrix4x5_($scalar)) { |
| 43 |
let mut a = a; |
| 44 |
unzero_diagonal(&mut a); |
| 45 |
let tri = a.lower_triangle(); |
| 46 |
let x = a.tr_solve_lower_triangular(&b).unwrap(); |
| 47 |
|
| 48 |
prop_assert!(relative_eq!(tri.transpose() * x, b, epsilon = 1.0e-7)) |
| 49 |
} |
| 50 |
|
| 51 |
#[test] |
| 52 |
fn tr_solve_upper_triangular(a in matrix4_($scalar), b in matrix4x5_($scalar)) { |
| 53 |
let mut a = a; |
| 54 |
unzero_diagonal(&mut a); |
| 55 |
let tri = a.upper_triangle(); |
| 56 |
let x = a.tr_solve_upper_triangular(&b).unwrap(); |
| 57 |
|
| 58 |
prop_assert!(relative_eq!(tri.transpose() * x, b, epsilon = 1.0e-7)) |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
); |
| 64 |
|
| 65 |
gen_tests!(complex, complex_f64()); |
| 66 |
gen_tests!(f64, PROPTEST_F64); |