Engauge Digitizer 2
Loading...
Searching...
No Matches
TestExportAlign.cpp
Go to the documentation of this file.
1#include "ExportAlignLinear.h"
2#include "ExportAlignLog.h"
3#include "Logger.h"
4#include <QtTest/QtTest>
6
7QTEST_MAIN (TestExportAlign)
8
9using namespace std;
10
11const bool DEBUG_FLAG = false;
12
14 QObject(parent)
15{
16}
17
18void TestExportAlign::cleanupTestCase ()
19{
20}
21
22bool TestExportAlign::epsilonTest (double a,
23 double b) const
24{
25 double epsilon = qMax (qAbs (a), qAbs (b)) / 100000.0;
26 if (epsilon == 0) {
27 epsilon = 1e-6;
28 }
29
30 return qAbs (a - b) <= epsilon;
31}
32
33void TestExportAlign::initTestCase ()
34{
35 initializeLogging ("engauge_test",
36 "engauge_test.log",
38}
39
40void TestExportAlign::testLinearDigits1 ()
41{
42 QVERIFY (testLinearGeneric (4, 6) == 4); // 4, 5, 6
43}
44
45void TestExportAlign::testLinearDigits2 ()
46{
47 QVERIFY (testLinearGeneric (4.4, 4.6) == 4.4); // 4.4, 4.5, 4.6
48}
49
50void TestExportAlign::testLinearDigits3 ()
51{
52 QVERIFY (testLinearGeneric (4.44, 4.46) == 4.44); // 4.44, 4.45, 4.46
53}
54
55double TestExportAlign::testLinearGeneric (double xMin,
56 double xMax) const
57{
58 ExportAlignLinear align (xMin, xMax);
59 return align.firstSimplestNumber ();
60}
61
62void TestExportAlign::testLinearHighDynamicRangeNegNeg ()
63{
64 QVERIFY (testLinearGeneric (-4.3, -0.002) == -5.0); // -5,-4,-3-,-2,-1,0,1
65}
66
67void TestExportAlign::testLinearHighDynamicRangeNegPos ()
68{
69 QVERIFY (testLinearGeneric (-0.002, 4.3) == -1.0); // -1,0,1,2,3,4,5
70}
71
72void TestExportAlign::testLinearHighDynamicRangePosPos ()
73{
74 QVERIFY (testLinearGeneric (0.002, 4.3) == 0.0); // 0,1,2,3,4,5
75}
76
77void TestExportAlign::testLinearLowDynamicRangeNegNeg ()
78{
79 QVERIFY (testLinearGeneric (-4.3, -0.2) == -5.0); // -5,-4,-3,-2,-1,0,1
80}
81
82void TestExportAlign::testLinearLowDynamicRangeNegPos ()
83{
84 QVERIFY (testLinearGeneric (-4.3, 0.2) == -5.0); // -5,-4,-3,-2,-1,0,1
85}
86
87void TestExportAlign::testLinearLowDynamicRangePosPos ()
88{
89 QVERIFY (testLinearGeneric (0.2, 4.3) == 0.0); // 0,1,2,3,4,5
90}
91
92void TestExportAlign::testLinearRelativelySmallRangeNeg ()
93{
94 QVERIFY (testLinearGeneric (-4.9995, -4.9993) == -4.9995); // -4.9995, -4.9994, -4.9993
95}
96
97void TestExportAlign::testLinearRelativelySmallRangePos ()
98{
99 QVERIFY (testLinearGeneric (4.9993, 4.9995) == 4.9993); // 4.9993, 4.9994, 4.9995
100}
101
102void TestExportAlign::testLogDigits1 ()
103{
104 QVERIFY (epsilonTest (testLogGeneric (4, 6), 4)); // 10^4, 10^5, 10^6
105}
106
107void TestExportAlign::testLogDigits2 ()
108{
109 QVERIFY (epsilonTest (testLogGeneric (4.4, 4.6), 4.4)); // 10^4.4, 10^4.5, 10^4.6
110}
111
112void TestExportAlign::testLogDigits3 ()
113{
114 QVERIFY (epsilonTest (testLogGeneric (4.44, 4.46), 4.44)); // 10^4.44, 10^4.45, 10^4.46
115}
116
117double TestExportAlign::testLogGeneric (double xMinExponent,
118 double xMaxExponent) const
119{
120 double xMin = qPow (10.0, xMinExponent);
121 double xMax = qPow (10.0, xMaxExponent);
122
123 ExportAlignLog align (xMin, xMax);
124 double result = align.firstSimplestNumber ();
125 double resultExponent = qLn (result) / qLn (10.0);
126
127 return resultExponent;
128}
129
130void TestExportAlign::testLogHighDynamicRangeNegNeg ()
131{
132 QVERIFY (epsilonTest (testLogGeneric (-4.3, -0.002), -5.0)); // -5,-4,-3-,-2,-1,0,1
133}
134
135void TestExportAlign::testLogHighDynamicRangeNegPos ()
136{
137 QVERIFY (epsilonTest (testLogGeneric (-0.002, 4.3), -1.0)); // -1,0,1,2,3,4,5
138}
139
140void TestExportAlign::testLogHighDynamicRangePosPos ()
141{
142 QVERIFY (epsilonTest (testLogGeneric (0.002, 4.3), 0.0)); // 0,1,2,3,4,5
143}
144
145void TestExportAlign::testLogLowDynamicRangeNegNeg ()
146{
147 QVERIFY (epsilonTest (testLogGeneric (-4.3, -0.2), -5.0)); // -5,-4,-3,-2,-1,0,1
148}
149
150void TestExportAlign::testLogLowDynamicRangeNegPos ()
151{
152 QVERIFY (epsilonTest (testLogGeneric (-4.3, 0.2), -5.0)); // -5,-4,-3,-2,-1,0,1
153}
154
155void TestExportAlign::testLogLowDynamicRangePosPos ()
156{
157 QVERIFY (epsilonTest (testLogGeneric (0.2, 4.3), 0.0)); // 0,1,2,3,4,5
158}
159
160void TestExportAlign::testLogRelativelySmallRangeNeg ()
161{
162 QVERIFY (epsilonTest (testLogGeneric (-4.9995, -4.9993), -4.9995)); // -4.9995, -4.9994, -4.9993
163}
164
165void TestExportAlign::testLogRelativelySmallRangePos ()
166{
167 QVERIFY (epsilonTest (testLogGeneric (4.9993, 4.9995), 4.9993)); // 4.9993, 4.9994, 4.9995
168}
void initializeLogging(const QString &name, const QString &filename, bool isDebug)
Definition Logger.cpp:21
const bool DEBUG_FLAG
Unit test of ExportAlign classes.
TestExportAlign(QObject *parent=0)
Single constructor.