19GTEST_TEST(testIntegrationMethods, theTrapzMethodCanBeUsedInCompileTimeCalculations)
21 const int x1 {0}, x2 {15}, y1 {0}, y2 {6};
23 static_assert(45 == DryChem::trapz(x1, x2, y1, y2),
"Trapz method failed.");
26GTEST_TEST(testIntegrationMethods, theTrapzMethodCanAcceptMultipleTypes)
28 long double x1 {0.1}, x2 {22.5}, y1 {2.3}, y2 {6.0};
30 ASSERT_DOUBLE_EQ(92.96, DryChem::trapz(x1, x2, y1, y2));
33GTEST_TEST(testIntegrationMethods, theCumulativeTrapzMethodHasAnOptionalParameterWhichCanBeOverriden)
35 std::vector<long double> x, y, expectedResult;
37 for (std::size_t i {}; i <= 10; ++i)
39 x.push_back(
static_cast<long double>(i));
40 y.push_back(
static_cast<long double>(i));
42 expectedResult.push_back((x[i] * x[i]) / 2.0);
46 auto integrationResult1 = DryChem::cumulativeTrapzIntegration(x.begin(), x.end(), y.begin(), y.end());
47 auto integrationResult2 = DryChem::cumulativeTrapzIntegration(x.begin(), x.end(), y.begin(), y.end(), 0.0);
48 auto integrationResult3 = DryChem::cumulativeTrapzIntegration(x.begin(), x.end(), y.begin(), y.end(), 5.0);
50 for (std::size_t i {}; i < expectedResult.size(); ++i)
52 ASSERT_EQ(expectedResult[i], integrationResult2[i]);
55 ASSERT_EQ(5.0, integrationResult3[i]);
57 ASSERT_EQ(expectedResult[i], integrationResult3[i]);
59 if (i == expectedResult.size() - 1)
62 ASSERT_EQ(expectedResult[i + 1], integrationResult1[i]);
66GTEST_TEST(testIntegrationMethods, insteadOfUsingIteratorsWeCanJustPassFullContainers)
68 std::vector<long double> x, y, expectedResult;
70 for (std::size_t i {}; i <= 10; ++i)
72 x.push_back(
static_cast<long double>(i));
73 y.push_back(
static_cast<long double>(i));
75 expectedResult.push_back((x[i] * x[i]) / 2.0);
79 auto integrationResult = DryChem::cumulativeTrapzIntegration(x, y, 0.0);
81 ASSERT_EQ(expectedResult, integrationResult);
84GTEST_TEST(testIntegrationMethods, passingTwoDifferentlySizedContainersResultsInFatalException)
86 std::stringstream deathRegex;
88 deathRegex <<
"Common-Utilities Fatal Error: ";
90#if GTEST_USES_POSIX_RE
91 deathRegex <<
"[(]integration.hpp: *[0-9]*[)]\n\t";
92#elif GTEST_USES_SIMPLE_RE
93 deathRegex <<
"\\(integration.hpp: \\d*\\)\n\t";
96 deathRegex <<
"Input sizes for x and y containers must be the same.\n";
98 std::vector<long double> x {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
99 std::vector<long double> y {2.0, 5.0, 3.0, 7.0, 8.0, 9.0, 12.0, 10.0, 15.0, 20.0};
105 DryChem::cumulativeTrapzIntegration(x.begin(), x.end(), y.begin(), y.end() - 2);
107 catch (
const DryChem::InputSizeMismatch& except)
109 except.handleErrorWithMessage();
GTEST_TEST(testIntegrationMethods, theTrapzMethodCanBeUsedInCompileTimeCalculations)
Definition testIntegrationMethods.hpp:19