1 #include "FittingStatistics.h" 3 #include "MainWindow.h" 6 #include <QtTest/QtTest> 7 #include "Test/TestFitting.h" 18 void TestFitting::cleanupTestCase ()
23 bool TestFitting::generalTest (
int order,
26 int orderReduced = qMin (order, numPoints - 1);
28 const double EPSILON = 0.0001;
30 double mse, rms, rSquared;
31 FittingCurveCoefficients coefficientsGot (MAX_POLYNOMIAL_ORDER + 1);
34 bool isOverfitting = (order >= numPoints - 1);
37 FittingPointsConvenient points;
38 for (
int iPoint = 0; iPoint < numPoints; iPoint++) {
41 if (orderReduced > 0) {
43 for (
int ord = 0; ord < orderReduced; ord++) {
48 points.append (QPointF (x, y));
61 FittingCurveCoefficients coefficientsExpected (orderReduced + 1);
65 coefficientsExpected [0] = 0;
68 coefficientsExpected [0] = 1;
69 coefficientsExpected [1] = 1;
72 coefficientsExpected [0] = 2;
73 coefficientsExpected [1] = 3;
74 coefficientsExpected [2] = 1;
77 coefficientsExpected [0] = 6;
78 coefficientsExpected [1] = 11;
79 coefficientsExpected [2] = 6;
80 coefficientsExpected [3] = 1;
83 coefficientsExpected [0] = 24;
84 coefficientsExpected [1] = 50;
85 coefficientsExpected [2] = 35;
86 coefficientsExpected [3] = 10;
87 coefficientsExpected [4] = 1;
91 for (
int coef = 0; coef < order + 1; coef++) {
92 double coefGot = coefficientsGot [coef];
94 double coefExpected = 0;
95 if (coef <= orderReduced) {
96 coefExpected = coefficientsExpected [coef];
99 success = (success && ((qAbs (coefGot - coefExpected) < EPSILON)));
104 success = (success && ((qAbs (mse) < EPSILON)));
110 void TestFitting::initTestCase ()
112 const QString NO_ERROR_REPORT_LOG_FILE;
113 const QString NO_REGRESSION_OPEN_FILE;
114 const bool NO_GNUPLOT_LOG_FILES =
false;
115 const bool NO_REGRESSION_IMPORT =
false;
116 const bool NO_RESET =
false;
117 const bool DEBUG_FLAG =
false;
118 const QStringList NO_LOAD_STARTUP_FILES;
120 initializeLogging (
"engauge_test",
125 NO_REGRESSION_OPEN_FILE,
126 NO_GNUPLOT_LOG_FILES,
127 NO_REGRESSION_IMPORT,
129 NO_LOAD_STARTUP_FILES);
133 void TestFitting::testExactFit01 ()
135 QVERIFY (generalTest (0, 1));
138 void TestFitting::testExactFit12 ()
140 QVERIFY (generalTest (1, 2));
143 void TestFitting::testExactFit23 ()
145 QVERIFY (generalTest (2, 3));
148 void TestFitting::testExactFit34 ()
150 QVERIFY (generalTest (3, 4));
153 void TestFitting::testOverfit11 ()
155 QVERIFY (generalTest (1, 1));
158 void TestFitting::testOverfit22 ()
160 QVERIFY (generalTest (2, 2));
163 void TestFitting::testOverfit33 ()
165 QVERIFY (generalTest (3, 3));
168 void TestFitting::testOverfit44 ()
170 QVERIFY (generalTest (4, 4));
173 void TestFitting::testUnderfit02 ()
175 QVERIFY (generalTest (0, 2));
178 void TestFitting::testUnderfit13 ()
180 QVERIFY (generalTest (1, 3));
183 void TestFitting::testUnderfit24 ()
185 QVERIFY (generalTest (2, 4));
188 void TestFitting::testUnderfit35 ()
190 QVERIFY (generalTest (3, 5));
Unit test of Fitting classes.
TestFitting(QObject *parent=0)
Single constructor.
This class does the math to compute statistics for FittingWindow.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
void calculateCurveFitAndStatistics(unsigned int order, const FittingPointsConvenient &pointsConvenient, FittingCurveCoefficients &coefficients, double &mse, double &rms, double &rSquared)
Compute the curve fit and the statistics for that curve fit.