From 6026a0543349ee39c48847b165045df39116cc90 Mon Sep 17 00:00:00 2001 From: Andreas Longva Date: Wed, 5 May 2021 10:03:18 +0200 Subject: [PATCH] Test that matrix macros work with arbitrary expressions --- nalgebra-macros/tests/tests.rs | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/nalgebra-macros/tests/tests.rs b/nalgebra-macros/tests/tests.rs index 206e5e66..22daaf8d 100644 --- a/nalgebra-macros/tests/tests.rs +++ b/nalgebra-macros/tests/tests.rs @@ -210,4 +210,49 @@ fn dvector_builtin_types() { let _: DVector = dvector![0, 1, 2, 3]; let _: DVector = dvector![0.0, 1.0, 2.0, 3.0]; let _: DVector = dvector![0.0, 1.0, 2.0, 3.0]; +} + +/// Black box function that's just used for testing macros with function call expressions. +fn f(x: T) -> T { + x +} + +#[rustfmt::skip] +#[test] +fn matrix_arbitrary_expressions() { + // Test that matrix! supports arbitrary expressions for its elements + let a = matrix![1 + 2 , 2 * 3; + 4 * f(5 + 6), 7 - 8 * 9]; + let a_expected = Matrix2::new(1 + 2 , 2 * 3, + 4 * f(5 + 6), 7 - 8 * 9); + assert_eq_and_type!(a, a_expected); +} + +#[rustfmt::skip] +#[test] +fn dmatrix_arbitrary_expressions() { + // Test that dmatrix! supports arbitrary expressions for its elements + let a = dmatrix![1 + 2 , 2 * 3; + 4 * f(5 + 6), 7 - 8 * 9]; + let a_expected = DMatrix::from_row_slice(2, 2, &[1 + 2 , 2 * 3, + 4 * f(5 + 6), 7 - 8 * 9]); + assert_eq_and_type!(a, a_expected); +} + +#[rustfmt::skip] +#[test] +fn vector_arbitrary_expressions() { + // Test that vector! supports arbitrary expressions for its elements + let a = vector![1 + 2, 2 * 3, 4 * f(5 + 6), 7 - 8 * 9]; + let a_expected = Vector4::new(1 + 2, 2 * 3, 4 * f(5 + 6), 7 - 8 * 9); + assert_eq_and_type!(a, a_expected); +} + +#[rustfmt::skip] +#[test] +fn dvector_arbitrary_expressions() { + // Test that dvector! supports arbitrary expressions for its elements + let a = dvector![1 + 2, 2 * 3, 4 * f(5 + 6), 7 - 8 * 9]; + let a_expected = DVector::from_column_slice(&[1 + 2, 2 * 3, 4 * f(5 + 6), 7 - 8 * 9]); + assert_eq_and_type!(a, a_expected); } \ No newline at end of file