19GTEST_TEST(testLinearLeastSquaresFitting, linearLeastSquaresFittingReturnsMultipleValuesInAStruct)
21 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};
22 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};
25 = DryChem::linearLeastSquaresFitting(x.begin(), x.end(), y.begin(), y.end());
27 ASSERT_NEAR(1.7152, result.
slope, DryChem::findAbsoluteError(1.7152, 5));
28 ASSERT_NEAR(-0.33333, result.
intercept, DryChem::findAbsoluteError(-0.33333, 5));
29 ASSERT_NEAR(0.2139317, std::sqrt(result.
variance), DryChem::findAbsoluteError(0.2139317, 7));
32GTEST_TEST(testLinearLeastSquaresFitting, linearLeastSquaresFittingCanReturnATypeCompatibleWithStructuredBinding)
34 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};
35 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};
37 auto [slope, intercept, variance] = DryChem::linearLeastSquaresFitting(x.cbegin(), x.cend(), y.cbegin(), y.cend());
39 ASSERT_NEAR(1.7152, slope, DryChem::findAbsoluteError(1.7152, 5));
40 ASSERT_NEAR(-0.33333, intercept, DryChem::findAbsoluteError(-0.33333, 5));
41 ASSERT_NEAR(0.2139317, std::sqrt(variance), DryChem::findAbsoluteError(0.2139317, 7));
44GTEST_TEST(testLinearLeastSquaresFitting, passingTwoDifferentlySizedContainersResultsInFatalException)
46 std::stringstream deathRegex;
48 deathRegex <<
"Common-Utilities Fatal Error: ";
50#if GTEST_USES_POSIX_RE
51 deathRegex <<
"[(]linearLeastSquaresFitting.hpp: *[0-9]*[)]\n\t";
52#elif GTEST_USES_SIMPLE_RE
53 deathRegex <<
"\\(linearLeastSquaresFitting.hpp: \\d*\\)\n\t";
56 deathRegex <<
"Input sizes for x and y containers must be the same.\n";
58 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};
59 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};
65 DryChem::linearLeastSquaresFitting(x.begin(), x.end(), y.begin(), y.end() - 2);
67 catch (
const DryChem::InputSizeMismatch& except)
69 except.handleErrorWithMessage();
GTEST_TEST(testLinearLeastSquaresFitting, linearLeastSquaresFittingReturnsMultipleValuesInAStruct)
Definition testLinearLeastSquaresFitting.hpp:19