Chris@1407
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1407
|
2
|
Chris@1407
|
3 /*
|
Chris@1407
|
4 Sonic Visualiser
|
Chris@1407
|
5 An audio file viewer and annotation editor.
|
Chris@1407
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1407
|
7
|
Chris@1407
|
8 This program is free software; you can redistribute it and/or
|
Chris@1407
|
9 modify it under the terms of the GNU General Public License as
|
Chris@1407
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@1407
|
11 License, or (at your option) any later version. See the file
|
Chris@1407
|
12 COPYING included with this distribution for more information.
|
Chris@1407
|
13 */
|
Chris@1407
|
14
|
Chris@1407
|
15 #ifndef TEST_SCALE_TICK_INTERVALS_H
|
Chris@1407
|
16 #define TEST_SCALE_TICK_INTERVALS_H
|
Chris@1407
|
17
|
Chris@1407
|
18 #include "../ScaleTickIntervals.h"
|
Chris@1407
|
19
|
Chris@1407
|
20 #include <QObject>
|
Chris@1407
|
21 #include <QtTest>
|
Chris@1407
|
22 #include <QDir>
|
Chris@1407
|
23
|
Chris@1407
|
24 #include <iostream>
|
Chris@1407
|
25
|
Chris@1407
|
26 using namespace std;
|
Chris@1407
|
27
|
Chris@1407
|
28 class TestScaleTickIntervals : public QObject
|
Chris@1407
|
29 {
|
Chris@1407
|
30 Q_OBJECT
|
Chris@1407
|
31
|
Chris@1407
|
32 void printDiff(vector<ScaleTickIntervals::Tick> ticks,
|
Chris@1407
|
33 vector<ScaleTickIntervals::Tick> expected) {
|
Chris@1407
|
34
|
Chris@1407
|
35 cerr << "Have " << ticks.size() << " ticks, expected "
|
Chris@1407
|
36 << expected.size() << endl;
|
Chris@1411
|
37 for (int i = 0; i < int(ticks.size()); ++i) {
|
Chris@1411
|
38 cerr << i << ": have " << ticks[i].value << " \""
|
Chris@1411
|
39 << ticks[i].label << "\", expected ";
|
Chris@1411
|
40 if (i < int(expected.size())) {
|
Chris@1411
|
41 cerr << expected[i].value << " \"" << expected[i].label
|
Chris@1407
|
42 << "\"" << endl;
|
Chris@1411
|
43 } else {
|
Chris@1411
|
44 cerr << "(n/a)" << endl;
|
Chris@1407
|
45 }
|
Chris@1407
|
46 }
|
Chris@1407
|
47 }
|
Chris@1407
|
48
|
Chris@1417
|
49 void compareTicks(ScaleTickIntervals::Ticks ticks,
|
Chris@1417
|
50 ScaleTickIntervals::Ticks expected,
|
Chris@1415
|
51 bool fuzzier = false)
|
Chris@1407
|
52 {
|
Chris@1408
|
53 double eps = 1e-7;
|
Chris@1407
|
54 for (int i = 0; i < int(expected.size()); ++i) {
|
Chris@1407
|
55 if (i < int(ticks.size())) {
|
Chris@1415
|
56 bool pass = true;
|
Chris@1415
|
57 if (ticks[i].label != expected[i].label) {
|
Chris@1415
|
58 pass = false;
|
Chris@1415
|
59 } else if (!fuzzier) {
|
Chris@1415
|
60 if (fabs(ticks[i].value - expected[i].value) > eps) {
|
Chris@1415
|
61 pass = false;
|
Chris@1415
|
62 }
|
Chris@1415
|
63 } else {
|
Chris@1415
|
64 if (fabs(ticks[i].value - expected[i].value) >
|
Chris@1415
|
65 fabs(ticks[i].value) * 1e-5) {
|
Chris@1415
|
66 pass = false;
|
Chris@1415
|
67 }
|
Chris@1415
|
68 }
|
Chris@1415
|
69 if (!pass) {
|
Chris@1407
|
70 printDiff(ticks, expected);
|
Chris@1415
|
71 QCOMPARE(ticks[i].label, expected[i].label);
|
Chris@1415
|
72 QCOMPARE(ticks[i].value, expected[i].value);
|
Chris@1415
|
73 }
|
Chris@1407
|
74 }
|
Chris@1407
|
75 }
|
Chris@1408
|
76 if (ticks.size() != expected.size()) {
|
Chris@1408
|
77 printDiff(ticks, expected);
|
Chris@1408
|
78 }
|
Chris@1407
|
79 QCOMPARE(ticks.size(), expected.size());
|
Chris@1407
|
80 }
|
Chris@1407
|
81
|
Chris@1407
|
82 private slots:
|
Chris@1407
|
83 void linear_0_1_10()
|
Chris@1407
|
84 {
|
Chris@1407
|
85 auto ticks = ScaleTickIntervals::linear({ 0, 1, 10 });
|
Chris@1417
|
86 ScaleTickIntervals::Ticks expected {
|
Chris@1409
|
87 { 0.0, "0.0" },
|
Chris@1409
|
88 { 0.1, "0.1" },
|
Chris@1409
|
89 { 0.2, "0.2" },
|
Chris@1409
|
90 { 0.3, "0.3" },
|
Chris@1409
|
91 { 0.4, "0.4" },
|
Chris@1409
|
92 { 0.5, "0.5" },
|
Chris@1409
|
93 { 0.6, "0.6" },
|
Chris@1409
|
94 { 0.7, "0.7" },
|
Chris@1409
|
95 { 0.8, "0.8" },
|
Chris@1409
|
96 { 0.9, "0.9" },
|
Chris@1409
|
97 { 1.0, "1.0" }
|
Chris@1409
|
98 };
|
Chris@1417
|
99 compareTicks(ticks, expected);
|
Chris@1409
|
100 }
|
Chris@1409
|
101
|
Chris@1409
|
102 void linear_0_5_5()
|
Chris@1409
|
103 {
|
Chris@1409
|
104 auto ticks = ScaleTickIntervals::linear({ 0, 5, 5 });
|
Chris@1417
|
105 ScaleTickIntervals::Ticks expected {
|
Chris@1415
|
106 { 0, "0" },
|
Chris@1415
|
107 { 1, "1" },
|
Chris@1415
|
108 { 2, "2" },
|
Chris@1415
|
109 { 3, "3" },
|
Chris@1415
|
110 { 4, "4" },
|
Chris@1415
|
111 { 5, "5" },
|
Chris@1409
|
112 };
|
Chris@1417
|
113 compareTicks(ticks, expected);
|
Chris@1409
|
114 }
|
Chris@1409
|
115
|
Chris@1409
|
116 void linear_0_10_5()
|
Chris@1409
|
117 {
|
Chris@1409
|
118 auto ticks = ScaleTickIntervals::linear({ 0, 10, 5 });
|
Chris@1417
|
119 ScaleTickIntervals::Ticks expected {
|
Chris@1415
|
120 { 0, "0" },
|
Chris@1415
|
121 { 2, "2" },
|
Chris@1415
|
122 { 4, "4" },
|
Chris@1415
|
123 { 6, "6" },
|
Chris@1415
|
124 { 8, "8" },
|
Chris@1415
|
125 { 10, "10" }
|
Chris@1407
|
126 };
|
Chris@1417
|
127 compareTicks(ticks, expected);
|
Chris@1407
|
128 }
|
Chris@1407
|
129
|
Chris@1411
|
130 void linear_10_0_5()
|
Chris@1411
|
131 {
|
Chris@1411
|
132 auto ticks = ScaleTickIntervals::linear({ 10, 0, 5 });
|
Chris@1417
|
133 ScaleTickIntervals::Ticks expected {
|
Chris@1415
|
134 { 0, "0" },
|
Chris@1415
|
135 { 2, "2" },
|
Chris@1415
|
136 { 4, "4" },
|
Chris@1415
|
137 { 6, "6" },
|
Chris@1415
|
138 { 8, "8" },
|
Chris@1415
|
139 { 10, "10" }
|
Chris@1411
|
140 };
|
Chris@1417
|
141 compareTicks(ticks, expected);
|
Chris@1411
|
142 }
|
Chris@1411
|
143
|
Chris@1411
|
144 void linear_m10_0_5()
|
Chris@1411
|
145 {
|
Chris@1411
|
146 auto ticks = ScaleTickIntervals::linear({ -10, 0, 5 });
|
Chris@1417
|
147 ScaleTickIntervals::Ticks expected {
|
Chris@1415
|
148 { -10, "-10" },
|
Chris@1415
|
149 { -8, "-8" },
|
Chris@1415
|
150 { -6, "-6" },
|
Chris@1415
|
151 { -4, "-4" },
|
Chris@1415
|
152 { -2, "-2" },
|
Chris@1415
|
153 { 0, "0" }
|
Chris@1411
|
154 };
|
Chris@1417
|
155 compareTicks(ticks, expected);
|
Chris@1411
|
156 }
|
Chris@1411
|
157
|
Chris@1411
|
158 void linear_0_m10_5()
|
Chris@1411
|
159 {
|
Chris@1411
|
160 auto ticks = ScaleTickIntervals::linear({ 0, -10, 5 });
|
Chris@1417
|
161 ScaleTickIntervals::Ticks expected {
|
Chris@1415
|
162 { -10, "-10" },
|
Chris@1415
|
163 { -8, "-8" },
|
Chris@1415
|
164 { -6, "-6" },
|
Chris@1415
|
165 { -4, "-4" },
|
Chris@1415
|
166 { -2, "-2" },
|
Chris@1415
|
167 { 0, "0" }
|
Chris@1411
|
168 };
|
Chris@1417
|
169 compareTicks(ticks, expected);
|
Chris@1411
|
170 }
|
Chris@1411
|
171
|
Chris@1407
|
172 void linear_0_0p1_5()
|
Chris@1407
|
173 {
|
Chris@1407
|
174 auto ticks = ScaleTickIntervals::linear({ 0, 0.1, 5 });
|
Chris@1417
|
175 ScaleTickIntervals::Ticks expected {
|
Chris@1409
|
176 { 0.00, "0.00" },
|
Chris@1407
|
177 { 0.02, "0.02" },
|
Chris@1407
|
178 { 0.04, "0.04" },
|
Chris@1407
|
179 { 0.06, "0.06" },
|
Chris@1407
|
180 { 0.08, "0.08" },
|
Chris@1409
|
181 { 0.10, "0.10" }
|
Chris@1407
|
182 };
|
Chris@1417
|
183 compareTicks(ticks, expected);
|
Chris@1407
|
184 }
|
Chris@1407
|
185
|
Chris@1407
|
186 void linear_0_0p01_5()
|
Chris@1407
|
187 {
|
Chris@1407
|
188 auto ticks = ScaleTickIntervals::linear({ 0, 0.01, 5 });
|
Chris@1417
|
189 ScaleTickIntervals::Ticks expected {
|
Chris@1409
|
190 { 0.000, "0.000" },
|
Chris@1407
|
191 { 0.002, "0.002" },
|
Chris@1407
|
192 { 0.004, "0.004" },
|
Chris@1407
|
193 { 0.006, "0.006" },
|
Chris@1407
|
194 { 0.008, "0.008" },
|
Chris@1409
|
195 { 0.010, "0.010" }
|
Chris@1409
|
196 };
|
Chris@1417
|
197 compareTicks(ticks, expected);
|
Chris@1409
|
198 }
|
Chris@1409
|
199
|
Chris@1409
|
200 void linear_0_0p005_5()
|
Chris@1409
|
201 {
|
Chris@1409
|
202 auto ticks = ScaleTickIntervals::linear({ 0, 0.005, 5 });
|
Chris@1417
|
203 ScaleTickIntervals::Ticks expected {
|
Chris@1409
|
204 { 0.000, "0.000" },
|
Chris@1409
|
205 { 0.001, "0.001" },
|
Chris@1409
|
206 { 0.002, "0.002" },
|
Chris@1409
|
207 { 0.003, "0.003" },
|
Chris@1409
|
208 { 0.004, "0.004" },
|
Chris@1409
|
209 { 0.005, "0.005" }
|
Chris@1407
|
210 };
|
Chris@1417
|
211 compareTicks(ticks, expected);
|
Chris@1407
|
212 }
|
Chris@1407
|
213
|
Chris@1407
|
214 void linear_0_0p001_5()
|
Chris@1407
|
215 {
|
Chris@1407
|
216 auto ticks = ScaleTickIntervals::linear({ 0, 0.001, 5 });
|
Chris@1417
|
217 ScaleTickIntervals::Ticks expected {
|
Chris@1409
|
218 { 0.0000, "0.0e+00" },
|
Chris@1407
|
219 { 0.0002, "2.0e-04" },
|
Chris@1407
|
220 { 0.0004, "4.0e-04" },
|
Chris@1407
|
221 { 0.0006, "6.0e-04" },
|
Chris@1407
|
222 { 0.0008, "8.0e-04" },
|
Chris@1409
|
223 { 0.0010, "1.0e-03" }
|
Chris@1407
|
224 };
|
Chris@1417
|
225 compareTicks(ticks, expected);
|
Chris@1407
|
226 }
|
Chris@1407
|
227
|
Chris@1407
|
228 void linear_1_1p001_5()
|
Chris@1407
|
229 {
|
Chris@1407
|
230 auto ticks = ScaleTickIntervals::linear({ 1, 1.001, 5 });
|
Chris@1417
|
231 ScaleTickIntervals::Ticks expected {
|
Chris@1409
|
232 { 1.0000, "1.0000" },
|
Chris@1407
|
233 { 1.0002, "1.0002" },
|
Chris@1407
|
234 { 1.0004, "1.0004" },
|
Chris@1407
|
235 { 1.0006, "1.0006" },
|
Chris@1407
|
236 { 1.0008, "1.0008" },
|
Chris@1409
|
237 { 1.0010, "1.0010" }
|
Chris@1409
|
238 };
|
Chris@1417
|
239 compareTicks(ticks, expected);
|
Chris@1409
|
240 }
|
Chris@1409
|
241
|
Chris@1413
|
242 void linear_0p001_1_5()
|
Chris@1413
|
243 {
|
Chris@1413
|
244 auto ticks = ScaleTickIntervals::linear({ 0.001, 1, 5 });
|
Chris@1417
|
245 ScaleTickIntervals::Ticks expected {
|
Chris@1413
|
246 { 0.1, "0.1" },
|
Chris@1413
|
247 { 0.3, "0.3" },
|
Chris@1413
|
248 { 0.5, "0.5" },
|
Chris@1413
|
249 { 0.7, "0.7" },
|
Chris@1413
|
250 { 0.9, "0.9" },
|
Chris@1413
|
251 };
|
Chris@1417
|
252 compareTicks(ticks, expected);
|
Chris@1413
|
253 }
|
Chris@1413
|
254
|
Chris@1409
|
255 void linear_10000_10010_5()
|
Chris@1409
|
256 {
|
Chris@1409
|
257 auto ticks = ScaleTickIntervals::linear({ 10000, 10010, 5 });
|
Chris@1417
|
258 ScaleTickIntervals::Ticks expected {
|
Chris@1415
|
259 { 10000, "10000" },
|
Chris@1415
|
260 { 10002, "10002" },
|
Chris@1415
|
261 { 10004, "10004" },
|
Chris@1415
|
262 { 10006, "10006" },
|
Chris@1415
|
263 { 10008, "10008" },
|
Chris@1415
|
264 { 10010, "10010" },
|
Chris@1409
|
265 };
|
Chris@1417
|
266 compareTicks(ticks, expected);
|
Chris@1409
|
267 }
|
Chris@1409
|
268
|
Chris@1409
|
269 void linear_10000_20000_5()
|
Chris@1409
|
270 {
|
Chris@1409
|
271 auto ticks = ScaleTickIntervals::linear({ 10000, 20000, 5 });
|
Chris@1417
|
272 ScaleTickIntervals::Ticks expected {
|
Chris@1409
|
273 { 10000, "10000" },
|
Chris@1409
|
274 { 12000, "12000" },
|
Chris@1409
|
275 { 14000, "14000" },
|
Chris@1409
|
276 { 16000, "16000" },
|
Chris@1409
|
277 { 18000, "18000" },
|
Chris@1409
|
278 { 20000, "20000" },
|
Chris@1409
|
279 };
|
Chris@1417
|
280 compareTicks(ticks, expected);
|
Chris@1409
|
281 }
|
Chris@1409
|
282
|
Chris@1409
|
283 void linear_m1_1_10()
|
Chris@1409
|
284 {
|
Chris@1409
|
285 auto ticks = ScaleTickIntervals::linear({ -1, 1, 10 });
|
Chris@1417
|
286 ScaleTickIntervals::Ticks expected {
|
Chris@1409
|
287 { -1.0, "-1.0" },
|
Chris@1409
|
288 { -0.8, "-0.8" },
|
Chris@1409
|
289 { -0.6, "-0.6" },
|
Chris@1409
|
290 { -0.4, "-0.4" },
|
Chris@1409
|
291 { -0.2, "-0.2" },
|
Chris@1409
|
292 { 0.0, "0.0" },
|
Chris@1409
|
293 { 0.2, "0.2" },
|
Chris@1409
|
294 { 0.4, "0.4" },
|
Chris@1409
|
295 { 0.6, "0.6" },
|
Chris@1409
|
296 { 0.8, "0.8" },
|
Chris@1409
|
297 { 1.0, "1.0" }
|
Chris@1407
|
298 };
|
Chris@1417
|
299 compareTicks(ticks, expected);
|
Chris@1407
|
300 }
|
Chris@1411
|
301
|
Chris@1411
|
302 void linear_221p23_623p7_57p4()
|
Chris@1411
|
303 {
|
Chris@1411
|
304 auto ticks = ScaleTickIntervals::linear({ 221.23, 623.7, 4 });
|
Chris@1411
|
305 // only 4 ticks, not 5, because none of the rounded tick
|
Chris@1411
|
306 // values lies on an end value
|
Chris@1417
|
307 ScaleTickIntervals::Ticks expected {
|
Chris@1411
|
308 { 230, "230" },
|
Chris@1411
|
309 { 330, "330" },
|
Chris@1411
|
310 { 430, "430" },
|
Chris@1411
|
311 { 530, "530" },
|
Chris@1411
|
312 };
|
Chris@1417
|
313 compareTicks(ticks, expected);
|
Chris@1411
|
314 }
|
Chris@1411
|
315
|
Chris@1412
|
316 void linear_sqrt2_pi_7()
|
Chris@1412
|
317 {
|
Chris@1412
|
318 auto ticks = ScaleTickIntervals::linear({ sqrt(2.0), M_PI, 7 });
|
Chris@1412
|
319 // This would be better in steps of 0.25, but we only round to
|
Chris@1412
|
320 // integral powers of ten
|
Chris@1417
|
321 ScaleTickIntervals::Ticks expected {
|
Chris@1412
|
322 { 1.5, "1.5" },
|
Chris@1412
|
323 { 1.7, "1.7" },
|
Chris@1412
|
324 { 1.9, "1.9" },
|
Chris@1412
|
325 { 2.1, "2.1" },
|
Chris@1412
|
326 { 2.3, "2.3" },
|
Chris@1412
|
327 { 2.5, "2.5" },
|
Chris@1412
|
328 { 2.7, "2.7" },
|
Chris@1412
|
329 { 2.9, "2.9" },
|
Chris@1412
|
330 { 3.1, "3.1" },
|
Chris@1412
|
331 };
|
Chris@1417
|
332 compareTicks(ticks, expected);
|
Chris@1412
|
333 }
|
Chris@1412
|
334
|
Chris@1412
|
335 void linear_pi_avogadro_7()
|
Chris@1412
|
336 {
|
Chris@1412
|
337 auto ticks = ScaleTickIntervals::linear({ M_PI, 6.022140857e23, 7 });
|
Chris@1417
|
338 ScaleTickIntervals::Ticks expected {
|
Chris@1413
|
339 { 1e+21, "1.000e+21" },
|
Chris@1413
|
340 { 8.7e+22, "8.700e+22" },
|
Chris@1413
|
341 { 1.73e+23, "1.730e+23" },
|
Chris@1413
|
342 { 2.59e+23, "2.590e+23" },
|
Chris@1413
|
343 { 3.45e+23, "3.450e+23" },
|
Chris@1413
|
344 { 4.31e+23, "4.310e+23" },
|
Chris@1413
|
345 { 5.17e+23, "5.170e+23" },
|
Chris@1412
|
346 };
|
Chris@1417
|
347 compareTicks(ticks, expected);
|
Chris@1412
|
348 }
|
Chris@1412
|
349
|
Chris@1412
|
350 void linear_2_3_1()
|
Chris@1412
|
351 {
|
Chris@1412
|
352 auto ticks = ScaleTickIntervals::linear({ 2, 3, 1 });
|
Chris@1417
|
353 ScaleTickIntervals::Ticks expected {
|
Chris@1415
|
354 { 2.0, "2" },
|
Chris@1415
|
355 { 3.0, "3" }
|
Chris@1412
|
356 };
|
Chris@1417
|
357 compareTicks(ticks, expected);
|
Chris@1412
|
358 }
|
Chris@1412
|
359
|
Chris@1412
|
360 void linear_2_3_2()
|
Chris@1412
|
361 {
|
Chris@1412
|
362 auto ticks = ScaleTickIntervals::linear({ 2, 3, 2 });
|
Chris@1417
|
363 ScaleTickIntervals::Ticks expected {
|
Chris@1412
|
364 { 2.0, "2.0" },
|
Chris@1412
|
365 { 2.5, "2.5" },
|
Chris@1412
|
366 { 3.0, "3.0" }
|
Chris@1412
|
367 };
|
Chris@1417
|
368 compareTicks(ticks, expected);
|
Chris@1412
|
369 }
|
Chris@1412
|
370
|
Chris@1412
|
371 void linear_2_3_3()
|
Chris@1412
|
372 {
|
Chris@1412
|
373 auto ticks = ScaleTickIntervals::linear({ 2, 3, 3 });
|
Chris@1417
|
374 ScaleTickIntervals::Ticks expected {
|
Chris@1412
|
375 { 2.0, "2.0" },
|
Chris@1412
|
376 { 2.3, "2.3" },
|
Chris@1412
|
377 { 2.6, "2.6" },
|
Chris@1412
|
378 { 2.9, "2.9" }
|
Chris@1412
|
379 };
|
Chris@1417
|
380 compareTicks(ticks, expected);
|
Chris@1412
|
381 }
|
Chris@1412
|
382
|
Chris@1412
|
383 void linear_2_3_4()
|
Chris@1412
|
384 {
|
Chris@1412
|
385 auto ticks = ScaleTickIntervals::linear({ 2, 3, 4 });
|
Chris@1412
|
386 // This would be better in steps of 0.25, but we only round to
|
Chris@1412
|
387 // integral powers of ten
|
Chris@1417
|
388 ScaleTickIntervals::Ticks expected {
|
Chris@1412
|
389 { 2.0, "2.0" },
|
Chris@1412
|
390 { 2.3, "2.3" },
|
Chris@1412
|
391 { 2.6, "2.6" },
|
Chris@1412
|
392 { 2.9, "2.9" }
|
Chris@1412
|
393 };
|
Chris@1417
|
394 compareTicks(ticks, expected);
|
Chris@1412
|
395 }
|
Chris@1412
|
396
|
Chris@1412
|
397 void linear_2_3_5()
|
Chris@1412
|
398 {
|
Chris@1412
|
399 auto ticks = ScaleTickIntervals::linear({ 2, 3, 5 });
|
Chris@1417
|
400 ScaleTickIntervals::Ticks expected {
|
Chris@1412
|
401 { 2.0, "2.0" },
|
Chris@1412
|
402 { 2.2, "2.2" },
|
Chris@1412
|
403 { 2.4, "2.4" },
|
Chris@1412
|
404 { 2.6, "2.6" },
|
Chris@1412
|
405 { 2.8, "2.8" },
|
Chris@1412
|
406 { 3.0, "3.0" }
|
Chris@1412
|
407 };
|
Chris@1417
|
408 compareTicks(ticks, expected);
|
Chris@1412
|
409 }
|
Chris@1412
|
410
|
Chris@1412
|
411 void linear_2_3_6()
|
Chris@1412
|
412 {
|
Chris@1412
|
413 auto ticks = ScaleTickIntervals::linear({ 2, 3, 6 });
|
Chris@1417
|
414 ScaleTickIntervals::Ticks expected {
|
Chris@1412
|
415 { 2.0, "2.0" },
|
Chris@1412
|
416 { 2.2, "2.2" },
|
Chris@1412
|
417 { 2.4, "2.4" },
|
Chris@1412
|
418 { 2.6, "2.6" },
|
Chris@1412
|
419 { 2.8, "2.8" },
|
Chris@1412
|
420 { 3.0, "3.0" }
|
Chris@1412
|
421 };
|
Chris@1417
|
422 compareTicks(ticks, expected);
|
Chris@1412
|
423 }
|
Chris@1412
|
424
|
Chris@1411
|
425 void linear_1_1_10()
|
Chris@1411
|
426 {
|
Chris@1415
|
427 // pathological range
|
Chris@1411
|
428 auto ticks = ScaleTickIntervals::linear({ 1, 1, 10 });
|
Chris@1417
|
429 ScaleTickIntervals::Ticks expected {
|
Chris@1411
|
430 { 1.0, "1.0" }
|
Chris@1411
|
431 };
|
Chris@1417
|
432 compareTicks(ticks, expected);
|
Chris@1411
|
433 }
|
Chris@1411
|
434
|
Chris@1411
|
435 void linear_0_0_10()
|
Chris@1411
|
436 {
|
Chris@1415
|
437 // pathological range
|
Chris@1411
|
438 auto ticks = ScaleTickIntervals::linear({ 0, 0, 10 });
|
Chris@1417
|
439 ScaleTickIntervals::Ticks expected {
|
Chris@1411
|
440 { 0.0, "0.0" }
|
Chris@1411
|
441 };
|
Chris@1417
|
442 compareTicks(ticks, expected);
|
Chris@1411
|
443 }
|
Chris@1411
|
444
|
Chris@1411
|
445 void linear_0_1_1()
|
Chris@1411
|
446 {
|
Chris@1411
|
447 auto ticks = ScaleTickIntervals::linear({ 0, 1, 1 });
|
Chris@1417
|
448 ScaleTickIntervals::Ticks expected {
|
Chris@1415
|
449 { 0.0, "0" },
|
Chris@1415
|
450 { 1.0, "1" }
|
Chris@1411
|
451 };
|
Chris@1417
|
452 compareTicks(ticks, expected);
|
Chris@1411
|
453 }
|
Chris@1411
|
454
|
Chris@1411
|
455 void linear_0_1_0()
|
Chris@1411
|
456 {
|
Chris@1416
|
457 // senseless input
|
Chris@1411
|
458 auto ticks = ScaleTickIntervals::linear({ 0, 1, 0 });
|
Chris@1417
|
459 ScaleTickIntervals::Ticks expected {
|
Chris@1411
|
460 };
|
Chris@1417
|
461 compareTicks(ticks, expected);
|
Chris@1411
|
462 }
|
Chris@1411
|
463
|
Chris@1411
|
464 void linear_0_1_m1()
|
Chris@1411
|
465 {
|
Chris@1416
|
466 // senseless input
|
Chris@1411
|
467 auto ticks = ScaleTickIntervals::linear({ 0, 1, -1 });
|
Chris@1417
|
468 ScaleTickIntervals::Ticks expected {
|
Chris@1411
|
469 };
|
Chris@1417
|
470 compareTicks(ticks, expected);
|
Chris@1411
|
471 }
|
Chris@1414
|
472
|
Chris@1416
|
473 void linear_0p465_778_10()
|
Chris@1416
|
474 {
|
Chris@1416
|
475 // a case that gave unsatisfactory results in real life
|
Chris@1416
|
476 auto ticks = ScaleTickIntervals::linear({ 0.465, 778.08, 10 });
|
Chris@1417
|
477 ScaleTickIntervals::Ticks expected {
|
Chris@1416
|
478 };
|
Chris@1417
|
479 compareTicks(ticks, expected);
|
Chris@1416
|
480 }
|
Chris@1416
|
481
|
Chris@1414
|
482 void log_1_10_2()
|
Chris@1414
|
483 {
|
Chris@1414
|
484 auto ticks = ScaleTickIntervals::logarithmic({ 1, 10, 2 });
|
Chris@1417
|
485 ScaleTickIntervals::Ticks expected {
|
Chris@1414
|
486 { 1.0, "1.0" },
|
Chris@1414
|
487 { pow(10.0, 0.5), "3.2" },
|
Chris@1414
|
488 { 10.0, "10.0" },
|
Chris@1414
|
489 };
|
Chris@1417
|
490 compareTicks(ticks, expected);
|
Chris@1414
|
491 }
|
Chris@1414
|
492
|
Chris@1414
|
493 void log_0_10_2()
|
Chris@1414
|
494 {
|
Chris@1414
|
495 auto ticks = ScaleTickIntervals::logarithmic({ 0, 10, 2 });
|
Chris@1417
|
496 ScaleTickIntervals::Ticks expected {
|
Chris@1415
|
497 { 1e-10, "1e-10" },
|
Chris@1415
|
498 { pow(10.0, -4.5), "3e-05" },
|
Chris@1415
|
499 { 10.0, "1e+01" },
|
Chris@1414
|
500 };
|
Chris@1417
|
501 compareTicks(ticks, expected);
|
Chris@1414
|
502 }
|
Chris@1415
|
503
|
Chris@1415
|
504 void log_pi_avogadro_7()
|
Chris@1415
|
505 {
|
Chris@1415
|
506 auto ticks = ScaleTickIntervals::logarithmic({ M_PI, 6.022140857e23, 7 });
|
Chris@1417
|
507 ScaleTickIntervals::Ticks expected {
|
Chris@1415
|
508 { 3.16228, "3e+00" },
|
Chris@1415
|
509 { 6309.57, "6e+03" },
|
Chris@1415
|
510 { 1.25893e+07, "1e+07" },
|
Chris@1415
|
511 { 2.51189e+10, "3e+10" },
|
Chris@1415
|
512 { 5.01187e+13, "5e+13" },
|
Chris@1415
|
513 { 1e+17, "1e+17" },
|
Chris@1415
|
514 { 1.99526e+20, "2e+20" },
|
Chris@1415
|
515 { 3.98107e+23, "4e+23" },
|
Chris@1415
|
516 };
|
Chris@1417
|
517 compareTicks(ticks, expected, true);
|
Chris@1415
|
518 }
|
Chris@1407
|
519 };
|
Chris@1407
|
520
|
Chris@1407
|
521 #endif
|
Chris@1407
|
522
|
Chris@1407
|
523
|