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 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",
41  DEBUG_FLAG);
42 
43  MainWindow w (NO_ERROR_REPORT_LOG_FILE,
44  NO_REGRESSION_OPEN_FILE,
45  NO_REGRESSION_IMPORT,
46  NO_GNUPLOT_LOG_FILES,
47  NO_RESET,
48  NO_EXPORT_ONLY,
49  NO_EXTRACT_IMAGE_ONLY,
50  NO_EXTRACT_IMAGE_EXTENSION,
51  NO_LOAD_STARTUP_FILES,
52  NO_COMMAND_LINE);
53  w.show ();
54 }
55 
56 void TestGridLineLimiter::testBadStepLinearX ()
57 {
58  bool success = testLinearX (0,
59  0, // Bad
60  100,
61  0.001, 0.001,
62  1000, 0.001,
63  0.001, 1000);
64 
65  QVERIFY (success);
66 }
67 
68 void TestGridLineLimiter::testBadStepLinearY ()
69 {
70  bool success = testLinearY (0,
71  0, // Bad
72  100,
73  0.001, 0.001,
74  1000, 0.001,
75  0.001, 1000);
76 
77  QVERIFY (success);
78 }
79 
80 void TestGridLineLimiter::testBadStepLogX ()
81 {
82  bool success = testLogX (0, // Bad
83  1, // Bad
84  100,
85  0.001, 0.001,
86  1000, 0.001,
87  0.001, 1000);
88 
89  QVERIFY (success);
90 }
91 
92 void TestGridLineLimiter::testBadStepLogY ()
93 {
94  bool success = testLogY (0, // Bad
95  1, // Bad
96  100,
97  0.001, 0.001,
98  1000, 0.001,
99  0.001, 1000);
100 
101  QVERIFY (success);
102 }
103 
104 bool TestGridLineLimiter::testLinearX (double start,
105  double step,
106  double stop,
107  double x1, double y1,
108  double x2, double y2,
109  double x3, double y3)
110 {
111  GridLineLimiter limiter;
112  QImage image;
113  Document document (image);
114  DocumentModelCoords modelCoords;
115  MainWindowModel modelMainWindow;
116  DocumentModelGridDisplay modelGrid;
117  Transformation transformation;
118  double startX, stepX, stopX; // Outputs from GridLineLimiter
119 
120  modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
121  modelGrid.setStartX (start);
122  modelGrid.setStepX (step);
123  modelGrid.setStopX (stop);
124  modelMainWindow.setMaximumGridLines (5);
125  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
126  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
127  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
128 
129  limiter.limitForXTheta (document,
130  transformation,
131  modelCoords,
132  modelMainWindow,
133  modelGrid,
134  startX,
135  stepX,
136  stopX);
137 
138  bool success = true;
139 
140  if (stepX > 0) {
141 
142  int gridLineCount = 1 + (stopX - startX) / stepX;
143  success = (gridLineCount <= 20);
144 
145  } else {
146 
147  success = (startX == stopX);
148 
149  }
150 
151  return success;
152 }
153 
154 bool TestGridLineLimiter::testLinearY (double start,
155  double step,
156  double stop,
157  double x1, double y1,
158  double x2, double y2,
159  double x3, double y3)
160 {
161  GridLineLimiter limiter;
162  QImage image;
163  Document document (image);
164  DocumentModelCoords modelCoords;
165  MainWindowModel modelMainWindow;
166  DocumentModelGridDisplay modelGrid;
167  Transformation transformation;
168  double startY, stepY, stopY; // Outputs from GridLineLimiter
169 
170  modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
171  modelGrid.setStartY (start);
172  modelGrid.setStepY (step);
173  modelGrid.setStopY (stop);
174  modelMainWindow.setMaximumGridLines (5);
175  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
176  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
177  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
178 
179  limiter.limitForYRadius (document,
180  transformation,
181  modelCoords,
182  modelMainWindow,
183  modelGrid,
184  startY,
185  stepY,
186  stopY);
187 
188  bool success = true;
189 
190  if (stepY > 0) {
191 
192  int gridLineCount = 1 + (stopY - startY) / stepY;
193  success = (gridLineCount <= 20);
194 
195  } else {
196 
197  success = (startY == stopY);
198 
199  }
200 
201  return success;
202 }
203 
204 bool TestGridLineLimiter::testLogX (double start,
205  double step,
206  double stop,
207  double x1, double y1,
208  double x2, double y2,
209  double x3, double y3)
210 {
211  GridLineLimiter limiter;
212  QImage image;
213  Document document (image);
214  DocumentModelCoords modelCoords;
215  MainWindowModel modelMainWindow;
216  DocumentModelGridDisplay modelGrid;
217  Transformation transformation;
218  double startX, stepX, stopX; // Outputs from GridLineLimiter
219 
220  modelCoords.setCoordScaleXTheta (COORD_SCALE_LOG);
221  modelGrid.setStartX (start);
222  modelGrid.setStepX (step);
223  modelGrid.setStopX (stop);
224  modelMainWindow.setMaximumGridLines (5);
225  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
226  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
227  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
228 
229  limiter.limitForXTheta (document,
230  transformation,
231  modelCoords,
232  modelMainWindow,
233  modelGrid,
234  startX,
235  stepX,
236  stopX);
237 
238  bool success = (startX > 0) && (stepX > 0);
239 
240  if (success) {
241 
242  int gridLineCount = 1 + (qLn (stopX) - qLn (startX)) / qLn (stepX);
243  success = (gridLineCount <= 20);
244 
245  }
246 
247  return success;
248 }
249 
250 bool TestGridLineLimiter::testLogY (double start,
251  double step,
252  double stop,
253  double x1, double y1,
254  double x2, double y2,
255  double x3, double y3)
256 {
257  GridLineLimiter limiter;
258  QImage image;
259  Document document (image);
260  DocumentModelCoords modelCoords;
261  MainWindowModel modelMainWindow;
262  DocumentModelGridDisplay modelGrid;
263  Transformation transformation;
264  double startY, stepY, stopY; // Outputs from GridLineLimiter
265 
266  modelCoords.setCoordScaleYRadius (COORD_SCALE_LOG);
267  modelGrid.setStartY (start);
268  modelGrid.setStepY (step);
269  modelGrid.setStopY (stop);
270  modelMainWindow.setMaximumGridLines (5);
271  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
272  document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
273  document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
274 
275  limiter.limitForYRadius (document,
276  transformation,
277  modelCoords,
278  modelMainWindow,
279  modelGrid,
280  startY,
281  stepY,
282  stopY);
283 
284  bool success = (startY > 0) && (stepY > 0);
285 
286  if (success) {
287 
288  int gridLineCount = 1 + (qLn (stopY) - qLn (startY)) / qLn (stepY);
289  success = (gridLineCount <= 20);
290 
291  }
292 
293  return success;
294 }
295 
296 void TestGridLineLimiter::testTransitionLinearToLogX ()
297 {
298  bool success = testLogX (0,
299  250,
300  1000,
301  0.001, 0.001,
302  1000, 0.001,
303  0.001, 1000);
304 
305  QVERIFY (success);
306 }
307 
308 void TestGridLineLimiter::testTransitionLinearToLogY ()
309 {
310  bool success = testLogY (0,
311  250,
312  1000,
313  0.001, 0.001,
314  1000, 0.001,
315  0.001, 1000);
316 
317  QVERIFY (success);
318 }
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:91
void setCoordScaleXTheta(CoordScale coordScale)
Set method for linear/log scale on x/theta.