Engauge Digitizer  2
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>
5 #include "Test/TestExportAlign.h"
6 
7 QTEST_MAIN (TestExportAlign)
8 
9 using namespace std;
10 
11 const bool DEBUG_FLAG = false;
12 
14  QObject(parent)
15 {
16 }
17 
18 void TestExportAlign::cleanupTestCase ()
19 {
20 }
21 
22 bool 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 
33 void TestExportAlign::initTestCase ()
34 {
35  initializeLogging ("engauge_test",
36  "engauge_test.log",
37  DEBUG_FLAG);
38 }
39 
40 void TestExportAlign::testLinearDigits1 ()
41 {
42  QVERIFY (testLinearGeneric (4, 6) == 4); // 4, 5, 6
43 }
44 
45 void TestExportAlign::testLinearDigits2 ()
46 {
47  QVERIFY (testLinearGeneric (4.4, 4.6) == 4.4); // 4.4, 4.5, 4.6
48 }
49 
50 void TestExportAlign::testLinearDigits3 ()
51 {
52  QVERIFY (testLinearGeneric (4.44, 4.46) == 4.44); // 4.44, 4.45, 4.46
53 }
54 
55 double TestExportAlign::testLinearGeneric (double xMin,
56  double xMax) const
57 {
58  ExportAlignLinear align (xMin, xMax);
59  return align.firstSimplestNumber ();
60 }
61 
62 void TestExportAlign::testLinearHighDynamicRangeNegNeg ()
63 {
64  QVERIFY (testLinearGeneric (-4.3, -0.002) == -5.0); // -5,-4,-3-,-2,-1,0,1
65 }
66 
67 void TestExportAlign::testLinearHighDynamicRangeNegPos ()
68 {
69  QVERIFY (testLinearGeneric (-0.002, 4.3) == -1.0); // -1,0,1,2,3,4,5
70 }
71 
72 void TestExportAlign::testLinearHighDynamicRangePosPos ()
73 {
74  QVERIFY (testLinearGeneric (0.002, 4.3) == 0.0); // 0,1,2,3,4,5
75 }
76 
77 void TestExportAlign::testLinearLowDynamicRangeNegNeg ()
78 {
79  QVERIFY (testLinearGeneric (-4.3, -0.2) == -5.0); // -5,-4,-3,-2,-1,0,1
80 }
81 
82 void TestExportAlign::testLinearLowDynamicRangeNegPos ()
83 {
84  QVERIFY (testLinearGeneric (-4.3, 0.2) == -5.0); // -5,-4,-3,-2,-1,0,1
85 }
86 
87 void TestExportAlign::testLinearLowDynamicRangePosPos ()
88 {
89  QVERIFY (testLinearGeneric (0.2, 4.3) == 0.0); // 0,1,2,3,4,5
90 }
91 
92 void TestExportAlign::testLinearRelativelySmallRangeNeg ()
93 {
94  QVERIFY (testLinearGeneric (-4.9995, -4.9993) == -4.9995); // -4.9995, -4.9994, -4.9993
95 }
96 
97 void TestExportAlign::testLinearRelativelySmallRangePos ()
98 {
99  QVERIFY (testLinearGeneric (4.9993, 4.9995) == 4.9993); // 4.9993, 4.9994, 4.9995
100 }
101 
102 void TestExportAlign::testLogDigits1 ()
103 {
104  QVERIFY (epsilonTest (testLogGeneric (4, 6), 4)); // 10^4, 10^5, 10^6
105 }
106 
107 void TestExportAlign::testLogDigits2 ()
108 {
109  QVERIFY (epsilonTest (testLogGeneric (4.4, 4.6), 4.4)); // 10^4.4, 10^4.5, 10^4.6
110 }
111 
112 void TestExportAlign::testLogDigits3 ()
113 {
114  QVERIFY (epsilonTest (testLogGeneric (4.44, 4.46), 4.44)); // 10^4.44, 10^4.45, 10^4.46
115 }
116 
117 double 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 
130 void TestExportAlign::testLogHighDynamicRangeNegNeg ()
131 {
132  QVERIFY (epsilonTest (testLogGeneric (-4.3, -0.002), -5.0)); // -5,-4,-3-,-2,-1,0,1
133 }
134 
135 void TestExportAlign::testLogHighDynamicRangeNegPos ()
136 {
137  QVERIFY (epsilonTest (testLogGeneric (-0.002, 4.3), -1.0)); // -1,0,1,2,3,4,5
138 }
139 
140 void TestExportAlign::testLogHighDynamicRangePosPos ()
141 {
142  QVERIFY (epsilonTest (testLogGeneric (0.002, 4.3), 0.0)); // 0,1,2,3,4,5
143 }
144 
145 void TestExportAlign::testLogLowDynamicRangeNegNeg ()
146 {
147  QVERIFY (epsilonTest (testLogGeneric (-4.3, -0.2), -5.0)); // -5,-4,-3,-2,-1,0,1
148 }
149 
150 void TestExportAlign::testLogLowDynamicRangeNegPos ()
151 {
152  QVERIFY (epsilonTest (testLogGeneric (-4.3, 0.2), -5.0)); // -5,-4,-3,-2,-1,0,1
153 }
154 
155 void TestExportAlign::testLogLowDynamicRangePosPos ()
156 {
157  QVERIFY (epsilonTest (testLogGeneric (0.2, 4.3), 0.0)); // 0,1,2,3,4,5
158 }
159 
160 void TestExportAlign::testLogRelativelySmallRangeNeg ()
161 {
162  QVERIFY (epsilonTest (testLogGeneric (-4.9995, -4.9993), -4.9995)); // -4.9995, -4.9994, -4.9993
163 }
164 
165 void TestExportAlign::testLogRelativelySmallRangePos ()
166 {
167  QVERIFY (epsilonTest (testLogGeneric (4.9993, 4.9995), 4.9993)); // 4.9993, 4.9994, 4.9995
168 }
const bool DEBUG_FLAG
TestExportAlign(QObject *parent=0)
Single constructor.
Pick first simplest x value between specified min and max, for linear scaling.
Pick first simplest x value between specified min and max, for log scaling.
void initializeLogging(const QString &name, const QString &filename, bool isDebug)
Definition: Logger.cpp:21
Unit test of ExportAlign classes.