added googletest and a USStandardAtmosphereTest
This commit is contained in:
parent
d307bf47c6
commit
c7b453d253
@ -5,6 +5,15 @@ project(qtrocket VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
# Google Test framework
|
||||
FetchContent_Declare(googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest
|
||||
GIT_TAG v1.13.0)
|
||||
if(WIN32)
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
|
||||
# fmtlib dependency
|
||||
FetchContent_Declare(fmt
|
||||
GIT_REPOSITORY https://github.com/fmtlib/fmt
|
||||
|
@ -22,3 +22,5 @@ add_library(sim
|
||||
target_link_libraries(sim PRIVATE
|
||||
utils)
|
||||
|
||||
# Unit tests
|
||||
add_subdirectory(tests)
|
||||
|
@ -10,6 +10,7 @@
|
||||
// qtrocket headers
|
||||
#include "sim/USStandardAtmosphere.h"
|
||||
#include "utils/math/Constants.h"
|
||||
#include "utils/math/UtilityMathFunctions.h"
|
||||
|
||||
using namespace utils::math;
|
||||
|
||||
@ -35,13 +36,13 @@ utils::BinMap initTemps()
|
||||
utils::BinMap initLapseRates()
|
||||
{
|
||||
utils::BinMap map;
|
||||
map.insert(std::make_pair(0.0, 0.0065));
|
||||
map.insert(std::make_pair(0.0, -0.0065));
|
||||
map.insert(std::make_pair(11000.0, 0.0));
|
||||
map.insert(std::make_pair(20000.0, -0.001));
|
||||
map.insert(std::make_pair(32000.0, -0.0028));
|
||||
map.insert(std::make_pair(20000.0, 0.001));
|
||||
map.insert(std::make_pair(32000.0, 0.0028));
|
||||
map.insert(std::make_pair(47000.0, 0.0));
|
||||
map.insert(std::make_pair(51000.0, 0.0028));
|
||||
map.insert(std::make_pair(71000.0, 0.002));
|
||||
map.insert(std::make_pair(51000.0, -0.0028));
|
||||
map.insert(std::make_pair(71000.0, -0.002));
|
||||
|
||||
return map;
|
||||
}
|
||||
@ -78,7 +79,7 @@ USStandardAtmosphere::~USStandardAtmosphere()
|
||||
|
||||
double USStandardAtmosphere::getDensity(double altitude)
|
||||
{
|
||||
if(temperatureLapseRate[altitude] == 0.0)
|
||||
if(utils::math::floatingPointEqual(temperatureLapseRate[altitude], 0.0))
|
||||
{
|
||||
return standardDensity[altitude] * std::exp((-Constants::g0 * Constants::airMolarMass * (altitude - standardDensity.getBinBase(altitude)))
|
||||
/ (Constants::Rstar * standardTemperature[altitude]));
|
||||
@ -86,11 +87,10 @@ double USStandardAtmosphere::getDensity(double altitude)
|
||||
}
|
||||
else
|
||||
{
|
||||
double base = standardTemperature[altitude] /
|
||||
(standardTemperature[altitude] + temperatureLapseRate[altitude] * (altitude - standardDensity.getBinBase(altitude)));
|
||||
double base = (standardTemperature[altitude] - temperatureLapseRate[altitude] * (altitude - standardDensity.getBinBase(altitude))) / standardTemperature[altitude];
|
||||
|
||||
double exponent = 1 + (Constants::g0 * Constants::airMolarMass) /
|
||||
(Constants::Rstar * temperatureLapseRate[altitude]);
|
||||
double exponent = (Constants::g0 * Constants::airMolarMass) /
|
||||
(Constants::Rstar * temperatureLapseRate[altitude]) - 1.0;
|
||||
|
||||
return standardDensity[altitude] * std::pow(base, exponent);
|
||||
|
||||
|
14
sim/tests/CMakeLists.txt
Normal file
14
sim/tests/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
enable_testing()
|
||||
|
||||
add_executable(sim_tests
|
||||
USStandardAtmosphereTests.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(sim_tests
|
||||
sim
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(sim_tests)
|
||||
|
29
sim/tests/USStandardAtmosphereTests.cpp
Normal file
29
sim/tests/USStandardAtmosphereTests.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "sim/USStandardAtmosphere.h"
|
||||
|
||||
TEST(USStandardAtmosphereTests, DensityTests)
|
||||
{
|
||||
sim::USStandardAtmosphere atmosphere;
|
||||
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(0.0), 1.225);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(1000.0), 1.112);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(2000.0), 1.007);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(3000.0), 0.9093);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(4000.0), 0.8194);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(5000.0), 0.7364);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(6000.0), 0.6601);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(7000.0), 0.5900);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(8000.0), 0.5258);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(9000.0), 0.4647);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(10000.0), 0.4135);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(15000.0), 0.1948);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(20000.0), 0.08891);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(25000.0), 0.04008);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(30000.0), 0.01841);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(40000.0), 0.003996);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(50000.0), 0.001027);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(60000.0), 0.0003097);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(70000.0), 0.00008283);
|
||||
EXPECT_DOUBLE_EQ(atmosphere.getDensity(80000.0), 0.00001846);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user