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;
24 const QStringList NO_LOAD_STARTUP_FILES;
26 initializeLogging (
"engauge_test",
32 NO_LOAD_STARTUP_FILES);
36 void TestCorrelation::loadSinusoid (
double function [],
40 for (
int i = 0; i < n; i++) {
45 function [i] = qSin (x) / x;
50 void TestCorrelation::loadThreeTriangles (
double function [],
54 const int PEAK_SEPARATION = 50, PEAK_HALF_WIDTH = 5;
57 for (
int i = 0; i < n; i++) {
61 if (x > PEAK_HALF_WIDTH) {
64 x = i - (center - PEAK_SEPARATION);
65 if (x > PEAK_HALF_WIDTH) {
68 x = i - (center + PEAK_SEPARATION);
72 if (x < PEAK_HALF_WIDTH) {
75 function [i] = (double) (PEAK_HALF_WIDTH - x) / (double) PEAK_HALF_WIDTH;
84 void TestCorrelation::testShiftSinusoidNonPowerOf2 ()
87 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
90 double function1 [N], function2 [N], correlations [N];
97 loadSinusoid (function1, N, INDEX_MAX);
98 loadSinusoid (function2, N, INDEX_MAX + INDEX_SHIFT);
100 correlation.correlateWithShift (N,
107 QVERIFY (binStartMax = INDEX_SHIFT);
110 void TestCorrelation::testShiftSinusoidPowerOf2 ()
113 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
116 double function1 [N], function2 [N], correlations [N];
123 loadSinusoid (function1, N, INDEX_MAX);
124 loadSinusoid (function2, N, INDEX_MAX + INDEX_SHIFT);
126 correlation.correlateWithShift (N,
133 QVERIFY (binStartMax = INDEX_SHIFT);
136 void TestCorrelation::testShiftThreeTrianglesNonPowerOf2 ()
139 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
142 double function1 [N], function2 [N], correlations [N];
149 loadThreeTriangles (function1, N, INDEX_MAX);
150 loadThreeTriangles (function2, N, INDEX_MAX + INDEX_SHIFT);
152 correlation.correlateWithShift (N,
159 QVERIFY (binStartMax = INDEX_SHIFT);
162 void TestCorrelation::testShiftThreeTrianglesPowerOf2 ()
165 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
168 double function1 [N], function2 [N], correlations [N];
175 loadThreeTriangles (function1, N, INDEX_MAX);
176 loadThreeTriangles (function2, N, INDEX_MAX + INDEX_SHIFT);
178 correlation.correlateWithShift (N,
185 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...