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 NO_RESET = false;
00030 const bool DEBUG_FLAG = false;
00031 const QStringList NO_LOAD_STARTUP_FILES;
00032
00033 initializeLogging ("engauge_test",
00034 "engauge_test.log",
00035 DEBUG_FLAG);
00036
00037 MainWindow w (NO_ERROR_REPORT_LOG_FILE,
00038 NO_REGRESSION_OPEN_FILE,
00039 NO_GNUPLOT_LOG_FILES,
00040 NO_REGRESSION_IMPORT,
00041 NO_RESET,
00042 NO_LOAD_STARTUP_FILES);
00043 w.show ();
00044 }
00045
00046 void TestSpline::testSplinesAsControlPoints ()
00047 {
00048 const int T_START = 1, T_STOP = 7;
00049 const double SPLINE_EPSILON = 0.01;
00050 const int NUM_T = 60;
00051
00052 bool success = true;
00053
00054 vector<double> t;
00055 vector<SplinePair> xy;
00056
00057
00058 t.push_back (T_START);
00059 t.push_back (2);
00060 t.push_back (3);
00061 t.push_back (4);
00062 t.push_back (5);
00063 t.push_back (6);
00064 t.push_back (T_STOP);
00065
00066
00067 xy.push_back (SplinePair (1, 0.22));
00068 xy.push_back (SplinePair (1.8, 0.04));
00069 xy.push_back (SplinePair (3.2, -0.13));
00070 xy.push_back (SplinePair (4.3, -0.17));
00071 xy.push_back (SplinePair (5, -0.04));
00072 xy.push_back (SplinePair (5.8, 0.09));
00073 xy.push_back (SplinePair (7, 0.11));
00074
00075 Spline s (t, xy);
00076
00077 for (int i = 0; i <= NUM_T; i++) {
00078 double t = T_START + (double) i * (T_STOP - T_START) / (double) NUM_T;
00079 SplinePair spCoeff = s.interpolateCoeff (t);
00080 SplinePair spBezier = s.interpolateControlPoints (t);
00081
00082 double xCoeff = spCoeff.x();
00083 double yCoeff = spCoeff.y();
00084 double xControl = spBezier.x();
00085 double yControl = spBezier.y();
00086
00087 if (qAbs (xCoeff - xControl) > SPLINE_EPSILON) {
00088 success = false;
00089 }
00090
00091 if (qAbs (yCoeff - yControl) > SPLINE_EPSILON) {
00092 success = false;
00093 }
00094 }
00095
00096 QVERIFY (success);
00097 }