test(network): added approx8 network tests

This commit is contained in:
2025-03-21 14:03:46 -04:00
parent 3c0057ea34
commit 2b4830f74d
2 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
#include <gtest/gtest.h>
#include <string>
#include "approx8.h"
#include "config.h"
#include "network.h"
#include <vector>
std::string TEST_CONFIG = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/testsConfig.yaml";
class approx8Test : public ::testing::Test {};
/**
* @brief Test the constructor of the Config class.
*/
TEST_F(approx8Test, constructor) {
Config& config = Config::getInstance();
config.loadConfig(TEST_CONFIG);
EXPECT_NO_THROW(nnApprox8::Approx8Network());
}
TEST_F(approx8Test, setStiff) {
nnApprox8::Approx8Network network;
EXPECT_NO_THROW(network.setStiff(true));
EXPECT_TRUE(network.isStiff());
EXPECT_NO_THROW(network.setStiff(false));
EXPECT_FALSE(network.isStiff());
}
TEST_F(approx8Test, evaluate) {
nnApprox8::Approx8Network network;
nuclearNetwork::NetIn netIn;
std::vector<double> comp = {0.708, 2.94e-5, 0.276, 0.003, 0.0011, 9.62e-3, 1.62e-3, 5.16e-4};
netIn.composition = comp;
netIn.temperature = 1e7;
netIn.density = 1e2;
netIn.energy = 0.0;
netIn.tmax = 3.15e17;
netIn.dt0 = 1e12;
nuclearNetwork::NetOut netOut;
EXPECT_NO_THROW(netOut = network.evaluate(netIn));
EXPECT_DOUBLE_EQ(netOut.composition[nnApprox8::Net::ih1], 0.50166260916650918);
EXPECT_DOUBLE_EQ(netOut.composition[nnApprox8::Net::ihe4],0.48172270591286032);
EXPECT_DOUBLE_EQ(netOut.energy, -1.6433049870528356e+18);
}

25
tests/network/meson.build Normal file
View File

@@ -0,0 +1,25 @@
# Test files for network
test_sources = [
'approx8Test.cpp',
]
foreach test_file : test_sources
exe_name = test_file.split('.')[0]
message('Building test: ' + exe_name)
# Create an executable target for each test
test_exe = executable(
exe_name,
test_file,
dependencies: [gtest_dep, network_dep, gtest_main],
include_directories: include_directories('../../src/network/public'),
link_with: libnetwork, # Link the dobj library
install_rpath: '@loader_path/../../src' # Ensure runtime library path resolves correctly
)
# Add the executable as a test
test(
exe_name,
test_exe,
env: ['MESON_SOURCE_ROOT=' + meson.project_source_root(), 'MESON_BUILD_ROOT=' + meson.project_build_root()])
endforeach