annotate base/test/TestScaleTickIntervals.h @ 1699:ad33d6c10738 single-point

Merge from default branch
author Chris Cannam
date Fri, 03 May 2019 13:44:45 +0100
parents 2b2b58ae8b59
children
rev   line source
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@1463 35 SVCERR << "Have " << ticks.size() << " ticks, expected "
Chris@1463 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@1463 39 << ticks[i].label << "\", expected ";
Chris@1429 40 if (i < int(expected.size())) {
Chris@1428 41 SVCERR << expected[i].value << " \"" << expected[i].label
Chris@1463 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@1429 53 for (int i = 0; i < int(expected.size()); ++i) {
Chris@1429 54 if (i < int(ticks.size())) {
Chris@1415 55 bool pass = true;
Chris@1429 56 if (ticks[i].label != expected[i].label) {
Chris@1415 57 pass = false;
Chris@1415 58 } else {
Chris@1463 59 double eps = fuzzier ? 1e-5 : 1e-10;
Chris@1463 60 double diff = fabs(ticks[i].value - expected[i].value);
Chris@1463 61 double limit = max(eps, fabs(ticks[i].value) * eps);
Chris@1463 62 if (diff > limit) {
Chris@1415 63 pass = false;
Chris@1415 64 }
Chris@1415 65 }
Chris@1415 66 if (!pass) {
Chris@1429 67 printDiff(ticks, expected);
Chris@1415 68 }
Chris@1463 69 QCOMPARE(ticks[i].label, expected[i].label);
Chris@1463 70 QCOMPARE(ticks[i].value, expected[i].value);
Chris@1429 71 }
Chris@1429 72 }
Chris@1408 73 if (ticks.size() != expected.size()) {
Chris@1408 74 printDiff(ticks, expected);
Chris@1408 75 }
Chris@1429 76 QCOMPARE(ticks.size(), expected.size());
Chris@1407 77 }
Chris@1407 78
Chris@1407 79 private slots:
Chris@1407 80 void linear_0_1_10()
Chris@1407 81 {
Chris@1429 82 auto ticks = ScaleTickIntervals::linear({ 0, 1, 10 });
Chris@1429 83 ScaleTickIntervals::Ticks expected {
Chris@1429 84 { 0.0, "0.0" },
Chris@1429 85 { 0.1, "0.1" },
Chris@1429 86 { 0.2, "0.2" },
Chris@1429 87 { 0.3, "0.3" },
Chris@1429 88 { 0.4, "0.4" },
Chris@1429 89 { 0.5, "0.5" },
Chris@1429 90 { 0.6, "0.6" },
Chris@1429 91 { 0.7, "0.7" },
Chris@1429 92 { 0.8, "0.8" },
Chris@1429 93 { 0.9, "0.9" },
Chris@1429 94 { 1.0, "1.0" }
Chris@1429 95 };
Chris@1429 96 compareTicks(ticks, expected);
Chris@1409 97 }
Chris@1409 98
Chris@1409 99 void linear_0_5_5()
Chris@1409 100 {
Chris@1429 101 auto ticks = ScaleTickIntervals::linear({ 0, 5, 5 });
Chris@1429 102 ScaleTickIntervals::Ticks expected {
Chris@1429 103 { 0, "0" },
Chris@1429 104 { 1, "1" },
Chris@1429 105 { 2, "2" },
Chris@1429 106 { 3, "3" },
Chris@1429 107 { 4, "4" },
Chris@1429 108 { 5, "5" },
Chris@1429 109 };
Chris@1429 110 compareTicks(ticks, expected);
Chris@1409 111 }
Chris@1409 112
Chris@1409 113 void linear_0_10_5()
Chris@1409 114 {
Chris@1429 115 auto ticks = ScaleTickIntervals::linear({ 0, 10, 5 });
Chris@1429 116 ScaleTickIntervals::Ticks expected {
Chris@1429 117 { 0, "0" },
Chris@1429 118 { 2, "2" },
Chris@1429 119 { 4, "4" },
Chris@1429 120 { 6, "6" },
Chris@1429 121 { 8, "8" },
Chris@1429 122 { 10, "10" }
Chris@1429 123 };
Chris@1429 124 compareTicks(ticks, expected);
Chris@1407 125 }
Chris@1407 126
Chris@1411 127 void linear_10_0_5()
Chris@1411 128 {
Chris@1429 129 auto ticks = ScaleTickIntervals::linear({ 10, 0, 5 });
Chris@1429 130 ScaleTickIntervals::Ticks expected {
Chris@1429 131 { 0, "0" },
Chris@1429 132 { 2, "2" },
Chris@1429 133 { 4, "4" },
Chris@1429 134 { 6, "6" },
Chris@1429 135 { 8, "8" },
Chris@1429 136 { 10, "10" }
Chris@1429 137 };
Chris@1429 138 compareTicks(ticks, expected);
Chris@1411 139 }
Chris@1411 140
Chris@1411 141 void linear_m10_0_5()
Chris@1411 142 {
Chris@1429 143 auto ticks = ScaleTickIntervals::linear({ -10, 0, 5 });
Chris@1429 144 ScaleTickIntervals::Ticks expected {
Chris@1429 145 { -10, "-10" },
Chris@1429 146 { -8, "-8" },
Chris@1429 147 { -6, "-6" },
Chris@1429 148 { -4, "-4" },
Chris@1429 149 { -2, "-2" },
Chris@1429 150 { 0, "0" }
Chris@1429 151 };
Chris@1429 152 compareTicks(ticks, expected);
Chris@1411 153 }
Chris@1411 154
Chris@1411 155 void linear_0_m10_5()
Chris@1411 156 {
Chris@1429 157 auto ticks = ScaleTickIntervals::linear({ 0, -10, 5 });
Chris@1429 158 ScaleTickIntervals::Ticks expected {
Chris@1429 159 { -10, "-10" },
Chris@1429 160 { -8, "-8" },
Chris@1429 161 { -6, "-6" },
Chris@1429 162 { -4, "-4" },
Chris@1429 163 { -2, "-2" },
Chris@1429 164 { 0, "0" }
Chris@1429 165 };
Chris@1429 166 compareTicks(ticks, expected);
Chris@1411 167 }
Chris@1411 168
Chris@1407 169 void linear_0_0p1_5()
Chris@1407 170 {
Chris@1429 171 auto ticks = ScaleTickIntervals::linear({ 0, 0.1, 5 });
Chris@1429 172 ScaleTickIntervals::Ticks expected {
Chris@1429 173 { 0.00, "0.00" },
Chris@1429 174 { 0.02, "0.02" },
Chris@1429 175 { 0.04, "0.04" },
Chris@1429 176 { 0.06, "0.06" },
Chris@1429 177 { 0.08, "0.08" },
Chris@1429 178 { 0.10, "0.10" }
Chris@1429 179 };
Chris@1429 180 compareTicks(ticks, expected);
Chris@1407 181 }
Chris@1407 182
Chris@1407 183 void linear_0_0p01_5()
Chris@1407 184 {
Chris@1429 185 auto ticks = ScaleTickIntervals::linear({ 0, 0.01, 5 });
Chris@1429 186 ScaleTickIntervals::Ticks expected {
Chris@1429 187 { 0.000, "0.000" },
Chris@1429 188 { 0.002, "0.002" },
Chris@1429 189 { 0.004, "0.004" },
Chris@1429 190 { 0.006, "0.006" },
Chris@1429 191 { 0.008, "0.008" },
Chris@1429 192 { 0.010, "0.010" }
Chris@1429 193 };
Chris@1429 194 compareTicks(ticks, expected);
Chris@1409 195 }
Chris@1409 196
Chris@1409 197 void linear_0_0p005_5()
Chris@1409 198 {
Chris@1429 199 auto ticks = ScaleTickIntervals::linear({ 0, 0.005, 5 });
Chris@1429 200 ScaleTickIntervals::Ticks expected {
Chris@1429 201 { 0.000, "0.000" },
Chris@1429 202 { 0.001, "0.001" },
Chris@1429 203 { 0.002, "0.002" },
Chris@1429 204 { 0.003, "0.003" },
Chris@1429 205 { 0.004, "0.004" },
Chris@1429 206 { 0.005, "0.005" }
Chris@1429 207 };
Chris@1429 208 compareTicks(ticks, expected);
Chris@1407 209 }
Chris@1407 210
Chris@1407 211 void linear_0_0p001_5()
Chris@1407 212 {
Chris@1429 213 auto ticks = ScaleTickIntervals::linear({ 0, 0.001, 5 });
Chris@1429 214 ScaleTickIntervals::Ticks expected {
Chris@1429 215 { 0.0000, "0.0e+00" },
Chris@1429 216 { 0.0002, "2.0e-04" },
Chris@1429 217 { 0.0004, "4.0e-04" },
Chris@1429 218 { 0.0006, "6.0e-04" },
Chris@1429 219 { 0.0008, "8.0e-04" },
Chris@1429 220 { 0.0010, "1.0e-03" }
Chris@1429 221 };
Chris@1429 222 compareTicks(ticks, expected);
Chris@1407 223 }
Chris@1407 224
Chris@1407 225 void linear_1_1p001_5()
Chris@1407 226 {
Chris@1429 227 auto ticks = ScaleTickIntervals::linear({ 1, 1.001, 5 });
Chris@1429 228 ScaleTickIntervals::Ticks expected {
Chris@1429 229 { 1.0000, "1.0000" },
Chris@1429 230 { 1.0002, "1.0002" },
Chris@1429 231 { 1.0004, "1.0004" },
Chris@1429 232 { 1.0006, "1.0006" },
Chris@1429 233 { 1.0008, "1.0008" },
Chris@1429 234 { 1.0010, "1.0010" }
Chris@1429 235 };
Chris@1429 236 compareTicks(ticks, expected);
Chris@1409 237 }
Chris@1409 238
Chris@1413 239 void linear_0p001_1_5()
Chris@1413 240 {
Chris@1429 241 auto ticks = ScaleTickIntervals::linear({ 0.001, 1, 5 });
Chris@1429 242 ScaleTickIntervals::Ticks expected {
Chris@1429 243 { 0.1, "0.1" },
Chris@1429 244 { 0.3, "0.3" },
Chris@1429 245 { 0.5, "0.5" },
Chris@1429 246 { 0.7, "0.7" },
Chris@1429 247 { 0.9, "0.9" },
Chris@1429 248 };
Chris@1429 249 compareTicks(ticks, expected);
Chris@1413 250 }
Chris@1413 251
Chris@1409 252 void linear_10000_10010_5()
Chris@1409 253 {
Chris@1429 254 auto ticks = ScaleTickIntervals::linear({ 10000, 10010, 5 });
Chris@1429 255 ScaleTickIntervals::Ticks expected {
Chris@1429 256 { 10000, "10000" },
Chris@1429 257 { 10002, "10002" },
Chris@1429 258 { 10004, "10004" },
Chris@1429 259 { 10006, "10006" },
Chris@1429 260 { 10008, "10008" },
Chris@1429 261 { 10010, "10010" },
Chris@1429 262 };
Chris@1429 263 compareTicks(ticks, expected);
Chris@1409 264 }
Chris@1409 265
Chris@1409 266 void linear_10000_20000_5()
Chris@1409 267 {
Chris@1429 268 auto ticks = ScaleTickIntervals::linear({ 10000, 20000, 5 });
Chris@1429 269 ScaleTickIntervals::Ticks expected {
Chris@1429 270 { 10000, "10000" },
Chris@1429 271 { 12000, "12000" },
Chris@1429 272 { 14000, "14000" },
Chris@1429 273 { 16000, "16000" },
Chris@1429 274 { 18000, "18000" },
Chris@1429 275 { 20000, "20000" },
Chris@1429 276 };
Chris@1429 277 compareTicks(ticks, expected);
Chris@1409 278 }
Chris@1409 279
Chris@1409 280 void linear_m1_1_10()
Chris@1409 281 {
Chris@1429 282 auto ticks = ScaleTickIntervals::linear({ -1, 1, 10 });
Chris@1429 283 ScaleTickIntervals::Ticks expected {
Chris@1429 284 { -1.0, "-1.0" },
Chris@1429 285 { -0.8, "-0.8" },
Chris@1429 286 { -0.6, "-0.6" },
Chris@1429 287 { -0.4, "-0.4" },
Chris@1429 288 { -0.2, "-0.2" },
Chris@1429 289 { 0.0, "0.0" },
Chris@1429 290 { 0.2, "0.2" },
Chris@1429 291 { 0.4, "0.4" },
Chris@1429 292 { 0.6, "0.6" },
Chris@1429 293 { 0.8, "0.8" },
Chris@1429 294 { 1.0, "1.0" }
Chris@1429 295 };
Chris@1429 296 compareTicks(ticks, expected);
Chris@1407 297 }
Chris@1411 298
Chris@1411 299 void linear_221p23_623p7_57p4()
Chris@1411 300 {
Chris@1429 301 auto ticks = ScaleTickIntervals::linear({ 221.23, 623.7, 4 });
Chris@1411 302 // only 4 ticks, not 5, because none of the rounded tick
Chris@1411 303 // values lies on an end value
Chris@1429 304 ScaleTickIntervals::Ticks expected {
Chris@1418 305 { 300, "300" },
Chris@1418 306 { 400, "400" },
Chris@1418 307 { 500, "500" },
Chris@1418 308 { 600, "600" },
Chris@1429 309 };
Chris@1429 310 compareTicks(ticks, expected);
Chris@1411 311 }
Chris@1411 312
Chris@1412 313 void linear_sqrt2_pi_7()
Chris@1412 314 {
Chris@1429 315 auto ticks = ScaleTickIntervals::linear({ sqrt(2.0), M_PI, 7 });
Chris@1412 316 // This would be better in steps of 0.25, but we only round to
Chris@1412 317 // integral powers of ten
Chris@1429 318 ScaleTickIntervals::Ticks expected {
Chris@1412 319 { 1.5, "1.5" },
Chris@1412 320 { 1.7, "1.7" },
Chris@1412 321 { 1.9, "1.9" },
Chris@1412 322 { 2.1, "2.1" },
Chris@1412 323 { 2.3, "2.3" },
Chris@1412 324 { 2.5, "2.5" },
Chris@1412 325 { 2.7, "2.7" },
Chris@1412 326 { 2.9, "2.9" },
Chris@1412 327 { 3.1, "3.1" },
Chris@1429 328 };
Chris@1429 329 compareTicks(ticks, expected);
Chris@1412 330 }
Chris@1412 331
Chris@1412 332 void linear_pi_avogadro_7()
Chris@1412 333 {
Chris@1429 334 auto ticks = ScaleTickIntervals::linear({ M_PI, 6.022140857e23, 7 });
Chris@1429 335 ScaleTickIntervals::Ticks expected {
Chris@1418 336 // not perfect, but ok-ish
Chris@1421 337 { 0, "0.0e+00" },
Chris@1421 338 { 9e+22, "9.0e+22" },
Chris@1421 339 { 1.8e+23, "1.8e+23" },
Chris@1421 340 { 2.7e+23, "2.7e+23" },
Chris@1421 341 { 3.6e+23, "3.6e+23" },
Chris@1421 342 { 4.5e+23, "4.5e+23" },
Chris@1421 343 { 5.4e+23, "5.4e+23" },
Chris@1429 344 };
Chris@1429 345 compareTicks(ticks, expected);
Chris@1412 346 }
Chris@1412 347
Chris@1412 348 void linear_2_3_1()
Chris@1412 349 {
Chris@1429 350 auto ticks = ScaleTickIntervals::linear({ 2, 3, 1 });
Chris@1429 351 ScaleTickIntervals::Ticks expected {
Chris@1429 352 { 2.0, "2" },
Chris@1429 353 { 3.0, "3" }
Chris@1429 354 };
Chris@1429 355 compareTicks(ticks, expected);
Chris@1412 356 }
Chris@1412 357
Chris@1412 358 void linear_2_3_2()
Chris@1412 359 {
Chris@1429 360 auto ticks = ScaleTickIntervals::linear({ 2, 3, 2 });
Chris@1429 361 ScaleTickIntervals::Ticks expected {
Chris@1429 362 { 2.0, "2.0" },
Chris@1429 363 { 2.5, "2.5" },
Chris@1429 364 { 3.0, "3.0" }
Chris@1429 365 };
Chris@1429 366 compareTicks(ticks, expected);
Chris@1412 367 }
Chris@1412 368
Chris@1412 369 void linear_2_3_3()
Chris@1412 370 {
Chris@1429 371 auto ticks = ScaleTickIntervals::linear({ 2, 3, 3 });
Chris@1429 372 ScaleTickIntervals::Ticks expected {
Chris@1429 373 { 2.0, "2.0" },
Chris@1429 374 { 2.3, "2.3" },
Chris@1429 375 { 2.6, "2.6" },
Chris@1429 376 { 2.9, "2.9" }
Chris@1429 377 };
Chris@1429 378 compareTicks(ticks, expected);
Chris@1412 379 }
Chris@1412 380
Chris@1412 381 void linear_2_3_4()
Chris@1412 382 {
Chris@1429 383 auto ticks = ScaleTickIntervals::linear({ 2, 3, 4 });
Chris@1412 384 // This would be better in steps of 0.25, but we only round to
Chris@1412 385 // integral powers of ten
Chris@1429 386 ScaleTickIntervals::Ticks expected {
Chris@1429 387 { 2.0, "2.0" },
Chris@1429 388 { 2.3, "2.3" },
Chris@1429 389 { 2.6, "2.6" },
Chris@1429 390 { 2.9, "2.9" }
Chris@1429 391 };
Chris@1429 392 compareTicks(ticks, expected);
Chris@1412 393 }
Chris@1412 394
Chris@1412 395 void linear_2_3_5()
Chris@1412 396 {
Chris@1429 397 auto ticks = ScaleTickIntervals::linear({ 2, 3, 5 });
Chris@1429 398 ScaleTickIntervals::Ticks expected {
Chris@1429 399 { 2.0, "2.0" },
Chris@1429 400 { 2.2, "2.2" },
Chris@1429 401 { 2.4, "2.4" },
Chris@1429 402 { 2.6, "2.6" },
Chris@1429 403 { 2.8, "2.8" },
Chris@1429 404 { 3.0, "3.0" }
Chris@1429 405 };
Chris@1429 406 compareTicks(ticks, expected);
Chris@1412 407 }
Chris@1412 408
Chris@1412 409 void linear_2_3_6()
Chris@1412 410 {
Chris@1429 411 auto ticks = ScaleTickIntervals::linear({ 2, 3, 6 });
Chris@1429 412 ScaleTickIntervals::Ticks expected {
Chris@1429 413 { 2.0, "2.0" },
Chris@1429 414 { 2.2, "2.2" },
Chris@1429 415 { 2.4, "2.4" },
Chris@1429 416 { 2.6, "2.6" },
Chris@1429 417 { 2.8, "2.8" },
Chris@1429 418 { 3.0, "3.0" }
Chris@1429 419 };
Chris@1429 420 compareTicks(ticks, expected);
Chris@1412 421 }
Chris@1412 422
Chris@1411 423 void linear_1_1_10()
Chris@1411 424 {
Chris@1415 425 // pathological range
Chris@1429 426 auto ticks = ScaleTickIntervals::linear({ 1, 1, 10 });
Chris@1429 427 ScaleTickIntervals::Ticks expected {
Chris@1460 428 { 1.0, "1" }
Chris@1429 429 };
Chris@1429 430 compareTicks(ticks, expected);
Chris@1411 431 }
Chris@1411 432
Chris@1411 433 void linear_0_0_10()
Chris@1411 434 {
Chris@1415 435 // pathological range
Chris@1429 436 auto ticks = ScaleTickIntervals::linear({ 0, 0, 10 });
Chris@1429 437 ScaleTickIntervals::Ticks expected {
Chris@1459 438 { 0.0, "0.0" }
Chris@1429 439 };
Chris@1429 440 compareTicks(ticks, expected);
Chris@1411 441 }
Chris@1411 442
Chris@1411 443 void linear_0_1_1()
Chris@1411 444 {
Chris@1429 445 auto ticks = ScaleTickIntervals::linear({ 0, 1, 1 });
Chris@1429 446 ScaleTickIntervals::Ticks expected {
Chris@1429 447 { 0.0, "0" },
Chris@1429 448 { 1.0, "1" }
Chris@1429 449 };
Chris@1429 450 compareTicks(ticks, expected);
Chris@1411 451 }
Chris@1411 452
Chris@1411 453 void linear_0_1_0()
Chris@1411 454 {
Chris@1416 455 // senseless input
Chris@1429 456 auto ticks = ScaleTickIntervals::linear({ 0, 1, 0 });
Chris@1429 457 ScaleTickIntervals::Ticks expected {
Chris@1459 458 { 0.0, "0.0" },
Chris@1429 459 };
Chris@1429 460 compareTicks(ticks, expected);
Chris@1411 461 }
Chris@1411 462
Chris@1411 463 void linear_0_1_m1()
Chris@1411 464 {
Chris@1416 465 // senseless input
Chris@1429 466 auto ticks = ScaleTickIntervals::linear({ 0, 1, -1 });
Chris@1429 467 ScaleTickIntervals::Ticks expected {
Chris@1459 468 { 0.0, "0.0" },
Chris@1429 469 };
Chris@1429 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@1418 476 // (initially it had the first tick at 1)
Chris@1416 477 auto ticks = ScaleTickIntervals::linear({ 0.465, 778.08, 10 });
Chris@1417 478 ScaleTickIntervals::Ticks expected {
Chris@1418 479 { 10, "10" },
Chris@1418 480 { 90, "90" },
Chris@1418 481 { 170, "170" },
Chris@1418 482 { 250, "250" },
Chris@1418 483 { 330, "330" },
Chris@1418 484 { 410, "410" },
Chris@1418 485 { 490, "490" },
Chris@1418 486 { 570, "570" },
Chris@1418 487 { 650, "650" },
Chris@1418 488 { 730, "730" },
Chris@1416 489 };
Chris@1417 490 compareTicks(ticks, expected);
Chris@1416 491 }
Chris@1416 492
Chris@1414 493 void log_1_10_2()
Chris@1414 494 {
Chris@1414 495 auto ticks = ScaleTickIntervals::logarithmic({ 1, 10, 2 });
Chris@1429 496 ScaleTickIntervals::Ticks expected {
Chris@1414 497 { 1.0, "1.0" },
Chris@1460 498 { 3.2, "3.2" },
Chris@1460 499 { 10.0, "10" },
Chris@1429 500 };
Chris@1429 501 compareTicks(ticks, expected);
Chris@1414 502 }
Chris@1414 503
Chris@1414 504 void log_0_10_2()
Chris@1414 505 {
Chris@1414 506 auto ticks = ScaleTickIntervals::logarithmic({ 0, 10, 2 });
Chris@1429 507 ScaleTickIntervals::Ticks expected {
Chris@1418 508 { 1e-6, "1e-06" },
Chris@1418 509 { 1, "1" },
Chris@1429 510 };
Chris@1429 511 compareTicks(ticks, expected);
Chris@1414 512 }
Chris@1415 513
Chris@1415 514 void log_pi_avogadro_7()
Chris@1415 515 {
Chris@1429 516 auto ticks = ScaleTickIntervals::logarithmic({ M_PI, 6.022140857e23, 7 });
Chris@1429 517 ScaleTickIntervals::Ticks expected {
Chris@1460 518 { 1000, "1000" },
Chris@1418 519 { 1e+06, "1e+06" },
Chris@1418 520 { 1e+09, "1e+09" },
Chris@1418 521 { 1e+12, "1e+12" },
Chris@1418 522 { 1e+15, "1e+15" },
Chris@1418 523 { 1e+18, "1e+18" },
Chris@1418 524 { 1e+21, "1e+21" },
Chris@1429 525 };
Chris@1429 526 compareTicks(ticks, expected, true);
Chris@1415 527 }
Chris@1459 528
Chris@1418 529 void log_0p465_778_10()
Chris@1418 530 {
Chris@1418 531 auto ticks = ScaleTickIntervals::logarithmic({ 0.465, 778.08, 10 });
Chris@1418 532 ScaleTickIntervals::Ticks expected {
Chris@1460 533 { 0.5, "0.50" },
Chris@1418 534 { 1, "1.0" },
Chris@1418 535 { 2, "2.0" },
Chris@1418 536 { 4, "4.0" },
Chris@1418 537 { 8, "8.0" },
Chris@1460 538 { 16, "16" },
Chris@1460 539 { 32, "32" },
Chris@1460 540 { 64, "64" },
Chris@1460 541 { 130, "130" },
Chris@1460 542 { 260, "260" },
Chris@1460 543 { 510, "510" },
Chris@1418 544 };
Chris@1418 545 compareTicks(ticks, expected);
Chris@1418 546 }
Chris@1418 547
Chris@1459 548 void log_1_10k_10()
Chris@1459 549 {
Chris@1459 550 auto ticks = ScaleTickIntervals::logarithmic({ 1.0, 10000.0, 10 });
Chris@1459 551 ScaleTickIntervals::Ticks expected {
Chris@1459 552 { 1.0, "1.0" },
Chris@1459 553 { 2.5, "2.5" },
Chris@1460 554 { 6.3, "6.3" },
Chris@1460 555 { 16.0, "16" },
Chris@1460 556 { 40.0, "40" },
Chris@1460 557 { 100.0, "100" },
Chris@1460 558 { 250.0, "250" },
Chris@1460 559 { 630.0, "630" },
Chris@1460 560 { 1600.0, "1600" },
Chris@1460 561 { 4000.0, "4000" },
Chris@1459 562 { 10000.0, "1e+04" },
Chris@1459 563 };
Chris@1459 564 compareTicks(ticks, expected, true);
Chris@1459 565 }
Chris@1459 566
Chris@1459 567 void log_80_10k_6()
Chris@1459 568 {
Chris@1459 569 auto ticks = ScaleTickIntervals::logarithmic({ 80.0, 10000.0, 6 });
Chris@1459 570 ScaleTickIntervals::Ticks expected {
Chris@1459 571 { 130, "130" },
Chris@1459 572 { 260, "260" },
Chris@1459 573 { 510, "510" },
Chris@1459 574 { 1000, "1000" },
Chris@1459 575 { 2000, "2000" },
Chris@1459 576 { 4100, "4100" },
Chris@1459 577 { 8200, "8200" }
Chris@1459 578 };
Chris@1459 579 compareTicks(ticks, expected, true);
Chris@1459 580 }
Chris@1459 581
Chris@1459 582 void log_80_800k_10()
Chris@1459 583 {
Chris@1459 584 auto ticks = ScaleTickIntervals::logarithmic({ 80.0, 800000.0, 10 });
Chris@1459 585 ScaleTickIntervals::Ticks expected {
Chris@1459 586 { 100, "100" },
Chris@1460 587 { 250, "250" },
Chris@1460 588 { 630, "630" },
Chris@1460 589 { 1600, "1600" },
Chris@1460 590 { 4000, "4000" },
Chris@1460 591 { 10000, "1e+04" },
Chris@1460 592 { 25000, "2.5e+04" },
Chris@1460 593 { 63000, "6.3e+04" },
Chris@1459 594 { 160000, "1.6e+05" },
Chris@1459 595 { 400000, "4e+05" },
Chris@1459 596 };
Chris@1459 597 compareTicks(ticks, expected, true);
Chris@1459 598 }
Chris@1459 599
Chris@1459 600 void log_0_1_0()
Chris@1459 601 {
Chris@1459 602 // senseless input
Chris@1459 603 auto ticks = ScaleTickIntervals::logarithmic({ 0, 1, 0 });
Chris@1459 604 ScaleTickIntervals::Ticks expected {
Chris@1459 605 };
Chris@1459 606 compareTicks(ticks, expected);
Chris@1459 607 }
Chris@1459 608
Chris@1459 609 void log_0_1_m1()
Chris@1459 610 {
Chris@1459 611 // senseless input
Chris@1459 612 auto ticks = ScaleTickIntervals::logarithmic({ 0, 1, -1 });
Chris@1459 613 ScaleTickIntervals::Ticks expected {
Chris@1459 614 };
Chris@1459 615 compareTicks(ticks, expected);
Chris@1459 616 }
Chris@1459 617
Chris@1407 618 };
Chris@1407 619
Chris@1407 620 #endif
Chris@1407 621
Chris@1407 622