perf(const): const changed to a singelton
const needds to be accessed all throughout so it has been changed to a singleton to allow for more efficient usage BREAKING CHANGE: Any previous loads to const will break, also constant->Constant and constants->Constants
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
std::string RELATIVE_PATH = "../src/resources/const/const.dat";
|
||||
/**
|
||||
* @file constTest.cpp
|
||||
* @brief Unit tests for the const class.
|
||||
@@ -17,12 +16,8 @@ std::string RELATIVE_PATH = "../src/resources/const/const.dat";
|
||||
*/
|
||||
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);
|
||||
Constants::getInstance();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -30,23 +25,22 @@ protected:
|
||||
* @test Verify default constructor initializes correctly.
|
||||
*/
|
||||
TEST_F(constTest, DefaultConstructor) {
|
||||
EXPECT_NO_THROW(constants());
|
||||
EXPECT_NO_THROW(Constants::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test Verify constructor initializes with provided data and metadata.
|
||||
*/
|
||||
TEST_F(constTest, ParameterizedConstructor) {
|
||||
constants obj(RELATIVE_PATH);
|
||||
TEST_F(constTest, isLoaded) {
|
||||
|
||||
EXPECT_NO_THROW(obj.is_loaded());
|
||||
EXPECT_NO_THROW(Constants::getInstance().isLoaded());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test Verify get method returns the correct constant.
|
||||
*/
|
||||
TEST_F(constTest, Get) {
|
||||
constants obj(RELATIVE_PATH);
|
||||
TEST_F(constTest, GetMethod) {
|
||||
Constants& obj = Constants::getInstance();
|
||||
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);
|
||||
@@ -56,8 +50,8 @@ TEST_F(constTest, Get) {
|
||||
/**
|
||||
* @test Verify [] opperators returns the correct constant.
|
||||
*/
|
||||
TEST_F(constTest, Sub) {
|
||||
constants obj(RELATIVE_PATH);
|
||||
TEST_F(constTest, SubscriptOperator) {
|
||||
Constants& obj = Constants::getInstance();
|
||||
EXPECT_DOUBLE_EQ(obj["c"].value, 2.99792458e10);
|
||||
EXPECT_EQ(obj["c"].unit, "cm / s");
|
||||
EXPECT_DOUBLE_EQ(obj["c"].uncertainty, 0.0);
|
||||
@@ -67,16 +61,16 @@ TEST_F(constTest, Sub) {
|
||||
/**
|
||||
* @test Verify that the has method returns the correct values
|
||||
*/
|
||||
TEST_F(constTest, Has) {
|
||||
constants obj(RELATIVE_PATH);
|
||||
TEST_F(constTest, HasMethod) {
|
||||
Constants& obj = Constants::getInstance();
|
||||
|
||||
EXPECT_TRUE(obj.has("c"));
|
||||
EXPECT_FALSE(obj.has("c4"));
|
||||
EXPECT_TRUE(obj.has("hbar"));
|
||||
}
|
||||
|
||||
TEST_F(constTest, Keys) {
|
||||
constants obj(RELATIVE_PATH);
|
||||
TEST_F(constTest, KeysMethod) {
|
||||
Constants& obj = Constants::getInstance();
|
||||
std::set<std::string> checkKeys;
|
||||
checkKeys.insert("c");
|
||||
checkKeys.insert("wienK");
|
||||
@@ -104,8 +98,8 @@ TEST_F(constTest, Keys) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(constTest, Output) {
|
||||
constants obj(RELATIVE_PATH);
|
||||
TEST_F(constTest, StreamOperator) {
|
||||
Constants& obj = Constants::getInstance();
|
||||
std::ostringstream os;
|
||||
|
||||
os << obj.get("c");
|
||||
|
||||
Reference in New Issue
Block a user