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@1429
|
33 vector<ScaleTickIntervals::Tick> expected) {
|
Chris@1407
|
34
|
Chris@1428
|
35 SVCERR << "Have " << ticks.size() << " ticks, expected "
|
Chris@1429
|
36 << expected.size() << endl;
|
Chris@1429
|
37 for (int i = 0; i < int(ticks.size()); ++i) {
|
Chris@1428
|
38 SVCERR << i << ": have " << ticks[i].value << " \""
|
Chris@1411
|
39 << ticks[i].label << "\", expected ";
|
Chris@1429
|
40 if (i < int(expected.size())) {
|
Chris@1428
|
41 SVCERR << expected[i].value << " \"" << expected[i].label
|
Chris@1429
|
42 << "\"" << endl;
|
Chris@1411
|
43 } else {
|
Chris@1428
|
44 SVCERR << "(n/a)" << endl;
|
Chris@1429
|
45 }
|
Chris@1429
|
46 }
|
Chris@1407
|
47 }
|
Chris@1407
|
48
|
Chris@1417
|
49 void compareTicks(ScaleTickIntervals::Ticks ticks,
|
Chris@1429
|
50 ScaleTickIntervals::Ticks expected,
|
Chris@1415
|
51 bool fuzzier = false)
|
Chris@1407
|
52 {
|
Chris@1408
|
53 double eps = 1e-7;
|
Chris@1429
|
54 for (int i = 0; i < int(expected.size()); ++i) {
|
Chris@1429
|
55 if (i < int(ticks.size())) {
|
Chris@1415
|
56 bool pass = true;
|
Chris@1429
|
57 if (ticks[i].label != expected[i].label) {
|
Chris@1415
|
58 pass = false;
|
Chris@1415
|
59 } else if (!fuzzier) {
|
Chris@1429
|
60 if (fabs(ticks[i].value - expected[i].value) > eps) {
|
Chris@1415
|
61 pass = false;
|
Chris@1415
|
62 }
|
Chris@1415
|
63 } else {
|
Chris@1429
|
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@1429
|
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@1429
|
74 }
|
Chris@1429
|
75 }
|
Chris@1408
|
76 if (ticks.size() != expected.size()) {
|
Chris@1408
|
77 printDiff(ticks, expected);
|
Chris@1408
|
78 }
|
Chris@1429
|
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@1429
|
85 auto ticks = ScaleTickIntervals::linear({ 0, 1, 10 });
|
Chris@1429
|
86 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
87 { 0.0, "0.0" },
|
Chris@1429
|
88 { 0.1, "0.1" },
|
Chris@1429
|
89 { 0.2, "0.2" },
|
Chris@1429
|
90 { 0.3, "0.3" },
|
Chris@1429
|
91 { 0.4, "0.4" },
|
Chris@1429
|
92 { 0.5, "0.5" },
|
Chris@1429
|
93 { 0.6, "0.6" },
|
Chris@1429
|
94 { 0.7, "0.7" },
|
Chris@1429
|
95 { 0.8, "0.8" },
|
Chris@1429
|
96 { 0.9, "0.9" },
|
Chris@1429
|
97 { 1.0, "1.0" }
|
Chris@1429
|
98 };
|
Chris@1429
|
99 compareTicks(ticks, expected);
|
Chris@1409
|
100 }
|
Chris@1409
|
101
|
Chris@1409
|
102 void linear_0_5_5()
|
Chris@1409
|
103 {
|
Chris@1429
|
104 auto ticks = ScaleTickIntervals::linear({ 0, 5, 5 });
|
Chris@1429
|
105 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
106 { 0, "0" },
|
Chris@1429
|
107 { 1, "1" },
|
Chris@1429
|
108 { 2, "2" },
|
Chris@1429
|
109 { 3, "3" },
|
Chris@1429
|
110 { 4, "4" },
|
Chris@1429
|
111 { 5, "5" },
|
Chris@1429
|
112 };
|
Chris@1429
|
113 compareTicks(ticks, expected);
|
Chris@1409
|
114 }
|
Chris@1409
|
115
|
Chris@1409
|
116 void linear_0_10_5()
|
Chris@1409
|
117 {
|
Chris@1429
|
118 auto ticks = ScaleTickIntervals::linear({ 0, 10, 5 });
|
Chris@1429
|
119 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
120 { 0, "0" },
|
Chris@1429
|
121 { 2, "2" },
|
Chris@1429
|
122 { 4, "4" },
|
Chris@1429
|
123 { 6, "6" },
|
Chris@1429
|
124 { 8, "8" },
|
Chris@1429
|
125 { 10, "10" }
|
Chris@1429
|
126 };
|
Chris@1429
|
127 compareTicks(ticks, expected);
|
Chris@1407
|
128 }
|
Chris@1407
|
129
|
Chris@1411
|
130 void linear_10_0_5()
|
Chris@1411
|
131 {
|
Chris@1429
|
132 auto ticks = ScaleTickIntervals::linear({ 10, 0, 5 });
|
Chris@1429
|
133 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
134 { 0, "0" },
|
Chris@1429
|
135 { 2, "2" },
|
Chris@1429
|
136 { 4, "4" },
|
Chris@1429
|
137 { 6, "6" },
|
Chris@1429
|
138 { 8, "8" },
|
Chris@1429
|
139 { 10, "10" }
|
Chris@1429
|
140 };
|
Chris@1429
|
141 compareTicks(ticks, expected);
|
Chris@1411
|
142 }
|
Chris@1411
|
143
|
Chris@1411
|
144 void linear_m10_0_5()
|
Chris@1411
|
145 {
|
Chris@1429
|
146 auto ticks = ScaleTickIntervals::linear({ -10, 0, 5 });
|
Chris@1429
|
147 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
148 { -10, "-10" },
|
Chris@1429
|
149 { -8, "-8" },
|
Chris@1429
|
150 { -6, "-6" },
|
Chris@1429
|
151 { -4, "-4" },
|
Chris@1429
|
152 { -2, "-2" },
|
Chris@1429
|
153 { 0, "0" }
|
Chris@1429
|
154 };
|
Chris@1429
|
155 compareTicks(ticks, expected);
|
Chris@1411
|
156 }
|
Chris@1411
|
157
|
Chris@1411
|
158 void linear_0_m10_5()
|
Chris@1411
|
159 {
|
Chris@1429
|
160 auto ticks = ScaleTickIntervals::linear({ 0, -10, 5 });
|
Chris@1429
|
161 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
162 { -10, "-10" },
|
Chris@1429
|
163 { -8, "-8" },
|
Chris@1429
|
164 { -6, "-6" },
|
Chris@1429
|
165 { -4, "-4" },
|
Chris@1429
|
166 { -2, "-2" },
|
Chris@1429
|
167 { 0, "0" }
|
Chris@1429
|
168 };
|
Chris@1429
|
169 compareTicks(ticks, expected);
|
Chris@1411
|
170 }
|
Chris@1411
|
171
|
Chris@1407
|
172 void linear_0_0p1_5()
|
Chris@1407
|
173 {
|
Chris@1429
|
174 auto ticks = ScaleTickIntervals::linear({ 0, 0.1, 5 });
|
Chris@1429
|
175 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
176 { 0.00, "0.00" },
|
Chris@1429
|
177 { 0.02, "0.02" },
|
Chris@1429
|
178 { 0.04, "0.04" },
|
Chris@1429
|
179 { 0.06, "0.06" },
|
Chris@1429
|
180 { 0.08, "0.08" },
|
Chris@1429
|
181 { 0.10, "0.10" }
|
Chris@1429
|
182 };
|
Chris@1429
|
183 compareTicks(ticks, expected);
|
Chris@1407
|
184 }
|
Chris@1407
|
185
|
Chris@1407
|
186 void linear_0_0p01_5()
|
Chris@1407
|
187 {
|
Chris@1429
|
188 auto ticks = ScaleTickIntervals::linear({ 0, 0.01, 5 });
|
Chris@1429
|
189 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
190 { 0.000, "0.000" },
|
Chris@1429
|
191 { 0.002, "0.002" },
|
Chris@1429
|
192 { 0.004, "0.004" },
|
Chris@1429
|
193 { 0.006, "0.006" },
|
Chris@1429
|
194 { 0.008, "0.008" },
|
Chris@1429
|
195 { 0.010, "0.010" }
|
Chris@1429
|
196 };
|
Chris@1429
|
197 compareTicks(ticks, expected);
|
Chris@1409
|
198 }
|
Chris@1409
|
199
|
Chris@1409
|
200 void linear_0_0p005_5()
|
Chris@1409
|
201 {
|
Chris@1429
|
202 auto ticks = ScaleTickIntervals::linear({ 0, 0.005, 5 });
|
Chris@1429
|
203 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
204 { 0.000, "0.000" },
|
Chris@1429
|
205 { 0.001, "0.001" },
|
Chris@1429
|
206 { 0.002, "0.002" },
|
Chris@1429
|
207 { 0.003, "0.003" },
|
Chris@1429
|
208 { 0.004, "0.004" },
|
Chris@1429
|
209 { 0.005, "0.005" }
|
Chris@1429
|
210 };
|
Chris@1429
|
211 compareTicks(ticks, expected);
|
Chris@1407
|
212 }
|
Chris@1407
|
213
|
Chris@1407
|
214 void linear_0_0p001_5()
|
Chris@1407
|
215 {
|
Chris@1429
|
216 auto ticks = ScaleTickIntervals::linear({ 0, 0.001, 5 });
|
Chris@1429
|
217 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
218 { 0.0000, "0.0e+00" },
|
Chris@1429
|
219 { 0.0002, "2.0e-04" },
|
Chris@1429
|
220 { 0.0004, "4.0e-04" },
|
Chris@1429
|
221 { 0.0006, "6.0e-04" },
|
Chris@1429
|
222 { 0.0008, "8.0e-04" },
|
Chris@1429
|
223 { 0.0010, "1.0e-03" }
|
Chris@1429
|
224 };
|
Chris@1429
|
225 compareTicks(ticks, expected);
|
Chris@1407
|
226 }
|
Chris@1407
|
227
|
Chris@1407
|
228 void linear_1_1p001_5()
|
Chris@1407
|
229 {
|
Chris@1429
|
230 auto ticks = ScaleTickIntervals::linear({ 1, 1.001, 5 });
|
Chris@1429
|
231 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
232 { 1.0000, "1.0000" },
|
Chris@1429
|
233 { 1.0002, "1.0002" },
|
Chris@1429
|
234 { 1.0004, "1.0004" },
|
Chris@1429
|
235 { 1.0006, "1.0006" },
|
Chris@1429
|
236 { 1.0008, "1.0008" },
|
Chris@1429
|
237 { 1.0010, "1.0010" }
|
Chris@1429
|
238 };
|
Chris@1429
|
239 compareTicks(ticks, expected);
|
Chris@1409
|
240 }
|
Chris@1409
|
241
|
Chris@1413
|
242 void linear_0p001_1_5()
|
Chris@1413
|
243 {
|
Chris@1429
|
244 auto ticks = ScaleTickIntervals::linear({ 0.001, 1, 5 });
|
Chris@1429
|
245 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
246 { 0.1, "0.1" },
|
Chris@1429
|
247 { 0.3, "0.3" },
|
Chris@1429
|
248 { 0.5, "0.5" },
|
Chris@1429
|
249 { 0.7, "0.7" },
|
Chris@1429
|
250 { 0.9, "0.9" },
|
Chris@1429
|
251 };
|
Chris@1429
|
252 compareTicks(ticks, expected);
|
Chris@1413
|
253 }
|
Chris@1413
|
254
|
Chris@1409
|
255 void linear_10000_10010_5()
|
Chris@1409
|
256 {
|
Chris@1429
|
257 auto ticks = ScaleTickIntervals::linear({ 10000, 10010, 5 });
|
Chris@1429
|
258 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
259 { 10000, "10000" },
|
Chris@1429
|
260 { 10002, "10002" },
|
Chris@1429
|
261 { 10004, "10004" },
|
Chris@1429
|
262 { 10006, "10006" },
|
Chris@1429
|
263 { 10008, "10008" },
|
Chris@1429
|
264 { 10010, "10010" },
|
Chris@1429
|
265 };
|
Chris@1429
|
266 compareTicks(ticks, expected);
|
Chris@1409
|
267 }
|
Chris@1409
|
268
|
Chris@1409
|
269 void linear_10000_20000_5()
|
Chris@1409
|
270 {
|
Chris@1429
|
271 auto ticks = ScaleTickIntervals::linear({ 10000, 20000, 5 });
|
Chris@1429
|
272 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
273 { 10000, "10000" },
|
Chris@1429
|
274 { 12000, "12000" },
|
Chris@1429
|
275 { 14000, "14000" },
|
Chris@1429
|
276 { 16000, "16000" },
|
Chris@1429
|
277 { 18000, "18000" },
|
Chris@1429
|
278 { 20000, "20000" },
|
Chris@1429
|
279 };
|
Chris@1429
|
280 compareTicks(ticks, expected);
|
Chris@1409
|
281 }
|
Chris@1409
|
282
|
Chris@1409
|
283 void linear_m1_1_10()
|
Chris@1409
|
284 {
|
Chris@1429
|
285 auto ticks = ScaleTickIntervals::linear({ -1, 1, 10 });
|
Chris@1429
|
286 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
287 { -1.0, "-1.0" },
|
Chris@1429
|
288 { -0.8, "-0.8" },
|
Chris@1429
|
289 { -0.6, "-0.6" },
|
Chris@1429
|
290 { -0.4, "-0.4" },
|
Chris@1429
|
291 { -0.2, "-0.2" },
|
Chris@1429
|
292 { 0.0, "0.0" },
|
Chris@1429
|
293 { 0.2, "0.2" },
|
Chris@1429
|
294 { 0.4, "0.4" },
|
Chris@1429
|
295 { 0.6, "0.6" },
|
Chris@1429
|
296 { 0.8, "0.8" },
|
Chris@1429
|
297 { 1.0, "1.0" }
|
Chris@1429
|
298 };
|
Chris@1429
|
299 compareTicks(ticks, expected);
|
Chris@1407
|
300 }
|
Chris@1411
|
301
|
Chris@1411
|
302 void linear_221p23_623p7_57p4()
|
Chris@1411
|
303 {
|
Chris@1429
|
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@1429
|
307 ScaleTickIntervals::Ticks expected {
|
Chris@1418
|
308 { 300, "300" },
|
Chris@1418
|
309 { 400, "400" },
|
Chris@1418
|
310 { 500, "500" },
|
Chris@1418
|
311 { 600, "600" },
|
Chris@1429
|
312 };
|
Chris@1429
|
313 compareTicks(ticks, expected);
|
Chris@1411
|
314 }
|
Chris@1411
|
315
|
Chris@1412
|
316 void linear_sqrt2_pi_7()
|
Chris@1412
|
317 {
|
Chris@1429
|
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@1429
|
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@1429
|
331 };
|
Chris@1429
|
332 compareTicks(ticks, expected);
|
Chris@1412
|
333 }
|
Chris@1412
|
334
|
Chris@1412
|
335 void linear_pi_avogadro_7()
|
Chris@1412
|
336 {
|
Chris@1429
|
337 auto ticks = ScaleTickIntervals::linear({ M_PI, 6.022140857e23, 7 });
|
Chris@1429
|
338 ScaleTickIntervals::Ticks expected {
|
Chris@1418
|
339 // not perfect, but ok-ish
|
Chris@1421
|
340 { 0, "0.0e+00" },
|
Chris@1421
|
341 { 9e+22, "9.0e+22" },
|
Chris@1421
|
342 { 1.8e+23, "1.8e+23" },
|
Chris@1421
|
343 { 2.7e+23, "2.7e+23" },
|
Chris@1421
|
344 { 3.6e+23, "3.6e+23" },
|
Chris@1421
|
345 { 4.5e+23, "4.5e+23" },
|
Chris@1421
|
346 { 5.4e+23, "5.4e+23" },
|
Chris@1429
|
347 };
|
Chris@1429
|
348 compareTicks(ticks, expected);
|
Chris@1412
|
349 }
|
Chris@1412
|
350
|
Chris@1412
|
351 void linear_2_3_1()
|
Chris@1412
|
352 {
|
Chris@1429
|
353 auto ticks = ScaleTickIntervals::linear({ 2, 3, 1 });
|
Chris@1429
|
354 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
355 { 2.0, "2" },
|
Chris@1429
|
356 { 3.0, "3" }
|
Chris@1429
|
357 };
|
Chris@1429
|
358 compareTicks(ticks, expected);
|
Chris@1412
|
359 }
|
Chris@1412
|
360
|
Chris@1412
|
361 void linear_2_3_2()
|
Chris@1412
|
362 {
|
Chris@1429
|
363 auto ticks = ScaleTickIntervals::linear({ 2, 3, 2 });
|
Chris@1429
|
364 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
365 { 2.0, "2.0" },
|
Chris@1429
|
366 { 2.5, "2.5" },
|
Chris@1429
|
367 { 3.0, "3.0" }
|
Chris@1429
|
368 };
|
Chris@1429
|
369 compareTicks(ticks, expected);
|
Chris@1412
|
370 }
|
Chris@1412
|
371
|
Chris@1412
|
372 void linear_2_3_3()
|
Chris@1412
|
373 {
|
Chris@1429
|
374 auto ticks = ScaleTickIntervals::linear({ 2, 3, 3 });
|
Chris@1429
|
375 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
376 { 2.0, "2.0" },
|
Chris@1429
|
377 { 2.3, "2.3" },
|
Chris@1429
|
378 { 2.6, "2.6" },
|
Chris@1429
|
379 { 2.9, "2.9" }
|
Chris@1429
|
380 };
|
Chris@1429
|
381 compareTicks(ticks, expected);
|
Chris@1412
|
382 }
|
Chris@1412
|
383
|
Chris@1412
|
384 void linear_2_3_4()
|
Chris@1412
|
385 {
|
Chris@1429
|
386 auto ticks = ScaleTickIntervals::linear({ 2, 3, 4 });
|
Chris@1412
|
387 // This would be better in steps of 0.25, but we only round to
|
Chris@1412
|
388 // integral powers of ten
|
Chris@1429
|
389 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
390 { 2.0, "2.0" },
|
Chris@1429
|
391 { 2.3, "2.3" },
|
Chris@1429
|
392 { 2.6, "2.6" },
|
Chris@1429
|
393 { 2.9, "2.9" }
|
Chris@1429
|
394 };
|
Chris@1429
|
395 compareTicks(ticks, expected);
|
Chris@1412
|
396 }
|
Chris@1412
|
397
|
Chris@1412
|
398 void linear_2_3_5()
|
Chris@1412
|
399 {
|
Chris@1429
|
400 auto ticks = ScaleTickIntervals::linear({ 2, 3, 5 });
|
Chris@1429
|
401 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
402 { 2.0, "2.0" },
|
Chris@1429
|
403 { 2.2, "2.2" },
|
Chris@1429
|
404 { 2.4, "2.4" },
|
Chris@1429
|
405 { 2.6, "2.6" },
|
Chris@1429
|
406 { 2.8, "2.8" },
|
Chris@1429
|
407 { 3.0, "3.0" }
|
Chris@1429
|
408 };
|
Chris@1429
|
409 compareTicks(ticks, expected);
|
Chris@1412
|
410 }
|
Chris@1412
|
411
|
Chris@1412
|
412 void linear_2_3_6()
|
Chris@1412
|
413 {
|
Chris@1429
|
414 auto ticks = ScaleTickIntervals::linear({ 2, 3, 6 });
|
Chris@1429
|
415 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
416 { 2.0, "2.0" },
|
Chris@1429
|
417 { 2.2, "2.2" },
|
Chris@1429
|
418 { 2.4, "2.4" },
|
Chris@1429
|
419 { 2.6, "2.6" },
|
Chris@1429
|
420 { 2.8, "2.8" },
|
Chris@1429
|
421 { 3.0, "3.0" }
|
Chris@1429
|
422 };
|
Chris@1429
|
423 compareTicks(ticks, expected);
|
Chris@1412
|
424 }
|
Chris@1412
|
425
|
Chris@1411
|
426 void linear_1_1_10()
|
Chris@1411
|
427 {
|
Chris@1415
|
428 // pathological range
|
Chris@1429
|
429 auto ticks = ScaleTickIntervals::linear({ 1, 1, 10 });
|
Chris@1429
|
430 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
431 { 1.0, "1" }
|
Chris@1429
|
432 };
|
Chris@1429
|
433 compareTicks(ticks, expected);
|
Chris@1411
|
434 }
|
Chris@1411
|
435
|
Chris@1411
|
436 void linear_0_0_10()
|
Chris@1411
|
437 {
|
Chris@1415
|
438 // pathological range
|
Chris@1429
|
439 auto ticks = ScaleTickIntervals::linear({ 0, 0, 10 });
|
Chris@1429
|
440 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
441 { 0.0, "0" }
|
Chris@1429
|
442 };
|
Chris@1429
|
443 compareTicks(ticks, expected);
|
Chris@1411
|
444 }
|
Chris@1411
|
445
|
Chris@1411
|
446 void linear_0_1_1()
|
Chris@1411
|
447 {
|
Chris@1429
|
448 auto ticks = ScaleTickIntervals::linear({ 0, 1, 1 });
|
Chris@1429
|
449 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
450 { 0.0, "0" },
|
Chris@1429
|
451 { 1.0, "1" }
|
Chris@1429
|
452 };
|
Chris@1429
|
453 compareTicks(ticks, expected);
|
Chris@1411
|
454 }
|
Chris@1411
|
455
|
Chris@1411
|
456 void linear_0_1_0()
|
Chris@1411
|
457 {
|
Chris@1416
|
458 // senseless input
|
Chris@1429
|
459 auto ticks = ScaleTickIntervals::linear({ 0, 1, 0 });
|
Chris@1429
|
460 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
461 { 0.0, "0" },
|
Chris@1429
|
462 };
|
Chris@1429
|
463 compareTicks(ticks, expected);
|
Chris@1411
|
464 }
|
Chris@1411
|
465
|
Chris@1411
|
466 void linear_0_1_m1()
|
Chris@1411
|
467 {
|
Chris@1416
|
468 // senseless input
|
Chris@1429
|
469 auto ticks = ScaleTickIntervals::linear({ 0, 1, -1 });
|
Chris@1429
|
470 ScaleTickIntervals::Ticks expected {
|
Chris@1429
|
471 { 0.0, "0" },
|
Chris@1429
|
472 };
|
Chris@1429
|
473 compareTicks(ticks, expected);
|
Chris@1411
|
474 }
|
Chris@1414
|
475
|
Chris@1416
|
476 void linear_0p465_778_10()
|
Chris@1416
|
477 {
|
Chris@1416
|
478 // a case that gave unsatisfactory results in real life
|
Chris@1418
|
479 // (initially it had the first tick at 1)
|
Chris@1416
|
480 auto ticks = ScaleTickIntervals::linear({ 0.465, 778.08, 10 });
|
Chris@1417
|
481 ScaleTickIntervals::Ticks expected {
|
Chris@1418
|
482 { 10, "10" },
|
Chris@1418
|
483 { 90, "90" },
|
Chris@1418
|
484 { 170, "170" },
|
Chris@1418
|
485 { 250, "250" },
|
Chris@1418
|
486 { 330, "330" },
|
Chris@1418
|
487 { 410, "410" },
|
Chris@1418
|
488 { 490, "490" },
|
Chris@1418
|
489 { 570, "570" },
|
Chris@1418
|
490 { 650, "650" },
|
Chris@1418
|
491 { 730, "730" },
|
Chris@1416
|
492 };
|
Chris@1417
|
493 compareTicks(ticks, expected);
|
Chris@1416
|
494 }
|
Chris@1416
|
495
|
Chris@1414
|
496 void log_1_10_2()
|
Chris@1414
|
497 {
|
Chris@1414
|
498 auto ticks = ScaleTickIntervals::logarithmic({ 1, 10, 2 });
|
Chris@1429
|
499 ScaleTickIntervals::Ticks expected {
|
Chris@1414
|
500 { 1.0, "1.0" },
|
Chris@1414
|
501 { pow(10.0, 0.5), "3.2" },
|
Chris@1414
|
502 { 10.0, "10.0" },
|
Chris@1429
|
503 };
|
Chris@1429
|
504 compareTicks(ticks, expected);
|
Chris@1414
|
505 }
|
Chris@1414
|
506
|
Chris@1414
|
507 void log_0_10_2()
|
Chris@1414
|
508 {
|
Chris@1414
|
509 auto ticks = ScaleTickIntervals::logarithmic({ 0, 10, 2 });
|
Chris@1429
|
510 ScaleTickIntervals::Ticks expected {
|
Chris@1418
|
511 { 1e-6, "1e-06" },
|
Chris@1418
|
512 { 1, "1" },
|
Chris@1429
|
513 };
|
Chris@1429
|
514 compareTicks(ticks, expected);
|
Chris@1414
|
515 }
|
Chris@1415
|
516
|
Chris@1415
|
517 void log_pi_avogadro_7()
|
Chris@1415
|
518 {
|
Chris@1429
|
519 auto ticks = ScaleTickIntervals::logarithmic({ M_PI, 6.022140857e23, 7 });
|
Chris@1429
|
520 ScaleTickIntervals::Ticks expected {
|
Chris@1418
|
521 { 1000, "1e+03" },
|
Chris@1418
|
522 { 1e+06, "1e+06" },
|
Chris@1418
|
523 { 1e+09, "1e+09" },
|
Chris@1418
|
524 { 1e+12, "1e+12" },
|
Chris@1418
|
525 { 1e+15, "1e+15" },
|
Chris@1418
|
526 { 1e+18, "1e+18" },
|
Chris@1418
|
527 { 1e+21, "1e+21" },
|
Chris@1429
|
528 };
|
Chris@1429
|
529 compareTicks(ticks, expected, true);
|
Chris@1415
|
530 }
|
Chris@1418
|
531
|
Chris@1418
|
532 void log_0p465_778_10()
|
Chris@1418
|
533 {
|
Chris@1418
|
534 auto ticks = ScaleTickIntervals::logarithmic({ 0.465, 778.08, 10 });
|
Chris@1418
|
535 ScaleTickIntervals::Ticks expected {
|
Chris@1418
|
536 { 0.5, "0.5" },
|
Chris@1418
|
537 { 1, "1.0" },
|
Chris@1418
|
538 { 2, "2.0" },
|
Chris@1418
|
539 { 4, "4.0" },
|
Chris@1418
|
540 { 8, "8.0" },
|
Chris@1418
|
541 { 16, "16.0" },
|
Chris@1418
|
542 { 32, "32.0" },
|
Chris@1418
|
543 { 64, "64.0" },
|
Chris@1418
|
544 { 128, "128.0" },
|
Chris@1418
|
545 { 256, "256.0" },
|
Chris@1418
|
546 { 512, "512.0" },
|
Chris@1418
|
547 };
|
Chris@1418
|
548 compareTicks(ticks, expected);
|
Chris@1418
|
549 }
|
Chris@1418
|
550
|
Chris@1407
|
551 };
|
Chris@1407
|
552
|
Chris@1407
|
553 #endif
|
Chris@1407
|
554
|
Chris@1407
|
555
|