From 308a6c91cbce698c5602296eb5b69a755e47b0df Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Wed, 15 Nov 2017 22:44:03 +0100 Subject: [PATCH] Test: added copyTo tests for Vector3, Quaternion and Matrix including clolumn-major order --- .gitignore | 1 + test/CMakeLists.txt | 1 + test/attitude.cpp | 10 --------- test/copyto.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 test/copyto.cpp diff --git a/.gitignore b/.gitignore index 8efccc5293..09e562fc8c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ Makefile test/attitude test/cmake_install.cmake test/CMakeFiles/ +test/copyto test/coverage.info test/CTestTestfile.cmake test/filter diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2c7d42981f..77284c0170 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,6 +16,7 @@ set(tests squareMatrix helper hatvee + copyto ) add_custom_target(test_build) diff --git a/test/attitude.cpp b/test/attitude.cpp index 25bdefa489..7972aedb9e 100644 --- a/test/attitude.cpp +++ b/test/attitude.cpp @@ -334,16 +334,6 @@ int main() R = Dcmf(q); TEST(isEqual(q, Quatf(R))); - - // Quaternion copyTo - q = Quatf(1, 2, 3, 4); - float dst[4] = {}; - q.copyTo(dst); - TEST(fabs(q(0) - dst[0]) < eps); - TEST(fabs(q(1) - dst[1]) < eps); - TEST(fabs(q(2) - dst[2]) < eps); - TEST(fabs(q(3) - dst[3]) < eps); - return 0; } diff --git a/test/copyto.cpp b/test/copyto.cpp new file mode 100644 index 0000000000..0a9ccb20f7 --- /dev/null +++ b/test/copyto.cpp @@ -0,0 +1,51 @@ +#include "test_macros.hpp" +#include + +using namespace matrix; + +int main() +{ + float eps = 1e-6f; + + // Vector3 copyTo + Vector3f v(1, 2, 3); + float dst3[3] = {}; + v.copyTo(dst3); + for (size_t i = 0; i < 3; i++) { + TEST(fabs(v(i) - dst3[i]) < eps); + } + + // Quaternion copyTo + Quatf q(1, 2, 3, 4); + float dst4[4] = {}; + q.copyTo(dst4); + for (size_t i = 0; i < 4; i++) { + TEST(fabs(q(i) - dst4[i]) < eps); + } + + // Matrix copyTo + Matrix A; + A(0,0) = 1; + A(0,1) = 2; + A(0,2) = 3; + A(1,0) = 4; + A(1,1) = 5; + A(1,2) = 6; + float array_A[6] = {}; + A.copyTo(array_A); + float array_row[6] = {1, 2, 3, 4, 5, 6}; + for (size_t i = 0; i < 6; i++) { + TEST(fabs(array_A[i] - array_row[i]) < eps); + } + + // Matrix copyToColumnMajor + A.copyToColumnMajor(array_A); + float array_column[6] = {1, 4, 2, 5, 3, 6}; + for (size_t i = 0; i < 6; i++) { + TEST(fabs(array_A[i] - array_column[i]) < eps); + } + + return 0; +} + +/* vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */