38GTEST_TEST(testVector3DFunctions, memberTypesForAnExampleVector3DTypeAreCorrect)
41 static_assert((std::is_same_v<DryChem::Vector3D<double>::value_type,
double>),
"value_type is incorrect.");
42 static_assert((std::is_same_v<DryChem::Vector3D<double>::size_type, std::size_t>),
"size_type is incorrect.");
43 static_assert((std::is_same_v<DryChem::Vector3D<double>::difference_type, std::ptrdiff_t>),
"difference_type is incorrect.");
44 static_assert((std::is_same_v<DryChem::Vector3D<double>::reference,
double&>),
"reference is incorrect.");
45 static_assert((std::is_same_v<DryChem::Vector3D<double>::const_reference,
const double&>),
"const_reference is incorrect.");
46 static_assert((std::is_same_v<DryChem::Vector3D<double>::pointer,
double*>),
"pointer is incorrect.");
47 static_assert((std::is_same_v<DryChem::Vector3D<double>::const_pointer,
const double*>),
"const_pointer is incorrect.");
48 static_assert((std::is_same_v<DryChem::Vector3D<double>::iterator, std::array<double, 3>::iterator>),
"iterator is incorrect.");
49 static_assert((std::is_same_v<DryChem::Vector3D<double>::const_iterator, std::array<double, 3>::const_iterator>),
"const_iterator is incorrect.");
50 static_assert((std::is_same_v<DryChem::Vector3D<double>::container_type, std::array<double, 3>>),
"const_iterator is incorrect.");
54GTEST_TEST(testVector3DFunctions, vector3DIsClassifiedLikeAStdArrayAndAContainerAdapter)
56 ASSERT_FALSE((DryChem::is_allocator_aware_container_v<DryChem::Vector3D<int>>));
57 ASSERT_FALSE((DryChem::is_associative_container_v<DryChem::Vector3D<int>>));
58 ASSERT_TRUE((DryChem::is_container_v<DryChem::Vector3D<int>>));
59 ASSERT_TRUE((DryChem::is_container_adapter_v<DryChem::Vector3D<int>>));
60 ASSERT_FALSE((DryChem::is_reversible_container_v<DryChem::Vector3D<int>>));
61 ASSERT_TRUE((DryChem::is_sequence_container_v<DryChem::Vector3D<int>>));
62 ASSERT_FALSE((DryChem::is_unordered_associative_container_v<DryChem::Vector3D<int>>));
65GTEST_TEST(testVector3DFunctions, differentConstructorsInitializeObjectsAsExpected)
67 std::array<int, 3> sampleArray {1, 2, 3};
69 DryChem::Vector3D<long double> defaultInitialized {};
70 DryChem::Vector3D<int> arrayInitialized {sampleArray};
71 DryChem::Vector3D<float> valuesInitialized {1.0f, 3.0f, 5.0f};
73 for (std::size_t i {}; i < 3; ++i)
75 ASSERT_EQ(0.0, defaultInitialized[i]);
76 ASSERT_EQ(sampleArray[i], arrayInitialized[i]);
77 ASSERT_EQ(2 * sampleArray[i] - 1, valuesInitialized[i]);
81GTEST_TEST(testVector3DFunctions, overloadedComparsionOperatorsPerformElementwiseComparisons)
83 std::array<int, 3> valueArray {1, 2, 3};
85 DryChem::Vector3D<int> value1 {1, 2, 3};
86 DryChem::Vector3D<int> value2 {};
87 DryChem::Vector3D<int> value3 {valueArray};
88 DryChem::Vector3D<int> value4 {1, 0, 3};
90 ASSERT_TRUE(value1 == value3);
91 ASSERT_FALSE(value1 == value2);
93 ASSERT_TRUE(value2 < value1);
94 ASSERT_FALSE(value1 < value2);
96 ASSERT_TRUE(value3 != value2);
97 ASSERT_FALSE(value3 != value1);
99 ASSERT_TRUE(value1 <= value3);
100 ASSERT_FALSE(value3 <= value4);
102 ASSERT_TRUE(value1 > value4);
103 ASSERT_FALSE(value2 > value4);
105 ASSERT_TRUE(value3 >= value2);
106 ASSERT_FALSE(value2 >= value4);
109GTEST_TEST(testVector3DFunctions, atFunctionOverloadsCanReturnAndSetTheInternalData)
111 DryChem::Vector3D<long double> coordinates {1.0, -3.0, 5.0};
113 ASSERT_EQ(1.0, coordinates.at(0));
114 ASSERT_EQ(-3.0, coordinates.at(1));
115 ASSERT_EQ(5.0, coordinates.at(2));
117 coordinates.at(0) += 4.0;
118 coordinates.at(1) += 4.0;
119 coordinates.at(2) += 4.0;
121 ASSERT_EQ(5.0, coordinates.at(0));
122 ASSERT_EQ(1.0, coordinates.at(1));
123 ASSERT_EQ(9.0, coordinates.at(2));
126GTEST_TEST(testVector3DFunctions, subscriptOperatorsCanReturnAndSetTheInternalData)
128 DryChem::Vector3D<long double> coordinates {1.0, -3.0, 5.0};
130 ASSERT_EQ(1.0, coordinates[0]);
131 ASSERT_EQ(-3.0, coordinates[1]);
132 ASSERT_EQ(5.0, coordinates[2]);
134 coordinates[0] += 4.0;
135 coordinates[1] += 4.0;
136 coordinates[2] += 4.0;
138 ASSERT_EQ(5.0, coordinates[0]);
139 ASSERT_EQ(1.0, coordinates[1]);
140 ASSERT_EQ(9.0, coordinates[2]);
143GTEST_TEST(testVector3DFunctions, atFunctionOverloadsWillThrowWhenIndexIsOutOfRange)
145 std::stringstream deathRegex;
147 deathRegex <<
"Common-Utilities Fatal Error:\n Exception message: ";
149#if GTEST_USES_POSIX_RE
150 deathRegex <<
"array::at";
151#elif GTEST_USES_SIMPLE_RE
154 std::cout << std::array<int, 3>().at(3) << std::endl;
156 catch (
const std::out_of_range& except)
158 deathRegex << except.what();
168 DryChem::Vector3D<int>().at(3);
170 catch (
const std::exception& except)
172 DryChem::ErrorMessage error;
173 error.programName =
"Common-Utilities";
174 error.message =
"Exception message: " + std::string {except.what()};
176 throw DryChem::FatalException(error);
179 catch (
const DryChem::FatalException& except)
181 except.handleErrorWithMessage();
192 DryChem::Vector3D<int>().at(3) = 2;
194 catch (
const std::exception& except)
196 DryChem::ErrorMessage error;
197 error.programName =
"Common-Utilities";
198 error.message =
"Exception message: " + std::string {except.what()};
200 throw DryChem::FatalException(error);
203 catch (
const DryChem::FatalException& except)
205 except.handleErrorWithMessage();
211GTEST_TEST(testVector3DFunctions, aVector3DCanBeUsedInStdAlgorithms)
213 DryChem::Vector3D<long double> vec {2.0l, 3.5l, 0.1l};
215 ASSERT_FALSE(std::is_sorted(vec.cbegin(), vec.cend()));
217 std::sort(vec.begin(), vec.end());
219 ASSERT_TRUE(std::is_sorted(vec.begin(), vec.end()));
222GTEST_TEST(testVector3DFunctions, aVector3DCanBeUsedInRangeBasedForLoops)
224 testing::internal::CaptureStdout();
226 for (
const auto& elem : DryChem::Vector3D<long double> {2.2l, 3.3l, 1.1l})
227 std::cout << elem <<
' ';
228 std::cout << std::endl;
230 std::string output = testing::internal::GetCapturedStdout();
231 ASSERT_EQ(output,
"2.2 3.3 1.1 \n");
256GTEST_TEST(testVector3DFunctions, theFillMemberFunctionSetsAllElementsToTheSameValue)
258 DryChem::Vector3D<long double> vec {1.0l, 2.0l, 3.0l};
260 long double counter {};
262 for (
const auto& elem : vec)
263 ASSERT_EQ(++counter, elem);
267 for (
const auto& elem : vec)
268 ASSERT_EQ(3.14l, elem);
271GTEST_TEST(testVector3DFunctions, theSwapMemberFunctionSwapsAllElementsOfTwoVector3Ds)
273 DryChem::Vector3D<long double> vec1 {1.0l, 2.0l, 3.0l};
274 DryChem::Vector3D<long double> vec2 {6.0l, 4.0l, 2.0l};
276 DryChem::Vector3D<long double> copyVec1 {vec1};
277 DryChem::Vector3D<long double> copyVec2 {vec2};
281 for (std::size_t i {}; i < vec1.size(); ++i)
283 ASSERT_EQ(vec1[i], copyVec2[i]);
284 ASSERT_EQ(vec2[i], copyVec1[i]);
GTEST_TEST(testVector3DFunctions, typeWithNoDefaultConstructorGivesACompileTimeError)
Definition testVector3DFunctions.hpp:26