TestSuite: Shifted the YASim atmosphere test into the CppUnit framework.
This commit is contained in:
parent
ba5b472705
commit
dbe7c90115
11 changed files with 138 additions and 43 deletions
|
@ -202,28 +202,4 @@ int Atmosphere::maxTableIndex() {
|
|||
return (sizeof(data) / (numColumns * sizeof(float))) - 1;
|
||||
}
|
||||
|
||||
bool Atmosphere::test() {
|
||||
bool passed = true;
|
||||
int rows = maxTableIndex() + 1;
|
||||
const float maxDeviation = 0.0002f;
|
||||
|
||||
fprintf(stderr, "Atmosphere::test()\n");
|
||||
fprintf(stderr, "Columns = %d\n", numColumns);
|
||||
fprintf(stderr, "Rows = %d\n", rows);
|
||||
|
||||
for (int alt = 0; alt <= maxTableIndex(); alt++) {
|
||||
float density = calcStdDensity(data[alt][PRESSURE], data[alt][TEMPERATURE]);
|
||||
float delta = data[alt][DENSITY] - density;
|
||||
fprintf(stderr, "%d : %f \n", alt, delta);
|
||||
if (Math::abs(delta) > maxDeviation) {
|
||||
passed = false;
|
||||
fprintf(stderr,"FAIL: Deviation above limit of %1.6f\n", maxDeviation);
|
||||
}
|
||||
}
|
||||
if (passed) {
|
||||
fprintf(stderr,"Deviation below %1.6f for all rows.\n", maxDeviation);
|
||||
}
|
||||
return passed;
|
||||
}
|
||||
|
||||
}; // namespace yasim
|
||||
|
|
|
@ -1,19 +1,24 @@
|
|||
#ifndef _ATMOSPHERE_HPP
|
||||
#define _ATMOSPHERE_HPP
|
||||
|
||||
namespace FGTestApi { namespace PrivateAccessor { namespace FDM { class Accessor; } } }
|
||||
|
||||
namespace yasim {
|
||||
|
||||
//constexpr int Atmosphere::numColumns {4};
|
||||
|
||||
class Atmosphere {
|
||||
friend class ::FGTestApi::PrivateAccessor::FDM::Accessor;
|
||||
|
||||
static const int numColumns {4};
|
||||
|
||||
public:
|
||||
enum Column {
|
||||
ALTITUDE,
|
||||
TEMPERATURE,
|
||||
PRESSURE,
|
||||
DENSITY
|
||||
};
|
||||
static const int numColumns {4};
|
||||
public:
|
||||
void setTemperature(float t) { _temperature = t; }
|
||||
void setPressure(float p) { _pressure = p; }
|
||||
void setDensity(float d) { _density = d; }
|
||||
|
@ -46,13 +51,13 @@ public:
|
|||
static void calcStaticAir(float p0, float t0, float d0, float v,
|
||||
float* pOut, float* tOut, float* dOut);
|
||||
void calcStaticAir(float v, float* pOut, float* tOut, float* dOut);
|
||||
static bool test();
|
||||
|
||||
|
||||
static int maxTableIndex();
|
||||
|
||||
private:
|
||||
static float getRecord(float alt, Atmosphere::Column recNum);
|
||||
static float data[][numColumns];
|
||||
static int maxTableIndex();
|
||||
|
||||
|
||||
float _temperature = 288.11f;
|
||||
float _pressure = 101325.0f;
|
||||
float _density = 1.22500f;
|
||||
|
|
|
@ -39,7 +39,6 @@ flightgear_component(YASim "${SOURCES}")
|
|||
|
||||
add_executable(yasim yasim-test.cpp ${COMMON})
|
||||
add_executable(yasim-proptest proptest.cpp ${COMMON})
|
||||
add_executable(yasim-atmotest yasim-atmotest.cpp Atmosphere.cpp )
|
||||
|
||||
target_link_libraries(yasim SimGearCore)
|
||||
target_link_libraries(yasim-proptest SimGearCore)
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
#include "Atmosphere.hpp"
|
||||
|
||||
using namespace yasim;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Atmosphere a;
|
||||
if (a.test()) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
|
@ -76,6 +76,7 @@ add_test(MktimeUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u Mktim
|
|||
add_test(NasalSysUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u NasalSysTests)
|
||||
add_test(NavaidsUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u NavaidsTests)
|
||||
add_test(PosInitUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u PosInitTests)
|
||||
add_test(YASimAtmosphereUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u YASimAtmosphereTests)
|
||||
|
||||
# GUI test suites.
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <FDM/AIWake/AIWakeGroup.hxx>
|
||||
#include <FDM/AIWake/AircraftMesh.hxx>
|
||||
#include <FDM/AIWake/WakeMesh.hxx>
|
||||
#include <FDM/YASim/Atmosphere.hpp>
|
||||
|
||||
|
||||
|
||||
// Access variables from src/FDM/AIWake/AIWakeGroup.hxx.
|
||||
|
@ -45,3 +47,17 @@ FGTestApi::PrivateAccessor::FDM::Accessor::read_FDM_AIWake_WakeMesh_Gamma(WakeMe
|
|||
{
|
||||
return instance->Gamma;
|
||||
}
|
||||
|
||||
|
||||
// Access variables from src/FDM/YASim/Atmosphere.hxx.
|
||||
float
|
||||
FGTestApi::PrivateAccessor::FDM::Accessor::read_FDM_YASim_Atmosphere_numColumns(std::unique_ptr<yasim::Atmosphere> &instance) const
|
||||
{
|
||||
return instance->numColumns;
|
||||
}
|
||||
|
||||
float
|
||||
FGTestApi::PrivateAccessor::FDM::Accessor::read_FDM_YASim_Atmosphere_data(std::unique_ptr<yasim::Atmosphere> &instance, int i, int j) const
|
||||
{
|
||||
return instance->data[i][j];
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define _FG_PRIVATE_ACCESSOR_FDM_HXX
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
|
@ -15,6 +16,11 @@ class WakeMesh;
|
|||
class AeroElement;
|
||||
typedef SGSharedPtr<AeroElement> AeroElement_ptr;
|
||||
|
||||
// Forward declaration for: src/FDM/YASim.
|
||||
namespace yasim {
|
||||
class Atmosphere;
|
||||
}
|
||||
|
||||
|
||||
namespace FGTestApi {
|
||||
namespace PrivateAccessor {
|
||||
|
@ -34,6 +40,10 @@ public:
|
|||
const std::vector<AeroElement_ptr> read_FDM_AIWake_WakeMesh_elements(WakeMesh* instance) const;
|
||||
int read_FDM_AIWake_WakeMesh_nelm(WakeMesh* instance) const;
|
||||
double **read_FDM_AIWake_WakeMesh_Gamma(WakeMesh* instance) const;
|
||||
|
||||
// Access variables from src/FDM/YASim/Atmosphere.hxx.
|
||||
float read_FDM_YASim_Atmosphere_numColumns(std::unique_ptr<yasim::Atmosphere> &instance) const;
|
||||
float read_FDM_YASim_Atmosphere_data(std::unique_ptr<yasim::Atmosphere> &instance, int i, int j) const;
|
||||
};
|
||||
|
||||
} // End of namespace FDM.
|
||||
|
|
|
@ -3,6 +3,7 @@ set(TESTSUITE_SOURCES
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_ls_matrix.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/testAeroElement.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/testYASimAtmosphere.cxx
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
|
@ -10,5 +11,6 @@ set(TESTSUITE_HEADERS
|
|||
${TESTSUITE_HEADERS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_ls_matrix.hxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/testAeroElement.hxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/testYASimAtmosphere.hxx
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
|
|
@ -19,8 +19,10 @@
|
|||
|
||||
#include "test_ls_matrix.hxx"
|
||||
#include "testAeroElement.hxx"
|
||||
#include "testYASimAtmosphere.hxx"
|
||||
|
||||
|
||||
// Set up the unit tests.
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AeroElementTests, "Unit tests");
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(LaRCSimMatrixTests, "Unit tests");
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(YASimAtmosphereTests, "Unit tests");
|
||||
|
|
44
test_suite/unit_tests/FDM/testYASimAtmosphere.cxx
Normal file
44
test_suite/unit_tests/FDM/testYASimAtmosphere.cxx
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include "test_suite/FGTestApi/PrivateAccessorFDM.hxx"
|
||||
|
||||
#include "testYASimAtmosphere.hxx"
|
||||
|
||||
#include <FDM/YASim/Math.hpp>
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
||||
|
||||
using namespace yasim;
|
||||
|
||||
void YASimAtmosphereTests::setUp()
|
||||
{
|
||||
a.reset(new Atmosphere());
|
||||
}
|
||||
|
||||
|
||||
void YASimAtmosphereTests::tearDown()
|
||||
{
|
||||
a.reset();
|
||||
}
|
||||
|
||||
|
||||
void YASimAtmosphereTests::testAtmosphere()
|
||||
{
|
||||
auto accessor = FGTestApi::PrivateAccessor::FDM::Accessor();
|
||||
|
||||
int numColumns = accessor.read_FDM_YASim_Atmosphere_numColumns(a);
|
||||
int maxTableIndex = a->maxTableIndex();
|
||||
int rows = maxTableIndex + 1;
|
||||
const float maxDeviation = 0.0002f;
|
||||
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "Columns = " << numColumns);
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "Rows = " << rows);
|
||||
|
||||
for (int alt = 0; alt <= maxTableIndex; alt++) {
|
||||
float density = a->calcStdDensity(accessor.read_FDM_YASim_Atmosphere_data(a, alt, a->PRESSURE), accessor.read_FDM_YASim_Atmosphere_data(a, alt, a->TEMPERATURE));
|
||||
float delta = accessor.read_FDM_YASim_Atmosphere_data(a, alt, a->DENSITY) - density;
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "alt: " << alt << ", delta: " << delta);
|
||||
if (Math::abs(delta) > maxDeviation)
|
||||
CPPUNIT_FAIL("Deviation above limit of 0.0002");
|
||||
}
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "Deviation below " << maxDeviation << " for all rows.");
|
||||
}
|
52
test_suite/unit_tests/FDM/testYASimAtmosphere.hxx
Normal file
52
test_suite/unit_tests/FDM/testYASimAtmosphere.hxx
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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_YASIM_ATMOSPHERE_UNIT_TESTS_HXX
|
||||
#define _FG_YASIM_ATMOSPHERE_UNIT_TESTS_HXX
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestFixture.h>
|
||||
|
||||
#include <src/FDM/YASim/Atmosphere.hpp>
|
||||
|
||||
|
||||
// The unit tests.
|
||||
class YASimAtmosphereTests : public CppUnit::TestFixture
|
||||
{
|
||||
// Set up the test suite.
|
||||
CPPUNIT_TEST_SUITE(YASimAtmosphereTests);
|
||||
CPPUNIT_TEST(testAtmosphere);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
// Set up function for each test.
|
||||
void setUp();
|
||||
|
||||
// Clean up after each test.
|
||||
void tearDown();
|
||||
|
||||
// The tests.
|
||||
void testAtmosphere();
|
||||
|
||||
// Data.
|
||||
std::unique_ptr<yasim::Atmosphere> a;
|
||||
};
|
||||
|
||||
#endif // _FG_YASIM_ATMOSPHERE_UNIT_TESTS_HXX
|
Loading…
Reference in a new issue