SERiF 0.0.1a
3+1D Stellar Structure and Evolution
Loading...
Searching...
No Matches
constTest.cpp
Go to the documentation of this file.
1#include <gtest/gtest.h>
2#include "const.h"
3#include <iostream>
4#include <string>
5#include <vector>
6#include <set>
7#include <sstream>
8
13
17class constTest : public ::testing::Test {
18protected:
19 void SetUp() override {
21 }
22};
23
27TEST_F(constTest, DefaultConstructor) {
29}
30
34TEST_F(constTest, isLoaded) {
35
36 EXPECT_NO_THROW(serif::constant::Constants::getInstance().isLoaded());
37}
38
42TEST_F(constTest, GetMethod) {
44 EXPECT_DOUBLE_EQ(obj.get("c").value, 2.99792458e10);
45 EXPECT_EQ(obj.get("c").unit, "cm / s");
46 EXPECT_DOUBLE_EQ(obj.get("c").uncertainty, 0.0);
47 EXPECT_EQ(obj.get("c").reference, "CODATA2022");
48}
49
53TEST_F(constTest, SubscriptOperator) {
55 EXPECT_DOUBLE_EQ(obj["c"].value, 2.99792458e10);
56 EXPECT_EQ(obj["c"].unit, "cm / s");
57 EXPECT_DOUBLE_EQ(obj["c"].uncertainty, 0.0);
58 EXPECT_EQ(obj["c"].reference, "CODATA2022");
59}
60
64TEST_F(constTest, HasMethod) {
66
67 EXPECT_TRUE(obj.has("c"));
68 EXPECT_FALSE(obj.has("c4"));
69 EXPECT_TRUE(obj.has("hbar"));
70}
71
72TEST_F(constTest, KeysMethod) {
74 std::set<std::string> checkKeys;
75 checkKeys.insert("c");
76 checkKeys.insert("wienK");
77 checkKeys.insert("hbar");
78 checkKeys.insert("g_h");
79 checkKeys.insert("R_sun");
80
81 std::set<std::string> keys = obj.keys();
82
83 for (const auto& key : checkKeys) {
84 bool found = keys.find(key) != keys.end();
85 EXPECT_TRUE(found);
86 }
87
88 std::set<std::string> checkBadKeys;
89 checkBadKeys.insert("c4");
90 checkBadKeys.insert("wienK4");
91 checkBadKeys.insert("hbar4");
92 checkBadKeys.insert("g_h4");
93 checkBadKeys.insert("R_sun4");
94
95 for (const auto& key : checkBadKeys) {
96 bool found = keys.find(key) != keys.end();
97 EXPECT_FALSE(found);
98 }
99}
100
101TEST_F(constTest, StreamOperator) {
103 std::ostringstream os;
104
105 os << obj.get("c");
106 std::string expected = "<speed of light in vacuum: 2.99792e+10±0 cm / s (CODATA2022)>\n";
107
108 EXPECT_EQ(os.str(), expected);
109}
Test suite for the const class.
Definition constTest.cpp:17
void SetUp() override
Definition constTest.cpp:19
Class to manage a collection of constants.
Definition const.h:63
bool has(const std::string &key) const
Check if a constant exists by key.
Definition const.cpp:55
std::set< std::string > keys() const
Get a list of all constant keys.
Definition const.cpp:59
static Constants & getInstance()
get instance of constants singleton
Definition const.h:99
Constant get(const std::string &key) const
Get a constant by key.
Definition const.cpp:42
TEST_F(constTest, DefaultConstructor)
Definition constTest.cpp:27
const std::string unit
Unit of the constant.
Definition const.h:35
const double uncertainty
Uncertainty in the constant's value.
Definition const.h:34
const std::string reference
Reference for the constant's value.
Definition const.h:36
const double value
Value of the constant.
Definition const.h:33