Skip to content

Commit 9e7cfbf

Browse files
authored
Affine approx tests (#625)
* Add approx tests for affine types. * fmt
1 parent 87518c8 commit 9e7cfbf

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

src/features/impl_approx.rs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,30 @@ mod test {
186186
};
187187
}
188188

189+
macro_rules! impl_affine_approx_test {
190+
($prim:ident, $type:ident, $from:ident, $mat:ident, $ones:expr) => {
191+
let ones = $mat::from($ones);
192+
let one_eps = ones * $mat::default_epsilon();
193+
let two_eps = one_eps + one_eps;
194+
195+
let one_ulp = ones * $prim::from_bits($prim::to_bits(1.0) + 1);
196+
let four_ulp = ones * $prim::from_bits($prim::to_bits(1.0) + 16);
197+
198+
approx::assert_abs_diff_eq!($type::$from(ones), $type::$from(ones));
199+
approx::assert_abs_diff_eq!($type::$from(ones), $type::$from(ones + one_eps));
200+
approx::assert_abs_diff_eq!($type::$from(ones), $type::$from(ones - one_eps));
201+
202+
approx::assert_abs_diff_ne!($type::$from(ones), $type::$from(ones + two_eps));
203+
approx::assert_abs_diff_ne!($type::$from(ones), $type::$from(ones - two_eps));
204+
205+
approx::assert_relative_eq!($type::$from(ones), $type::$from(ones));
206+
approx::assert_relative_ne!($type::$from(ones), $type::$from(ones - ones));
207+
208+
// defaults to 4 ulps and I have no idea how to pass other parameters to this macro :)
209+
approx::assert_ulps_eq!($type::$from(ones), $type::$from(one_ulp));
210+
approx::assert_ulps_ne!($type::$from(ones), $type::$from(four_ulp));
211+
};
212+
}
189213
#[test]
190214
fn test_approx() {
191215
const ONESF32: [f32; 16] = [1.0; 16];
@@ -199,8 +223,20 @@ mod test {
199223
impl_approx_test!(f32, Mat3, Mat3::from_cols_slice(&ONESF32));
200224
impl_approx_test!(f32, Mat3A, Mat3A::from_cols_slice(&ONESF32));
201225
impl_approx_test!(f32, Mat4, Mat4::from_cols_slice(&ONESF32));
202-
// impl_approx_test!(f32, Affine2, Affine2::from_cols_slice(&ONESF32));
203-
// impl_approx_test!(f32, Affine3A, Affine3A::from_cols_slice(&ONESF32));
226+
impl_affine_approx_test!(
227+
f32,
228+
Affine2,
229+
from_mat3,
230+
Mat3,
231+
Affine2::from_cols_slice(&ONESF32)
232+
);
233+
impl_affine_approx_test!(
234+
f32,
235+
Affine3A,
236+
from_mat4,
237+
Mat4,
238+
Affine3A::from_cols_slice(&ONESF32)
239+
);
204240

205241
const ONESF64: [f64; 16] = [1.0; 16];
206242
impl_approx_test!(f64, DVec2);
@@ -210,7 +246,19 @@ mod test {
210246
impl_approx_test!(f64, DMat2, DMat2::from_cols_slice(&ONESF64));
211247
impl_approx_test!(f64, DMat3, DMat3::from_cols_slice(&ONESF64));
212248
impl_approx_test!(f64, DMat4, DMat4::from_cols_slice(&ONESF64));
213-
// impl_approx_test!(f64, DAffine2, DAffine2::from_cols_slice(&ONESF64));
214-
// impl_approx_test!(f64, DAffine3, DAffine3::from_cols_slice(&ONESF64));
249+
impl_affine_approx_test!(
250+
f64,
251+
DAffine2,
252+
from_mat3,
253+
DMat3,
254+
DAffine2::from_cols_slice(&ONESF64)
255+
);
256+
impl_affine_approx_test!(
257+
f64,
258+
DAffine3,
259+
from_mat4,
260+
DMat4,
261+
DAffine3::from_cols_slice(&ONESF64)
262+
);
215263
}
216264
}

0 commit comments

Comments
 (0)