Engauge Digitizer 2
Loading...
Searching...
No Matches
TestGridLineLimiter.cpp
Go to the documentation of this file.
2#include "GridLineLimiter.h"
3#include "Logger.h"
4#include "MainWindow.h"
5#include "MainWindowModel.h"
6#include <qmath.h>
7#include <QtTest/QtTest>
9#include "Transformation.h"
10
11QTEST_MAIN (TestGridLineLimiter)
12
13using namespace std;
14
16 QObject(parent)
17{
18}
19
20void TestGridLineLimiter::cleanupTestCase ()
21{
22}
23
24void TestGridLineLimiter::initTestCase ()
25{
26 const bool NO_DROP_REGRESSION = false;
27 const QString NO_ERROR_REPORT_LOG_FILE;
28 const QString NO_REGRESSION_OPEN_FILE;
29 const bool NO_GNUPLOT_LOG_FILES = false;
30 const bool NO_REGRESSION_IMPORT = false;
31 const bool NO_RESET = false;
32 const bool NO_EXPORT_ONLY = false;
33 const bool NO_EXTRACT_IMAGE_ONLY = false;
34 const QString NO_EXTRACT_IMAGE_EXTENSION;
35 const bool DEBUG_FLAG = false;
36 const QStringList NO_LOAD_STARTUP_FILES;
37 const QStringList NO_COMMAND_LINE;
38
39 initializeLogging ("engauge_test",
40 "engauge_test.log",
42
43 MainWindow w (NO_ERROR_REPORT_LOG_FILE,
48 NO_RESET,
54 w.show ();
55}
56
57void TestGridLineLimiter::testBadStepLinearX ()
58{
59 bool success = testLinearX (0,
60 0, // Bad
61 100,
62 10,
63 0.001, 0.001,
64 1000, 0.001,
65 0.001, 1000);
66
67 QVERIFY (success);
68}
69
70void TestGridLineLimiter::testBadStepLinearY ()
71{
72 bool success = testLinearY (0,
73 0, // Bad
74 100,
75 10,
76 0.001, 0.001,
77 1000, 0.001,
78 0.001, 1000);
79
80 QVERIFY (success);
81}
82
83void TestGridLineLimiter::testBadStepLogX ()
84{
85 bool success = testLogX (0, // Bad
86 1, // Bad
87 100,
88 10,
89 0.001, 0.001,
90 1000, 0.001,
91 0.001, 1000);
92
93 QVERIFY (success);
94}
95
96void TestGridLineLimiter::testBadStepLogY ()
97{
98 bool success = testLogY (0, // Bad
99 1, // Bad
100 100,
101 10,
102 0.001, 0.001,
103 1000, 0.001,
104 0.001, 1000);
105
106 QVERIFY (success);
107}
108
109bool TestGridLineLimiter::testLinearX (double start,
110 double step,
111 double stop,
112 unsigned int num,
113 double x1, double y1,
114 double x2, double y2,
115 double x3, double y3)
116{
117 GridLineLimiter limiter;
118 QImage image;
119 Document document (image);
120 DocumentModelCoords modelCoords;
121 MainWindowModel modelMainWindow;
122 Transformation transformation;
123
125 modelMainWindow.setMaximumGridLines (5);
126 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
127 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
128 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
129
130 limiter.limitForXTheta (document,
131 transformation,
132 modelCoords,
133 modelMainWindow,
134 start,
135 step,
136 stop,
137 num);
138
139 bool success = true;
140
141 if (step > 0) {
142
143 int gridLineCount = 1 + (stop - start) / step;
144 success = (gridLineCount <= 20);
145
146 } else {
147
148 success = (start == stop);
149
150 }
151
152 return success;
153}
154
155bool TestGridLineLimiter::testLinearY (double start,
156 double step,
157 double stop,
158 unsigned int num,
159 double x1, double y1,
160 double x2, double y2,
161 double x3, double y3)
162{
163 GridLineLimiter limiter;
164 QImage image;
165 Document document (image);
166 DocumentModelCoords modelCoords;
167 MainWindowModel modelMainWindow;
168 Transformation transformation;
169
171 modelMainWindow.setMaximumGridLines (5);
172 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
173 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
174 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
175
176 limiter.limitForYRadius (document,
177 transformation,
178 modelCoords,
179 modelMainWindow,
180 start,
181 step,
182 stop,
183 num);
184
185 bool success = true;
186
187 if (step > 0) {
188
189 int gridLineCount = 1 + (stop - start) / step;
190 success = (gridLineCount <= 20);
191
192 } else {
193
194 success = (start == stop);
195
196 }
197
198 return success;
199}
200
201bool TestGridLineLimiter::testLogX (double start,
202 double step,
203 double stop,
204 unsigned int num,
205 double x1, double y1,
206 double x2, double y2,
207 double x3, double y3)
208{
209 GridLineLimiter limiter;
210 QImage image;
211 Document document (image);
212 DocumentModelCoords modelCoords;
213 MainWindowModel modelMainWindow;
214 Transformation transformation;
215
217 modelMainWindow.setMaximumGridLines (5);
218 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
219 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
220 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
221
222 limiter.limitForXTheta (document,
223 transformation,
224 modelCoords,
225 modelMainWindow,
226 start,
227 step,
228 stop,
229 num);
230
231 bool success = (start > 0) && (step > 0);
232
233 if (success) {
234
235 int gridLineCount = 1 + (qLn (stop) - qLn (start)) / qLn (step);
236 success = (gridLineCount <= 20);
237
238 }
239
240 return success;
241}
242
243bool TestGridLineLimiter::testLogY (double start,
244 double step,
245 double stop,
246 unsigned int num,
247 double x1, double y1,
248 double x2, double y2,
249 double x3, double y3)
250{
251 GridLineLimiter limiter;
252 QImage image;
253 Document document (image);
254 DocumentModelCoords modelCoords;
255 MainWindowModel modelMainWindow;
256 Transformation transformation;
257
259 modelMainWindow.setMaximumGridLines (5);
260 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
261 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
262 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
263
264 limiter.limitForYRadius (document,
265 transformation,
266 modelCoords,
267 modelMainWindow,
268 start,
269 step,
270 stop,
271 num);
272
273 bool success = (start > 0) && (step > 0);
274
275 if (success) {
276
277 int gridLineCount = 1 + (qLn (stop) - qLn (start)) / qLn (step);
278 success = (gridLineCount <= 20);
279
280 }
281
282 return success;
283}
284
285void TestGridLineLimiter::testTransitionLinearToLogX ()
286{
287 bool success = testLogX (0,
288 250,
289 1000,
290 10,
291 0.001, 0.001,
292 1000, 0.001,
293 0.001, 1000);
294
295 QVERIFY (success);
296}
297
298void TestGridLineLimiter::testTransitionLinearToLogY ()
299{
300 bool success = testLogY (0,
301 250,
302 1000,
303 10,
304 0.001, 0.001,
305 1000, 0.001,
306 0.001, 1000);
307
308 QVERIFY (success);
309}
@ COORD_SCALE_LINEAR
Definition CoordScale.h:13
@ COORD_SCALE_LOG
Definition CoordScale.h:14
void initializeLogging(const QString &name, const QString &filename, bool isDebug)
Definition Logger.cpp:21
const bool NO_EXPORT_ONLY
const QStringList NO_COMMAND_LINE
const QString NO_EXTRACT_IMAGE_EXTENSION
const QString NO_ERROR_REPORT_LOG_FILE
const bool NO_GNUPLOT_LOG_FILES
const QString NO_REGRESSION_OPEN_FILE
const QStringList NO_LOAD_STARTUP_FILES
const bool NO_REGRESSION_IMPORT
const bool NO_EXTRACT_IMAGE_ONLY
const bool NO_DROP_REGRESSION
const bool DEBUG_FLAG
void setCoordScaleXTheta(CoordScale coordScale)
Set method for linear/log scale on x/theta.
void setCoordScaleYRadius(CoordScale coordScale)
Set method for linear/log scale on y/radius.
void limitForYRadius(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, double &startY, double &stepY, double &stopY, unsigned int numY) const
Limit step value for y/range coordinate. This is a noop if the maximum grid line limit in MainWindowM...
void limitForXTheta(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, double &startX, double &stepX, double &stopX, unsigned int numX) const
Limit step value for x/theta coordinate. This is a noop if the maximum grid line limit in MainWindowM...
void setMaximumGridLines(int maximumGridLines)
Set method for maximum number of grid lines.
Unit test of GridLineLimiter class.
TestGridLineLimiter(QObject *parent=0)
Single constructor.