diff --git a/src/FDM/AIWake/AeroElement.hxx b/src/FDM/AIWake/AeroElement.hxx index b424639b3..dbdd22a59 100644 --- a/src/FDM/AIWake/AeroElement.hxx +++ b/src/FDM/AIWake/AeroElement.hxx @@ -23,6 +23,9 @@ #ifndef _FG_AEROELEMENT_HXX #define _FG_AEROELEMENT_HXX +#include + + class AeroElement : public SGReferenced { public: AeroElement(const SGVec3d& n1, const SGVec3d& n2, const SGVec3d& n3, diff --git a/test_suite/CMakeLists.txt b/test_suite/CMakeLists.txt index 0b0fbd9a3..7ef78b905 100644 --- a/test_suite/CMakeLists.txt +++ b/test_suite/CMakeLists.txt @@ -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) diff --git a/test_suite/unit_tests/FDM/CMakeLists.txt b/test_suite/unit_tests/FDM/CMakeLists.txt index 38f82303d..2fc3a5d42 100644 --- a/test_suite/unit_tests/FDM/CMakeLists.txt +++ b/test_suite/unit_tests/FDM/CMakeLists.txt @@ -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 ) diff --git a/test_suite/unit_tests/FDM/TestSuite.cxx b/test_suite/unit_tests/FDM/TestSuite.cxx index b628e6dbd..5377f2501 100644 --- a/test_suite/unit_tests/FDM/TestSuite.cxx +++ b/test_suite/unit_tests/FDM/TestSuite.cxx @@ -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"); diff --git a/tests/testAeroElement.cxx b/test_suite/unit_tests/FDM/testAeroElement.cxx similarity index 61% rename from tests/testAeroElement.cxx rename to test_suite/unit_tests/FDM/testAeroElement.cxx index 96597a3cc..c03e4bf1c 100644 --- a/tests/testAeroElement.cxx +++ b/test_suite/unit_tests/FDM/testAeroElement.cxx @@ -1,59 +1,61 @@ #include -#include #include #include #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); } diff --git a/test_suite/unit_tests/FDM/testAeroElement.hxx b/test_suite/unit_tests/FDM/testAeroElement.hxx new file mode 100644 index 000000000..ac293d751 --- /dev/null +++ b/test_suite/unit_tests/FDM/testAeroElement.hxx @@ -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 . + */ + + +#ifndef _FG_AERO_ELEMENT_UNIT_TESTS_HXX +#define _FG_AERO_ELEMENT_UNIT_TESTS_HXX + + +#include +#include + + +// 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 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9f8ef1395..69db72820 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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