00001 #include "Logger.h"
00002 #include "MainWindow.h"
00003 #include <qmath.h>
00004 #include <QtTest/QtTest>
00005 #include "Spline.h"
00006 #include "SplinePair.h"
00007 #include "Test/TestSpline.h"
00008
00009 QTEST_MAIN (TestSpline)
00010
00011 using namespace std;
00012
00013 TestSpline::TestSpline(QObject *parent) :
00014 QObject(parent)
00015 {
00016 }
00017
00018 void TestSpline::cleanupTestCase ()
00019 {
00020
00021 }
00022
00023 void TestSpline::initTestCase ()
00024 {
00025 const QString NO_ERROR_REPORT_LOG_FILE;
00026 const QString NO_REGRESSION_OPEN_FILE;
00027 const bool NO_GNUPLOT_LOG_FILES = false;
00028 const bool NO_REGRESSION_IMPORT = false;
00029 const bool DEBUG_FLAG = false;
00030 const QStringList NO_LOAD_STARTUP_FILES;
00031
00032 initializeLogging ("engauge_test",
00033 "engauge_test.log",
00034 DEBUG_FLAG);
00035
00036 MainWindow w (NO_ERROR_REPORT_LOG_FILE,
00037 NO_REGRESSION_OPEN_FILE,
00038 NO_GNUPLOT_LOG_FILES,
00039 NO_REGRESSION_IMPORT,
00040 NO_LOAD_STARTUP_FILES);
00041 w.show ();
00042 }
00043
00044 void TestSpline::testSplinesAsControlPoints ()
00045 {
00046 const int T_START = 1, T_STOP = 7;
00047 const double SPLINE_EPSILON = 0.01;
00048 const int NUM_T = 60;
00049
00050 bool success = true;
00051
00052 vector<double> t;
00053 vector<SplinePair> xy;
00054
00055
00056 t.push_back (T_START);
00057 t.push_back (2);
00058 t.push_back (3);
00059 t.push_back (4);
00060 t.push_back (5);
00061 t.push_back (6);
00062 t.push_back (T_STOP);
00063
00064
00065 xy.push_back (SplinePair (1, 0.22));
00066 xy.push_back (SplinePair (1.8, 0.04));
00067 xy.push_back (SplinePair (3.2, -0.13));
00068 xy.push_back (SplinePair (4.3, -0.17));
00069 xy.push_back (SplinePair (5, -0.04));
00070 xy.push_back (SplinePair (5.8, 0.09));
00071 xy.push_back (SplinePair (7, 0.11));
00072
00073 Spline s (t, xy);
00074
00075 for (int i = 0; i <= NUM_T; i++) {
00076 double t = T_START + (double) i * (T_STOP - T_START) / (double) NUM_T;
00077 SplinePair spCoeff = s.interpolateCoeff (t);
00078 SplinePair spBezier = s.interpolateControlPoints (t);
00079
00080 double xCoeff = spCoeff.x();
00081 double yCoeff = spCoeff.y();
00082 double xControl = spBezier.x();
00083 double yControl = spBezier.y();
00084
00085 if (qAbs (xCoeff - xControl) > SPLINE_EPSILON) {
00086 success = false;
00087 }
00088
00089 if (qAbs (yCoeff - yControl) > SPLINE_EPSILON) {
00090 success = false;
00091 }
00092 }
00093
00094 QVERIFY (success);
00095 }