From 2cd79851c3aadc2964f534b258f2cc5d8bfd0897 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 25 Jul 2017 11:19:18 -0400 Subject: [PATCH] Mint vector tests --- tests/core/conversion.rs | 42 +++++++++++++++++++++++++++++++++------- tests/core/mod.rs | 2 ++ tests/lib.rs | 2 ++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/tests/core/conversion.rs b/tests/core/conversion.rs index ad5590da..84420569 100644 --- a/tests/core/conversion.rs +++ b/tests/core/conversion.rs @@ -153,14 +153,14 @@ macro_rules! array_vector_conversion( fn $array_vector_conversion_i() { let v = $Vector::from_fn(|i, _| i); let arr: [usize; $SZ] = v.into(); - let arr_ref = v.as_ref(); + let arr_ref: &[usize; $SZ] = v.as_ref(); let v2 = $Vector::from(arr); - + for i in 0 .. $SZ { assert_eq!(arr[i], i); assert_eq!(arr_ref[i], i); } - + assert_eq!(v, v2); } )*} @@ -183,12 +183,12 @@ macro_rules! array_row_vector_conversion( let arr: [usize; $SZ] = v.into(); let arr_ref = v.as_ref(); let v2 = $Vector::from(arr); - + for i in 0 .. $SZ { assert_eq!(arr[i], i); assert_eq!(arr_ref[i], i); } - + assert_eq!(v, v2); } )*} @@ -211,14 +211,14 @@ macro_rules! array_matrix_conversion( let arr: [[usize; $NRows]; $NCols] = m.into(); let arr_ref = m.as_ref(); let m2 = $Matrix::from(arr); - + for i in 0 .. $NRows { for j in 0 .. $NCols { assert_eq!(arr[j][i], i * 10 + j); assert_eq!(arr_ref[j][i], i * 10 + j); } } - + assert_eq!(m, m2); } )*} @@ -255,3 +255,31 @@ array_matrix_conversion!( array_matrix_conversion_6_5, Matrix6x5, (6, 5); array_matrix_conversion_6_6, Matrix6, (6, 6); ); + +#[cfg(feature = "mint")] +macro_rules! mint_vector_conversion( + ($($mint_vector_conversion_i: ident, $Vector: ident, $SZ: expr);* $(;)*) => {$( + #[test] + fn $mint_vector_conversion_i() { + let v = $Vector::from_fn(|i, _| i); + let mv: mint::$Vector = v.into(); + let mv_ref: &mint::$Vector = v.as_ref(); + let v2 = $Vector::from(mv); + + let arr: [usize; $SZ] = mv.into(); + for i in 0 .. $SZ { + assert_eq!(arr[i], i); + } + + assert_eq!(&mv, mv_ref); + assert_eq!(v, v2); + } + )*} +); + +#[cfg(feature = "mint")] +mint_vector_conversion!( + mint_vector_conversion_2, Vector2, 2; + mint_vector_conversion_3, Vector3, 3; + mint_vector_conversion_4, Vector4, 4; +); diff --git a/tests/core/mod.rs b/tests/core/mod.rs index eb707f2c..95a54767 100644 --- a/tests/core/mod.rs +++ b/tests/core/mod.rs @@ -6,3 +6,5 @@ mod blas; mod serde; #[cfg(feature = "abomonation-serialize")] mod abomonation; +#[cfg(feature = "mint")] +extern crate mint; diff --git a/tests/lib.rs b/tests/lib.rs index 3cdbb6d4..4b913031 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -7,6 +7,8 @@ extern crate num_traits as num; extern crate serde_json; #[cfg(feature = "abomonation-serialize")] extern crate abomonation; +#[cfg(feature = "mint")] +extern crate mint; extern crate rand; extern crate alga; extern crate nalgebra as na;