1
0
Fork 0

TestSuite: Migration of the AeroElement tests into the CppUnit infrastructure.

This commit is contained in:
Edward d'Auvergne 2018-06-06 22:15:13 +02:00
parent 88179ec9c1
commit 7aa034bc80
7 changed files with 117 additions and 58 deletions

View file

@ -23,6 +23,9 @@
#ifndef _FG_AEROELEMENT_HXX
#define _FG_AEROELEMENT_HXX
#include <simgear/math/SGMathFwd.hxx>
class AeroElement : public SGReferenced {
public:
AeroElement(const SGVec3d& n1, const SGVec3d& n2, const SGVec3d& n3,

View file

@ -64,6 +64,7 @@ endif()
# Unit test suites.
add_test(AddonManagementUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u AddonManagementTests)
add_test(AeroElementUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u AeroElementTests)
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)

View file

@ -2,11 +2,13 @@ set(TESTSUITE_SOURCES
${TESTSUITE_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_ls_matrix.cxx
${CMAKE_CURRENT_SOURCE_DIR}/testAeroElement.cxx
PARENT_SCOPE
)
set(TESTSUITE_HEADERS
${TESTSUITE_HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/test_ls_matrix.hxx
${CMAKE_CURRENT_SOURCE_DIR}/testAeroElement.hxx
PARENT_SCOPE
)

View file

@ -18,7 +18,9 @@
*/
#include "test_ls_matrix.hxx"
#include "testAeroElement.hxx"
// Set up the unit tests.
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AeroElementTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(LaRCSimMatrixTests, "Unit tests");

View file

@ -1,59 +1,61 @@
#include <simgear/constants.h>
#include <simgear/misc/test_macros.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/math/SGVec3.hxx>
#include "FDM/AIWake/AeroElement.hxx"
void testNormal()
#include "testAeroElement.hxx"
void AeroElementTests::testNormal()
{
AeroElement_ptr el = new AeroElement(SGVec3d(-1., -0.5, 0.),
SGVec3d(0., -0.5, 0.),
SGVec3d(0., 0.5, 0.),
SGVec3d(-1., 0.5, 0.));
SGVec3d n = el->getNormal();
SG_CHECK_EQUAL_EP(n[0], 0.0);
SG_CHECK_EQUAL_EP(n[1], 0.0);
SG_CHECK_EQUAL_EP(n[2], -1.0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(n[0], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(n[1], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(n[2], -1.0, 1e-9);
}
void testCollocationPoint()
void AeroElementTests::testCollocationPoint()
{
AeroElement_ptr el = new AeroElement(SGVec3d(-1., -0.5, 0.),
SGVec3d(0., -0.5, 0.),
SGVec3d(0., 0.5, 0.),
SGVec3d(-1., 0.5, 0.));
SGVec3d cp = el->getCollocationPoint();
SG_CHECK_EQUAL_EP(cp[0], -0.75);
SG_CHECK_EQUAL_EP(cp[1], 0.0);
SG_CHECK_EQUAL_EP(cp[2], 0.0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(cp[0], -0.75, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(cp[1], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(cp[2], 0.0, 1e-9);
}
void testBoundVortexMidPoint()
void AeroElementTests::testBoundVortexMidPoint()
{
AeroElement_ptr el = new AeroElement(SGVec3d(-1., -0.5, 0.),
SGVec3d(0., -0.5, 0.),
SGVec3d(0., 0.5, 0.),
SGVec3d(-1., 0.5, 0.));
SGVec3d mp = el->getBoundVortexMidPoint();
SG_CHECK_EQUAL_EP(mp[0], -0.25);
SG_CHECK_EQUAL_EP(mp[1], 0.0);
SG_CHECK_EQUAL_EP(mp[2], 0.0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(mp[0], -0.25, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(mp[1], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(mp[2], 0.0, 1e-9);
}
void testBoundVortex()
void AeroElementTests::testBoundVortex()
{
AeroElement_ptr el = new AeroElement(SGVec3d(-1., -0.5, 0.),
SGVec3d(0., -0.5, 0.),
SGVec3d(0., 0.5, 0.),
SGVec3d(-1., 0.5, 0.));
SGVec3d v = el->getBoundVortex();
SG_CHECK_EQUAL_EP(v[0], 0.0);
SG_CHECK_EQUAL_EP(v[1], 1.0);
SG_CHECK_EQUAL_EP(v[2], 0.0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[0], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[1], 1.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[2], 0.0, 1e-9);
}
void testInducedVelocityOnBoundVortex()
void AeroElementTests::testInducedVelocityOnBoundVortex()
{
AeroElement_ptr el = new AeroElement(SGVec3d(-1., -0.5, 0.),
SGVec3d(0., -0.5, 0.),
@ -61,12 +63,12 @@ void testInducedVelocityOnBoundVortex()
SGVec3d(-1., 0.5, 0.));
SGVec3d mp = el->getBoundVortexMidPoint();
SGVec3d v = el->getInducedVelocity(mp);
SG_CHECK_EQUAL_EP(v[0], 0.0);
SG_CHECK_EQUAL_EP(v[1], 0.0);
SG_CHECK_EQUAL_EP(v[2], 1.0/M_PI);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[0], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[1], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[2], 1.0/M_PI, 1e-9);
}
void testInducedVelocityOnCollocationPoint()
void AeroElementTests::testInducedVelocityOnCollocationPoint()
{
AeroElement_ptr el = new AeroElement(SGVec3d(-1., -0.5, 0.),
SGVec3d(0., -0.5, 0.),
@ -74,12 +76,12 @@ void testInducedVelocityOnCollocationPoint()
SGVec3d(-1., 0.5, 0.));
SGVec3d cp = el->getCollocationPoint();
SGVec3d v = el->getInducedVelocity(cp);
SG_CHECK_EQUAL_EP(v[0], 0.0);
SG_CHECK_EQUAL_EP(v[1], 0.0);
SG_CHECK_EQUAL_EP(v[2], (1.0+sqrt(2.0)/M_PI));
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[0], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[1], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[2], (1.0+sqrt(2.0)/M_PI), 1e-9);
}
void testInducedVelocityAtFarField()
void AeroElementTests::testInducedVelocityAtFarField()
{
AeroElement_ptr el = new AeroElement(SGVec3d(-1., -0.5, 0.),
SGVec3d(0., -0.5, 0.),
@ -87,12 +89,12 @@ void testInducedVelocityAtFarField()
SGVec3d(-1., 0.5, 0.));
SGVec3d mp = el->getBoundVortexMidPoint();
SGVec3d v = el->getInducedVelocity(mp+SGVec3d(-1000.,0.,0.));
SG_CHECK_EQUAL_EP(v[0], 0.0);
SG_CHECK_EQUAL_EP(v[1], 0.0);
SG_CHECK_EQUAL_EP(v[2], 2.0/M_PI);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[0], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[1], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[2], 2.0/M_PI, 1e-7);
}
void testInducedVelocityAbove()
void AeroElementTests::testInducedVelocityAbove()
{
AeroElement_ptr el = new AeroElement(SGVec3d(-1., -0.5, 0.),
SGVec3d(0., -0.5, 0.),
@ -100,12 +102,12 @@ void testInducedVelocityAbove()
SGVec3d(-1., 0.5, 0.));
SGVec3d mp = el->getBoundVortexMidPoint();
SGVec3d v = el->getInducedVelocity(mp+SGVec3d(0.,0.,-0.5));
SG_CHECK_EQUAL_EP(v[0], -1.0/(sqrt(2.0)*M_PI));
SG_CHECK_EQUAL_EP(v[1], 0.0);
SG_CHECK_EQUAL_EP(v[2], 0.5/M_PI);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[0], -1.0/(sqrt(2.0)*M_PI), 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[1], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[2], 0.5/M_PI, 1e-9);
}
void testInducedVelocityAboveWithOffset()
void AeroElementTests::testInducedVelocityAboveWithOffset()
{
AeroElement_ptr el = new AeroElement(SGVec3d(-1., -0.5, 0.),
SGVec3d(0., -0.5, 0.),
@ -113,12 +115,12 @@ void testInducedVelocityAboveWithOffset()
SGVec3d(-1., 0.5, 0.));
SGVec3d mp = el->getBoundVortexMidPoint();
SGVec3d v = el->getInducedVelocity(mp+SGVec3d(0.0, 0.5, -1.0));
SG_CHECK_EQUAL_EP(v[0], -1.0/(4.0*M_PI*sqrt(2.0)));
SG_CHECK_EQUAL_EP(v[1], -0.125/M_PI);
SG_CHECK_EQUAL_EP(v[2], 0.125/M_PI);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[0], -1.0/(4.0*M_PI*sqrt(2.0)), 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[1], -0.125/M_PI, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[2], 0.125/M_PI, 1e-9);
}
void testInducedVelocityUpstream()
void AeroElementTests::testInducedVelocityUpstream()
{
AeroElement_ptr el = new AeroElement(SGVec3d(-1., -0.5, 0.),
SGVec3d(0., -0.5, 0.),
@ -126,20 +128,7 @@ void testInducedVelocityUpstream()
SGVec3d(-1., 0.5, 0.));
SGVec3d mp = el->getBoundVortexMidPoint();
SGVec3d v = el->getInducedVelocity(mp+SGVec3d(0.5, 0.0, 0.0));
SG_CHECK_EQUAL_EP(v[0], 0.0);
SG_CHECK_EQUAL_EP(v[1], 0.0);
SG_CHECK_EQUAL_EP(v[2], (1.0-sqrt(2.0))/M_PI);
}
int main(int argc, char* argv[])
{
testNormal();
testCollocationPoint();
testBoundVortexMidPoint();
testBoundVortex();
testInducedVelocityOnBoundVortex();
testInducedVelocityAtFarField();
testInducedVelocityAbove();
testInducedVelocityAboveWithOffset();
testInducedVelocityUpstream();
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[0], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[1], 0.0, 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(v[2], (1.0-sqrt(2.0))/M_PI, 1e-9);
}

View file

@ -0,0 +1,66 @@
/*
* 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_AERO_ELEMENT_UNIT_TESTS_HXX
#define _FG_AERO_ELEMENT_UNIT_TESTS_HXX
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
// The unit tests.
class AeroElementTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(AeroElementTests);
CPPUNIT_TEST(testBoundVortex);
CPPUNIT_TEST(testBoundVortexMidPoint);
CPPUNIT_TEST(testCollocationPoint);
CPPUNIT_TEST(testInducedVelocityAbove);
CPPUNIT_TEST(testInducedVelocityAboveWithOffset);
CPPUNIT_TEST(testInducedVelocityAtFarField);
CPPUNIT_TEST(testInducedVelocityOnBoundVortex);
//CPPUNIT_TEST(testInducedVelocityOnCollocationPoint); // Not run in the original ctest.
CPPUNIT_TEST(testInducedVelocityUpstream);
CPPUNIT_TEST(testNormal);
CPPUNIT_TEST_SUITE_END();
public:
// Set up function for each test.
void setUp() {}
// Clean up after each test.
void tearDown() {}
// The tests.
void testBoundVortex();
void testBoundVortexMidPoint();
void testCollocationPoint();
void testInducedVelocityAbove();
void testInducedVelocityAboveWithOffset();
void testInducedVelocityAtFarField();
void testInducedVelocityOnBoundVortex();
void testInducedVelocityOnCollocationPoint();
void testInducedVelocityUpstream();
void testNormal();
};
#endif // _FG_AERO_ELEMENT_UNIT_TESTS_HXX

View file

@ -116,10 +116,6 @@ macro(flightgear_test name sources)
add_test(${name} ${EXECUTABLE_OUTPUT_PATH}/${name})
endmacro()
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)
add_executable(testAeroMesh testAeroMesh.cxx
${CMAKE_SOURCE_DIR}/src/FDM/AIWake/AeroElement.cxx
${CMAKE_SOURCE_DIR}/src/FDM/AIWake/AircraftMesh.cxx