test(tests): added test suite

The test suite is extensive. Note that LLMs were used to aid in the development of the test suite. All LLM generated code was manually reviewed.
This commit is contained in:
2026-11-09 13:53:17 -05:00
parent 74e55a6859
commit cb20faeb3d
202 changed files with 35505 additions and 953 deletions

View File

@@ -0,0 +1,33 @@
#include <cmath>
#include <limits>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "serif/eos/evaluation.hpp"
#include "serif/eos/exceptions.hpp"
#include "serif/eos/models/polytropic.hpp"
namespace eos = serif::eos;
namespace dimensions = serif::dimensions;
TEST_CASE("Polytropic pressure potential obeys its mechanical derivative contract", "[eos][barotropic_density][unit]") {
for (const double index : {1.0, 1.5, 2.0, 2.5, 3.0}) {
const eos::models::Polytrope model{index, 0.73};
for (const double density : {1.0e-6, 0.2, 2.0}) {
CAPTURE(index, density);
const dimensions::DensityValue state{density};
const double potential = eos::evaluate<dimensions::BarotropicPressurePotential>(model, state).value();
CHECK_THAT(potential, Catch::Matchers::WithinRel((index + 1.0) * 0.73 * std::pow(density, 1.0 / index), 2.0e-15));
const double step = density * 1.0e-4;
const double positive = eos::evaluate<dimensions::BarotropicPressurePotential>(model, dimensions::DensityValue{density + step}).value();
const double negative = eos::evaluate<dimensions::BarotropicPressurePotential>(model, dimensions::DensityValue{density - step}).value();
const double expected_slope = eos::partial_derivative<dimensions::Pressure, dimensions::MassDensity>(model, state).value() / density;
CHECK_THAT((positive - negative) / (2.0 * step), Catch::Matchers::WithinRel(expected_slope, 3.0e-9));
}
CHECK(eos::evaluate<dimensions::BarotropicPressurePotential>(model, dimensions::DensityValue{0.0}).value() == 0.0);
for (const double invalid : {-0.1, std::numeric_limits<double>::infinity(), std::numeric_limits<double>::quiet_NaN()}) {
CHECK_THROWS_AS(eos::evaluate<dimensions::BarotropicPressurePotential>(model, dimensions::DensityValue{invalid}), eos::EOSEvaluationError);
}
}
}