1
0
Fork 0

TestSuite: Migration of the LaRCSim matrix computation unit tests.

This commit is contained in:
Edward d'Auvergne 2018-03-13 09:57:27 +01:00
parent 0030f655e0
commit d51e21c667
7 changed files with 108 additions and 24 deletions

View file

@ -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)

View file

@ -1,6 +1,7 @@
# Add each unit test category.
foreach( unit_test_category
general
FDM
Navaids
Scripting
)

View file

@ -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
)

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "test_ls_matrix.hxx"
// Set up the unit tests.
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(LaRCSimMatrixTests, "Unit tests");

View file

@ -1,10 +1,13 @@
#include "test_ls_matrix.hxx"
#include <simgear/constants.h>
#include <simgear/misc/test_macros.hxx>
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();
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef _FG_LARCSIM_MATRIX_UNIT_TESTS_HXX
#define _FG_LARCSIM_MATRIX_UNIT_TESTS_HXX
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
// 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

View file

@ -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)