test(tests/composition): added composition tests, atomicSpecies tests, and sandbox

This commit is contained in:
2025-03-24 12:59:17 -04:00
parent 7c42201ddb
commit b17cdbf1bf
2 changed files with 55 additions and 5 deletions

View File

@@ -3,8 +3,10 @@
#include <algorithm> #include <algorithm>
#include "atomicSpecies.h" #include "atomicSpecies.h"
#include "composition.h"
#include "config.h"
std::string EXAMPLE_FILENAME = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/composition/example.yaml"; std::string EXAMPLE_FILENAME = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/config/example.yaml";
/** /**
* @brief Test suite for the composition class. * @brief Test suite for the composition class.
@@ -14,8 +16,56 @@ class compositionTest : public ::testing::Test {};
/** /**
* @brief Test the constructor of the composition class. * @brief Test the constructor of the composition class.
*/ */
TEST_F(compositionTest, constructor) { TEST_F(compositionTest, isotopeMasses) {
std::cout << "Testing the constructor of the composition class." << std::endl; EXPECT_NO_THROW(chemSpecies::species.at("H-1"));
std::cout << chemSpecies::species.at("H-1") << std::endl; EXPECT_DOUBLE_EQ(chemSpecies::species.at("H-1").mass(), 1.007825031898);
EXPECT_DOUBLE_EQ(chemSpecies::species.at("He-3").mass(), 3.0160293219700001);
EXPECT_DOUBLE_EQ(chemSpecies::species.at("He-4").mass(),4.0026032541300003);
} }
TEST_F(compositionTest, constructor) {
Config::getInstance().loadConfig(EXAMPLE_FILENAME);
EXPECT_NO_THROW(composition::Composition comp);
}
TEST_F(compositionTest, registerSymbol) {
Config::getInstance().loadConfig(EXAMPLE_FILENAME);
composition::Composition comp;
EXPECT_NO_THROW(comp.registerSymbol("H-1"));
EXPECT_NO_THROW(comp.registerSymbol("He-4"));
EXPECT_THROW(comp.registerSymbol("H-19"), std::runtime_error);
EXPECT_THROW(comp.registerSymbol("He-21"), std::runtime_error);
std::set<std::string> registeredSymbols = comp.getRegisteredSymbols();
EXPECT_TRUE(registeredSymbols.find("H-1") != registeredSymbols.end());
EXPECT_TRUE(registeredSymbols.find("He-4") != registeredSymbols.end());
EXPECT_TRUE(registeredSymbols.find("H-19") == registeredSymbols.end());
EXPECT_TRUE(registeredSymbols.find("He-21") == registeredSymbols.end());
}
TEST_F(compositionTest, setGetComposition) {
Config::getInstance().loadConfig(EXAMPLE_FILENAME);
composition::Composition comp;
comp.registerSymbol("H-1");
comp.registerSymbol("He-4");
EXPECT_DOUBLE_EQ(comp.setComposition("H-1", 0.5), 0.0);
EXPECT_DOUBLE_EQ(comp.setComposition("He-4", 0.5), 0.0);
EXPECT_DOUBLE_EQ(comp.setComposition("H-1", 0.6), 0.5);
EXPECT_DOUBLE_EQ(comp.setComposition("He-4", 0.4), 0.5);
EXPECT_NO_THROW(comp.finalize());
std::unordered_map<std::string, composition::CompositionEntry> compositions = comp.getCompositions();
EXPECT_DOUBLE_EQ(compositions["H-1"].mass_fraction, 0.6);
EXPECT_THROW(comp.setComposition("He-3", 0.3), std::runtime_error);
EXPECT_NO_THROW(comp.setComposition({"H-1", "He-4"}, {0.5, 0.5}));
EXPECT_THROW(comp.getComposition("H-1"), std::runtime_error);
EXPECT_TRUE(comp.finalize());
EXPECT_DOUBLE_EQ(comp.getComposition("H-1").mass_fraction, 0.5);
EXPECT_NO_THROW(comp.setComposition({"H-1", "He-4"}, {0.6, 0.6}));
EXPECT_FALSE(comp.finalize());
EXPECT_THROW(comp.getComposition("H-1"), std::runtime_error);
}

View File

@@ -11,7 +11,7 @@ foreach test_file : test_sources
test_exe = executable( test_exe = executable(
exe_name, exe_name,
test_file, test_file,
dependencies: [gtest_dep, species_weight_dep, gtest_main], dependencies: [gtest_dep, species_weight_dep, gtest_main, composition_dep],
install_rpath: '@loader_path/../../src' # Ensure runtime library path resolves correctly install_rpath: '@loader_path/../../src' # Ensure runtime library path resolves correctly
) )