From fa35635486ac8eda2a1d6fb5415eb7f86c80c893 Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Wed, 23 Feb 2022 14:38:16 +0100 Subject: [PATCH] Matrix: change naming of sparse vector test --- src/lib/matrix/test/CMakeLists.txt | 4 +- ...eVector.cpp => MatrixSparseVectorTest.cpp} | 65 +++++++++++++------ .../test/{unwrap.cpp => MatrixUnwrapTest.cpp} | 4 +- 3 files changed, 49 insertions(+), 24 deletions(-) rename src/lib/matrix/test/{sparseVector.cpp => MatrixSparseVectorTest.cpp} (55%) rename src/lib/matrix/test/{unwrap.cpp => MatrixUnwrapTest.cpp} (95%) diff --git a/src/lib/matrix/test/CMakeLists.txt b/src/lib/matrix/test/CMakeLists.txt index 42a581b8d3..9767284b9a 100644 --- a/src/lib/matrix/test/CMakeLists.txt +++ b/src/lib/matrix/test/CMakeLists.txt @@ -43,5 +43,5 @@ foreach(test_name ${tests}) add_dependencies(test_results test-matrix_${test_name}) endforeach() -px4_add_unit_gtest(SRC sparseVector.cpp) -px4_add_unit_gtest(SRC unwrap.cpp) +px4_add_unit_gtest(SRC MatrixSparseVectorTest.cpp) +px4_add_unit_gtest(SRC MatrixUnwrapTest.cpp) diff --git a/src/lib/matrix/test/sparseVector.cpp b/src/lib/matrix/test/MatrixSparseVectorTest.cpp similarity index 55% rename from src/lib/matrix/test/sparseVector.cpp rename to src/lib/matrix/test/MatrixSparseVectorTest.cpp index c2a7d80476..14fd28af1d 100644 --- a/src/lib/matrix/test/sparseVector.cpp +++ b/src/lib/matrix/test/MatrixSparseVectorTest.cpp @@ -1,9 +1,42 @@ -#include +/**************************************************************************** + * + * Copyright (C) 2022 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + #include +#include using namespace matrix; -TEST(sparseVectorTest, defaultConstruction) +TEST(MatrixSparseVectorTest, defaultConstruction) { SparseVectorf<24, 4, 6> a; EXPECT_EQ(a.non_zeros(), 2); @@ -13,7 +46,7 @@ TEST(sparseVectorTest, defaultConstruction) a.at<6>() = 2.f; } -TEST(sparseVectorTest, initializationWithData) +TEST(MatrixSparseVectorTest, initializationWithData) { const float data[3] = {1.f, 2.f, 3.f}; SparseVectorf<24, 4, 6, 22> a(data); @@ -26,7 +59,7 @@ TEST(sparseVectorTest, initializationWithData) EXPECT_FLOAT_EQ(a.at<22>(), data[2]); } -TEST(sparseVectorTest, initialisationFromVector) +TEST(MatrixSparseVectorTest, initialisationFromVector) { const Vector3f vec(1.f, 2.f, 3.f); const SparseVectorf<3, 0, 2> a(vec); @@ -34,7 +67,7 @@ TEST(sparseVectorTest, initialisationFromVector) EXPECT_FLOAT_EQ(a.at<2>(), vec(2)); } -TEST(sparseVectorTest, accessDataWithCompressedIndices) +TEST(MatrixSparseVectorTest, accessDataWithCompressedIndices) { const Vector3f vec(1.f, 2.f, 3.f); SparseVectorf<3, 0, 2> a(vec); @@ -47,7 +80,7 @@ TEST(sparseVectorTest, accessDataWithCompressedIndices) EXPECT_FLOAT_EQ(a.at<2>(), a.atCompressedIndex(1)); } -TEST(sparseVectorTest, setZero) +TEST(MatrixSparseVectorTest, setZero) { const float data[3] = {1.f, 2.f, 3.f}; SparseVectorf<24, 4, 6, 22> a(data); @@ -57,7 +90,7 @@ TEST(sparseVectorTest, setZero) EXPECT_FLOAT_EQ(a.at<22>(), 0.f); } -TEST(sparseVectorTest, additionWithDenseVector) +TEST(MatrixSparseVectorTest, additionWithDenseVector) { Vector dense_vec; dense_vec.setAll(1.f); @@ -70,7 +103,7 @@ TEST(sparseVectorTest, additionWithDenseVector) EXPECT_FLOAT_EQ(res(3), 4.f); } -TEST(sparseVectorTest, addScalar) +TEST(MatrixSparseVectorTest, addScalar) { const float data[3] = {1.f, 2.f, 3.f}; SparseVectorf<4, 1, 2, 3> sparse_vec(data); @@ -80,7 +113,7 @@ TEST(sparseVectorTest, addScalar) EXPECT_FLOAT_EQ(sparse_vec.at<3>(), 5.f); } -TEST(sparseVectorTest, dotProductWithDenseVector) +TEST(MatrixSparseVectorTest, dotProductWithDenseVector) { Vector dense_vec; dense_vec.setAll(3.f); @@ -90,7 +123,7 @@ TEST(sparseVectorTest, dotProductWithDenseVector) EXPECT_FLOAT_EQ(res, 18.f); } -TEST(sparseVectorTest, multiplicationWithDenseMatrix) +TEST(MatrixSparseVectorTest, multiplicationWithDenseMatrix) { Matrix dense_matrix; dense_matrix.setAll(2.f); @@ -102,7 +135,7 @@ TEST(sparseVectorTest, multiplicationWithDenseMatrix) EXPECT_TRUE(isEqual(res_dense, res_sparse)); } -TEST(sparseVectorTest, quadraticForm) +TEST(MatrixSparseVectorTest, quadraticForm) { float matrix_data[9] = {1, 2, 3, 2, 4, 5, @@ -114,7 +147,7 @@ TEST(sparseVectorTest, quadraticForm) EXPECT_FLOAT_EQ(quadraticForm(dense_matrix, sparse_vec), 204.f); } -TEST(sparseVectorTest, norms) +TEST(MatrixSparseVectorTest, norms) { const float data[2] = {3.f, 4.f}; const SparseVectorf<4, 1, 3> sparse_vec(data); @@ -123,11 +156,3 @@ TEST(sparseVectorTest, norms) EXPECT_TRUE(sparse_vec.longerThan(4.5f)); EXPECT_FALSE(sparse_vec.longerThan(5.5f)); } - - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - std::cout << "Run SparseVector tests" << std::endl; - return RUN_ALL_TESTS(); -} diff --git a/src/lib/matrix/test/unwrap.cpp b/src/lib/matrix/test/MatrixUnwrapTest.cpp similarity index 95% rename from src/lib/matrix/test/unwrap.cpp rename to src/lib/matrix/test/MatrixUnwrapTest.cpp index 09c24d00ed..f774174ccf 100644 --- a/src/lib/matrix/test/unwrap.cpp +++ b/src/lib/matrix/test/MatrixUnwrapTest.cpp @@ -3,7 +3,7 @@ using namespace matrix; -TEST(Unwrap, UnwrapFloats) +TEST(MatrixUnwrapTest, UnwrapFloats) { const float M_TWO_PI_F = float(M_PI * 2); @@ -32,7 +32,7 @@ TEST(Unwrap, UnwrapFloats) } } -TEST(Unwrap, UnwrapDoubles) +TEST(MatrixUnwrapTest, UnwrapDoubles) { const double M_TWO_PI = M_PI * 2;