1 #include "Correlation.h"
3 #include "MainWindow.h"
5 #include <QtTest/QtTest>
6 #include "Test/TestCorrelation.h"
15 void TestCorrelation::cleanupTestCase ()
19 void TestCorrelation::initTestCase ()
21 const QString NO_ERROR_REPORT_LOG_FILE;
22 const bool NO_GNUPLOT_LOG_FILES =
false;
23 const bool DEBUG_FLAG =
false;
25 initializeLogging (
"engauge_test",
30 NO_GNUPLOT_LOG_FILES);
34 void TestCorrelation::loadSinusoid (
double function [],
38 for (
int i = 0; i < n; i++) {
43 function [i] = qSin (x) / x;
48 void TestCorrelation::loadThreeTriangles (
double function [],
52 const int PEAK_SEPARATION = 50, PEAK_HALF_WIDTH = 5;
55 for (
int i = 0; i < n; i++) {
59 if (x > PEAK_HALF_WIDTH) {
62 x = i - (center - PEAK_SEPARATION);
63 if (x > PEAK_HALF_WIDTH) {
66 x = i - (center + PEAK_SEPARATION);
70 if (x < PEAK_HALF_WIDTH) {
73 function [i] = (double) (PEAK_HALF_WIDTH - x) / (double) PEAK_HALF_WIDTH;
82 void TestCorrelation::testShiftSinusoidNonPowerOf2 ()
85 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
88 double function1 [N], function2 [N];
95 loadSinusoid (function1, N, INDEX_MAX);
96 loadSinusoid (function2, N, INDEX_MAX + INDEX_SHIFT);
98 correlation.correlateWithShift (N,
104 QVERIFY (binStartMax = INDEX_SHIFT);
107 void TestCorrelation::testShiftSinusoidPowerOf2 ()
110 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
113 double function1 [N], function2 [N];
120 loadSinusoid (function1, N, INDEX_MAX);
121 loadSinusoid (function2, N, INDEX_MAX + INDEX_SHIFT);
123 correlation.correlateWithShift (N,
129 QVERIFY (binStartMax = INDEX_SHIFT);
132 void TestCorrelation::testShiftThreeTrianglesNonPowerOf2 ()
135 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
138 double function1 [N], function2 [N];
145 loadThreeTriangles (function1, N, INDEX_MAX);
146 loadThreeTriangles (function2, N, INDEX_MAX + INDEX_SHIFT);
148 correlation.correlateWithShift (N,
154 QVERIFY (binStartMax = INDEX_SHIFT);
157 void TestCorrelation::testShiftThreeTrianglesPowerOf2 ()
160 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
163 double function1 [N], function2 [N];
170 loadThreeTriangles (function1, N, INDEX_MAX);
171 loadThreeTriangles (function2, N, INDEX_MAX + INDEX_SHIFT);
173 correlation.correlateWithShift (N,
179 QVERIFY (binStartMax = INDEX_SHIFT);
Fast cross correlation between two functions.
Unit tests of fast correlation algorithm.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...