Engauge Digitizer  2
 All Classes Functions Variables Typedefs Enumerations Friends Pages
TestGridLineLimiter.cpp
1 #include "DocumentModelCoords.h"
2 #include "DocumentModelGridDisplay.h"
3 #include "GridLineLimiter.h"
4 #include "Logger.h"
5 #include "MainWindow.h"
6 #include "MainWindowModel.h"
7 #include <qmath.h>
8 #include <QtTest/QtTest>
9 #include "Test/TestGridLineLimiter.h"
10 #include "Transformation.h"
11 
12 QTEST_MAIN (TestGridLineLimiter)
13 
14 using namespace std;
15 
17  QObject(parent)
18 {
19 }
20 
21 void TestGridLineLimiter::cleanupTestCase ()
22 {
23 }
24 
25 void TestGridLineLimiter::initTestCase ()
26 {
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 DEBUG_FLAG = false;
34  const QStringList NO_LOAD_STARTUP_FILES;
35 
36  initializeLogging ("engauge_test",
37  "engauge_test.log",
38  DEBUG_FLAG);
39 
40  MainWindow w (NO_ERROR_REPORT_LOG_FILE,
41  NO_REGRESSION_OPEN_FILE,
42  NO_REGRESSION_IMPORT,
43  NO_GNUPLOT_LOG_FILES,
44  NO_RESET,
45  NO_EXPORT_ONLY,
46  NO_LOAD_STARTUP_FILES);
47  w.show ();
48 }
49 
50 void TestGridLineLimiter::testBadStepLinearX ()
51 {
52  bool success = testLinearX (0,
53  0, // Bad
54  100,
55  0.001, 0.001,
56  1000, 0.001,
57  0.001, 1000);
58 
59  QVERIFY (success);
60 }
61 
62 void TestGridLineLimiter::testBadStepLinearY ()
63 {
64  bool success = testLinearY (0,
65  0, // Bad
66  100,
67  0.001, 0.001,
68  1000, 0.001,
69  0.001, 1000);
70 
71  QVERIFY (success);
72 }
73 
74 void TestGridLineLimiter::testBadStepLogX ()
75 {
76  bool success = testLogX (0, // Bad
77  1, // Bad
78  100,
79  0.001, 0.001,
80  1000, 0.001,
81  0.001, 1000);
82 
83  QVERIFY (success);
84 }
85 
86 void TestGridLineLimiter::testBadStepLogY ()
87 {
88  bool success = testLogY (0, // Bad
89  1, // Bad
90  100,
91  0.001, 0.001,
92  1000, 0.001,
93  0.001, 1000);
94 
95  QVERIFY (success);
96 }
97 
98 bool TestGridLineLimiter::testLinearX (double start,
99  double step,
100  double stop,
101  double x1, double y1,
102  double x2, double y2,
103  double x3, double y3)
104 {
105  GridLineLimiter limiter;
106  QImage image;
107  Document document (image);
108  DocumentModelCoords modelCoords;
109  MainWindowModel modelMainWindow;
110  DocumentModelGridDisplay modelGrid;
111  Transformation transformation;
112  double startX, stepX, stopX; // Outputs from GridLineLimiter
113 
114  modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
115  modelGrid.setStartX (start);
116  modelGrid.setStepX (step);
117  modelGrid.setStopX (stop);
118  modelMainWindow.setMaximumGridLines (5);
119  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
120  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
121  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
122 
123  limiter.limitForXTheta (document,
124  transformation,
125  modelCoords,
126  modelMainWindow,
127  modelGrid,
128  startX,
129  stepX,
130  stopX);
131 
132  bool success = true;
133 
134  if (stepX > 0) {
135 
136  int gridLineCount = 1 + (stopX - startX) / stepX;
137  success = (gridLineCount <= 20);
138 
139  } else {
140 
141  success = (startX == stopX);
142 
143  }
144 
145  return success;
146 }
147 
148 bool TestGridLineLimiter::testLinearY (double start,
149  double step,
150  double stop,
151  double x1, double y1,
152  double x2, double y2,
153  double x3, double y3)
154 {
155  GridLineLimiter limiter;
156  QImage image;
157  Document document (image);
158  DocumentModelCoords modelCoords;
159  MainWindowModel modelMainWindow;
160  DocumentModelGridDisplay modelGrid;
161  Transformation transformation;
162  double startY, stepY, stopY; // Outputs from GridLineLimiter
163 
164  modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
165  modelGrid.setStartY (start);
166  modelGrid.setStepY (step);
167  modelGrid.setStopY (stop);
168  modelMainWindow.setMaximumGridLines (5);
169  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
170  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
171  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
172 
173  limiter.limitForYRadius (document,
174  transformation,
175  modelCoords,
176  modelMainWindow,
177  modelGrid,
178  startY,
179  stepY,
180  stopY);
181 
182  bool success = true;
183 
184  if (stepY > 0) {
185 
186  int gridLineCount = 1 + (stopY - startY) / stepY;
187  success = (gridLineCount <= 20);
188 
189  } else {
190 
191  success = (startY == stopY);
192 
193  }
194 
195  return success;
196 }
197 
198 bool TestGridLineLimiter::testLogX (double start,
199  double step,
200  double stop,
201  double x1, double y1,
202  double x2, double y2,
203  double x3, double y3)
204 {
205  GridLineLimiter limiter;
206  QImage image;
207  Document document (image);
208  DocumentModelCoords modelCoords;
209  MainWindowModel modelMainWindow;
210  DocumentModelGridDisplay modelGrid;
211  Transformation transformation;
212  double startX, stepX, stopX; // Outputs from GridLineLimiter
213 
214  modelCoords.setCoordScaleXTheta (COORD_SCALE_LOG);
215  modelGrid.setStartX (start);
216  modelGrid.setStepX (step);
217  modelGrid.setStopX (stop);
218  modelMainWindow.setMaximumGridLines (5);
219  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
220  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
221  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
222 
223  limiter.limitForXTheta (document,
224  transformation,
225  modelCoords,
226  modelMainWindow,
227  modelGrid,
228  startX,
229  stepX,
230  stopX);
231 
232  bool success = (startX > 0) && (stepX > 0);
233 
234  if (success) {
235 
236  int gridLineCount = 1 + (qLn (stopX) - qLn (startX)) / qLn (stepX);
237  success = (gridLineCount <= 20);
238 
239  }
240 
241  return success;
242 }
243 
244 bool TestGridLineLimiter::testLogY (double start,
245  double step,
246  double stop,
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  DocumentModelGridDisplay modelGrid;
257  Transformation transformation;
258  double startY, stepY, stopY; // Outputs from GridLineLimiter
259 
260  modelCoords.setCoordScaleYRadius (COORD_SCALE_LOG);
261  modelGrid.setStartY (start);
262  modelGrid.setStepY (step);
263  modelGrid.setStopY (stop);
264  modelMainWindow.setMaximumGridLines (5);
265  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
266  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
267  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
268 
269  limiter.limitForYRadius (document,
270  transformation,
271  modelCoords,
272  modelMainWindow,
273  modelGrid,
274  startY,
275  stepY,
276  stopY);
277 
278  bool success = (startY > 0) && (stepY > 0);
279 
280  if (success) {
281 
282  int gridLineCount = 1 + (qLn (stopY) - qLn (startY)) / qLn (stepY);
283  success = (gridLineCount <= 20);
284 
285  }
286 
287  return success;
288 }
289 
290 void TestGridLineLimiter::testTransitionLinearToLogX ()
291 {
292  bool success = testLogX (0,
293  250,
294  1000,
295  0.001, 0.001,
296  1000, 0.001,
297  0.001, 1000);
298 
299  QVERIFY (success);
300 }
301 
302 void TestGridLineLimiter::testTransitionLinearToLogY ()
303 {
304  bool success = testLogY (0,
305  250,
306  1000,
307  0.001, 0.001,
308  1000, 0.001,
309  0.001, 1000);
310 
311  QVERIFY (success);
312 }
void limitForXTheta(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startX, double &stepX, double &stopX) const
Limit step value for x/theta coordinate. This is a noop if the maximum grid line limit in MainWindowM...
void limitForYRadius(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startY, double &stepY, double &stopY) const
Limit step value for y/range coordinate. This is a noop if the maximum grid line limit in MainWindowM...
void setStartX(double startX)
Set method for x grid line lower bound (inclusive).
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
void setStepX(double stepX)
Set method for x grid line increment.
void setCoordScaleYRadius(CoordScale coordScale)
Set method for linear/log scale on y/radius.
void setStepY(double yStep)
Set method for y grid line increment.
Affine transformation between screen and graph coordinates, based on digitized axis points...
void setStopX(double stopX)
Set method for x grid line upper bound (inclusive).
Model for DlgSettingsMainWindow.
void setStopY(double yStop)
Set method for y grid line upper bound (inclusive).
Model for DlgSettingsCoords and CmdSettingsCoords.
Storage of one imported image and the data attached to that image.
Definition: Document.h:41
void setMaximumGridLines(int maximumGridLines)
Set method for maximum number of grid lines.
void setStartY(double yStart)
Set method for y grid line lower bound (inclusive).
Unit test of GridLineLimiter class.
Limit the number of grid lines so a bad combination of start/step/stop value will not lead to extreme...
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:89
void setCoordScaleXTheta(CoordScale coordScale)
Set method for linear/log scale on x/theta.