#include #include "const.h" #include #include #include #include std::string RELATIVE_PATH = "../src/resources/const/const.dat"; /** * @file constTest.cpp * @brief Unit tests for the const class. */ /** * @brief Test suite for the const class. */ class constTest : public ::testing::Test { protected: constants physicalConstants; constants initializedConstants; void SetUp() override { // Create a DObject with initial data and metadata constants initializedConstants(RELATIVE_PATH); std::cout << "speed of light (tests) " << initializedConstants["c"].value << std::endl; } }; /** * @test Verify default constructor initializes correctly. */ TEST_F(constTest, DefaultConstructor) { EXPECT_NO_THROW(constants()); } /** * @test Verify constructor initializes with provided data and metadata. */ TEST_F(constTest, ParameterizedConstructor) { constants obj(RELATIVE_PATH); EXPECT_NO_THROW(obj.is_loaded()); } /** * @test Verify get method returns the correct constant. */ TEST_F(constTest, Get) { constants obj(RELATIVE_PATH); EXPECT_DOUBLE_EQ(obj.get("c").value, 2.99792458e10); EXPECT_EQ(obj.get("c").unit, "cm / s"); EXPECT_DOUBLE_EQ(obj.get("c").uncertainty, 0.0); EXPECT_EQ(obj.get("c").reference, "CODATA2022"); } /** * @test Verify [] opperators returns the correct constant. */ TEST_F(constTest, Sub) { constants obj(RELATIVE_PATH); EXPECT_DOUBLE_EQ(obj["c"].value, 2.99792458e10); EXPECT_EQ(obj["c"].unit, "cm / s"); EXPECT_DOUBLE_EQ(obj["c"].uncertainty, 0.0); EXPECT_EQ(obj["c"].reference, "CODATA2022"); } /** * @test Verify that the has method returns the correct values */ TEST_F(constTest, Has) { constants obj(RELATIVE_PATH); EXPECT_TRUE(obj.has("c")); EXPECT_FALSE(obj.has("c4")); EXPECT_TRUE(obj.has("hbar")); } TEST_F(constTest, Keys) { constants obj(RELATIVE_PATH); std::set checkKeys; checkKeys.insert("c"); checkKeys.insert("wienK"); checkKeys.insert("hbar"); checkKeys.insert("g_h"); checkKeys.insert("R_sun"); std::set keys = obj.keys(); for (const auto& key : checkKeys) { bool found = keys.find(key) != keys.end(); std::cout << "FOUND SIMILAR KEY " << key << ", found: " << found << std::endl; EXPECT_TRUE(found); } std::set checkBadKeys; checkBadKeys.insert("c4"); checkBadKeys.insert("wienK4"); checkBadKeys.insert("hbar4"); checkBadKeys.insert("g_h4"); checkBadKeys.insert("R_sun4"); for (const auto& key : checkBadKeys) { bool found = keys.find(key) != keys.end(); std::cout << "FOUND BAD KEY " << key << ", found: " << found << std::endl; EXPECT_FALSE(found); } }