From d51e21c6672dde184a710526edccd2a10d82d092 Mon Sep 17 00:00:00 2001 From: Edward d'Auvergne Date: Tue, 13 Mar 2018 09:57:27 +0100 Subject: [PATCH] TestSuite: Migration of the LaRCSim matrix computation unit tests. --- test_suite/CMakeLists.txt | 1 + test_suite/unit_tests/CMakeLists.txt | 1 + test_suite/unit_tests/FDM/CMakeLists.txt | 12 ++++ test_suite/unit_tests/FDM/TestSuite.cxx | 24 ++++++++ .../unit_tests/FDM}/test_ls_matrix.cxx | 34 +++++------ test_suite/unit_tests/FDM/test_ls_matrix.hxx | 56 +++++++++++++++++++ tests/CMakeLists.txt | 4 -- 7 files changed, 108 insertions(+), 24 deletions(-) create mode 100644 test_suite/unit_tests/FDM/CMakeLists.txt create mode 100644 test_suite/unit_tests/FDM/TestSuite.cxx rename {tests => test_suite/unit_tests/FDM}/test_ls_matrix.cxx (83%) create mode 100644 test_suite/unit_tests/FDM/test_ls_matrix.hxx diff --git a/test_suite/CMakeLists.txt b/test_suite/CMakeLists.txt index 185e09c76..f4bacbaf0 100644 --- a/test_suite/CMakeLists.txt +++ b/test_suite/CMakeLists.txt @@ -53,6 +53,7 @@ endif() # Unit test suites. add_test(FlightplanUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u FlightplanTests) +add_test(LaRCSimMatrixUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u LaRCSimMatrixTests) add_test(MktimeUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u MktimeTests) add_test(NasalSysUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u NasalSysTests) diff --git a/test_suite/unit_tests/CMakeLists.txt b/test_suite/unit_tests/CMakeLists.txt index 92d5fb50e..04ed1dc57 100644 --- a/test_suite/unit_tests/CMakeLists.txt +++ b/test_suite/unit_tests/CMakeLists.txt @@ -1,6 +1,7 @@ # Add each unit test category. foreach( unit_test_category general + FDM Navaids Scripting ) diff --git a/test_suite/unit_tests/FDM/CMakeLists.txt b/test_suite/unit_tests/FDM/CMakeLists.txt new file mode 100644 index 000000000..38f82303d --- /dev/null +++ b/test_suite/unit_tests/FDM/CMakeLists.txt @@ -0,0 +1,12 @@ +set(TESTSUITE_SOURCES + ${TESTSUITE_SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/test_ls_matrix.cxx + PARENT_SCOPE +) + +set(TESTSUITE_HEADERS + ${TESTSUITE_HEADERS} + ${CMAKE_CURRENT_SOURCE_DIR}/test_ls_matrix.hxx + PARENT_SCOPE +) diff --git a/test_suite/unit_tests/FDM/TestSuite.cxx b/test_suite/unit_tests/FDM/TestSuite.cxx new file mode 100644 index 000000000..b628e6dbd --- /dev/null +++ b/test_suite/unit_tests/FDM/TestSuite.cxx @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2018 Edward d'Auvergne + * + * This file is part of the program FlightGear. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test_ls_matrix.hxx" + + +// Set up the unit tests. +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(LaRCSimMatrixTests, "Unit tests"); diff --git a/tests/test_ls_matrix.cxx b/test_suite/unit_tests/FDM/test_ls_matrix.cxx similarity index 83% rename from tests/test_ls_matrix.cxx rename to test_suite/unit_tests/FDM/test_ls_matrix.cxx index 31faf78f3..4a09c688c 100644 --- a/tests/test_ls_matrix.cxx +++ b/test_suite/unit_tests/FDM/test_ls_matrix.cxx @@ -1,10 +1,13 @@ +#include "test_ls_matrix.hxx" + #include #include extern "C" { #include "src/FDM/LaRCsim/ls_matrix.h" } -void testCopyMatrix() + +void LaRCSimMatrixTests::testCopyMatrix() { int nelm = 20; double **src = nr_matrix(1, nelm, 1, nelm); @@ -19,13 +22,13 @@ void testCopyMatrix() for (int i=1; i<=nelm; ++i) for (int j=1; j<=nelm; ++j) - SG_CHECK_EQUAL(src[i][j], dest[i][j]); + CPPUNIT_ASSERT_EQUAL(src[i][j], dest[i][j]); nr_free_matrix(src, 1, nelm, 1, nelm); nr_free_matrix(dest, 1, nelm, 1, nelm); } -void testIdentityMatrix() +void LaRCSimMatrixTests::testIdentityMatrix() { int nelm = 10; double **id = nr_matrix(1, nelm, 1, nelm); @@ -38,12 +41,12 @@ void testIdentityMatrix() for (int i=1; i<=nelm; ++i) for (int j=1; j<=nelm; ++j) - SG_CHECK_EQUAL_EP(id[i][j], i == j ? 1.0 : 0.0); + CPPUNIT_ASSERT_DOUBLES_EQUAL(id[i][j], i == j ? 1.0 : 0.0, 1e-9); nr_free_matrix(id, 1, nelm, 1, nelm); } -void testOrthogonalMatrix() +void LaRCSimMatrixTests::testOrthogonalMatrix() { int nelm = 3; double **m = nr_matrix(1, nelm, 1, nelm); @@ -65,13 +68,13 @@ void testOrthogonalMatrix() for (int i=1; i<=nelm; ++i) for (int j=1; j<=nelm; ++j) - SG_CHECK_EQUAL_EP(m[i][j], inv[j][i]); + CPPUNIT_ASSERT_DOUBLES_EQUAL(m[i][j], inv[j][i], 1e-9); nr_free_matrix(m, 1, nelm, 1, nelm); nr_free_matrix(inv, 1, nelm, 1, nelm); } -void testRandomMatrix() +void LaRCSimMatrixTests::testRandomMatrix() { int nelm = 20; double **src = nr_matrix(1, nelm, 1, nelm); @@ -95,14 +98,14 @@ void testRandomMatrix() for (int i=1; i<=nelm; ++i) for (int j=1; j<=nelm; ++j) - SG_CHECK_EQUAL_EP(id[i][j], i == j ? 1.0 : 0.0); + CPPUNIT_ASSERT_DOUBLES_EQUAL(id[i][j], i == j ? 1.0 : 0.0, 1e-9); nr_free_matrix(src, 1, nelm, 1, nelm); nr_free_matrix(inv, 1, nelm, 1, nelm); nr_free_matrix(id, 1, nelm, 1, nelm); } -void testSolveLinearSystem() +void LaRCSimMatrixTests::testSolveLinearSystem() { int nelm = 20; double **src = nr_matrix(1, nelm, 1, nelm); @@ -133,7 +136,7 @@ void testSolveLinearSystem() for (int i=1; i<=nelm; ++i) for (int j=1; j<=nelm; ++j) - SG_CHECK_EQUAL_EP(check[i][j], i == j ? 1.0 : 0.0); + CPPUNIT_ASSERT_DOUBLES_EQUAL(check[i][j], i == j ? 1.0 : 0.0, 1e-9); for (int i=1; i<=nelm; ++i) { check[i][1] = 0.0; @@ -142,7 +145,7 @@ void testSolveLinearSystem() } for (int i=1; i<=nelm; ++i) - SG_CHECK_EQUAL_EP(check[i][1], rhs[i][1]); + CPPUNIT_ASSERT_DOUBLES_EQUAL(check[i][1], rhs[i][1], 1e-9); nr_free_matrix(src, 1, nelm, 1, nelm); nr_free_matrix(inv, 1, nelm, 1, nelm); @@ -150,12 +153,3 @@ void testSolveLinearSystem() nr_free_matrix(rhs, 1, nelm, 1, 1); nr_free_matrix(sol, 1, nelm, 1, 1); } - -int main(int argc, char* argv[]) -{ - testCopyMatrix(); - testIdentityMatrix(); - testOrthogonalMatrix(); - testRandomMatrix(); - testSolveLinearSystem(); -} diff --git a/test_suite/unit_tests/FDM/test_ls_matrix.hxx b/test_suite/unit_tests/FDM/test_ls_matrix.hxx new file mode 100644 index 000000000..4c445db71 --- /dev/null +++ b/test_suite/unit_tests/FDM/test_ls_matrix.hxx @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2018 Edward d'Auvergne + * + * This file is part of the program FlightGear. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef _FG_LARCSIM_MATRIX_UNIT_TESTS_HXX +#define _FG_LARCSIM_MATRIX_UNIT_TESTS_HXX + + +#include +#include + + +// The LaRCSim matrix unit tests. +class LaRCSimMatrixTests : public CppUnit::TestFixture +{ + // Set up the test suite. + CPPUNIT_TEST_SUITE(LaRCSimMatrixTests); + CPPUNIT_TEST(testCopyMatrix); + CPPUNIT_TEST(testIdentityMatrix); + CPPUNIT_TEST(testOrthogonalMatrix); + CPPUNIT_TEST(testRandomMatrix); + CPPUNIT_TEST(testSolveLinearSystem); + CPPUNIT_TEST_SUITE_END(); + +public: + // Set up function for each test. + void setUp() {} + + // Clean up after each test. + void tearDown() {} + + // The tests. + void testCopyMatrix(); + void testIdentityMatrix(); + void testOrthogonalMatrix(); + void testRandomMatrix(); + void testSolveLinearSystem(); +}; + +#endif // _FG_LARCSIM_MATRIX_UNIT_TESTS_HXX diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0d5af06db..b796949d8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -117,10 +117,6 @@ endmacro() flightgear_test(test_navs test_navaids2.cxx) -add_executable(test_ls_matrix test_ls_matrix.cxx ${CMAKE_SOURCE_DIR}/src/FDM/LaRCsim/ls_matrix.c) -target_link_libraries(test_ls_matrix SimGearCore) -add_test(test_ls_matrix ${EXECUTABLE_OUTPUT_PATH}/test_ls_matrix) - add_executable(testAeroElement testAeroElement.cxx ${CMAKE_SOURCE_DIR}/src/FDM/AIWake/AeroElement.cxx) target_link_libraries(testAeroElement SimGearCore) add_test(testAeroElement ${EXECUTABLE_OUTPUT_PATH}/testAeroElement)