Mercurial > hg > svcore
comparison base/test/TestScaleTickIntervals.h @ 1418:e7cb4fb2aee4 scale-ticks
Rework log scale calculation, update to changed interface
author | Chris Cannam |
---|---|
date | Thu, 04 May 2017 15:37:43 +0100 |
parents | 359147a50853 |
children | 8b7d6c1e1ab7 |
comparison
equal
deleted
inserted
replaced
1417:359147a50853 | 1418:e7cb4fb2aee4 |
---|---|
303 { | 303 { |
304 auto ticks = ScaleTickIntervals::linear({ 221.23, 623.7, 4 }); | 304 auto ticks = ScaleTickIntervals::linear({ 221.23, 623.7, 4 }); |
305 // only 4 ticks, not 5, because none of the rounded tick | 305 // only 4 ticks, not 5, because none of the rounded tick |
306 // values lies on an end value | 306 // values lies on an end value |
307 ScaleTickIntervals::Ticks expected { | 307 ScaleTickIntervals::Ticks expected { |
308 { 230, "230" }, | 308 { 300, "300" }, |
309 { 330, "330" }, | 309 { 400, "400" }, |
310 { 430, "430" }, | 310 { 500, "500" }, |
311 { 530, "530" }, | 311 { 600, "600" }, |
312 }; | 312 }; |
313 compareTicks(ticks, expected); | 313 compareTicks(ticks, expected); |
314 } | 314 } |
315 | 315 |
316 void linear_sqrt2_pi_7() | 316 void linear_sqrt2_pi_7() |
334 | 334 |
335 void linear_pi_avogadro_7() | 335 void linear_pi_avogadro_7() |
336 { | 336 { |
337 auto ticks = ScaleTickIntervals::linear({ M_PI, 6.022140857e23, 7 }); | 337 auto ticks = ScaleTickIntervals::linear({ M_PI, 6.022140857e23, 7 }); |
338 ScaleTickIntervals::Ticks expected { | 338 ScaleTickIntervals::Ticks expected { |
339 { 1e+21, "1.000e+21" }, | 339 // not perfect, but ok-ish |
340 { 8.7e+22, "8.700e+22" }, | 340 { 1e+22, "1.00e+22" }, |
341 { 1.73e+23, "1.730e+23" }, | 341 { 1e+23, "1.00e+23" }, |
342 { 2.59e+23, "2.590e+23" }, | 342 { 1.9e+23, "1.90e+23" }, |
343 { 3.45e+23, "3.450e+23" }, | 343 { 2.8e+23, "2.80e+23" }, |
344 { 4.31e+23, "4.310e+23" }, | 344 { 3.7e+23, "3.70e+23" }, |
345 { 5.17e+23, "5.170e+23" }, | 345 { 4.6e+23, "4.60e+23" }, |
346 { 5.5e+23, "5.50e+23" }, | |
346 }; | 347 }; |
347 compareTicks(ticks, expected); | 348 compareTicks(ticks, expected); |
348 } | 349 } |
349 | 350 |
350 void linear_2_3_1() | 351 void linear_2_3_1() |
425 void linear_1_1_10() | 426 void linear_1_1_10() |
426 { | 427 { |
427 // pathological range | 428 // pathological range |
428 auto ticks = ScaleTickIntervals::linear({ 1, 1, 10 }); | 429 auto ticks = ScaleTickIntervals::linear({ 1, 1, 10 }); |
429 ScaleTickIntervals::Ticks expected { | 430 ScaleTickIntervals::Ticks expected { |
430 { 1.0, "1.0" } | 431 { 1.0, "1" } |
431 }; | 432 }; |
432 compareTicks(ticks, expected); | 433 compareTicks(ticks, expected); |
433 } | 434 } |
434 | 435 |
435 void linear_0_0_10() | 436 void linear_0_0_10() |
436 { | 437 { |
437 // pathological range | 438 // pathological range |
438 auto ticks = ScaleTickIntervals::linear({ 0, 0, 10 }); | 439 auto ticks = ScaleTickIntervals::linear({ 0, 0, 10 }); |
439 ScaleTickIntervals::Ticks expected { | 440 ScaleTickIntervals::Ticks expected { |
440 { 0.0, "0.0" } | 441 { 0.0, "0" } |
441 }; | 442 }; |
442 compareTicks(ticks, expected); | 443 compareTicks(ticks, expected); |
443 } | 444 } |
444 | 445 |
445 void linear_0_1_1() | 446 void linear_0_1_1() |
455 void linear_0_1_0() | 456 void linear_0_1_0() |
456 { | 457 { |
457 // senseless input | 458 // senseless input |
458 auto ticks = ScaleTickIntervals::linear({ 0, 1, 0 }); | 459 auto ticks = ScaleTickIntervals::linear({ 0, 1, 0 }); |
459 ScaleTickIntervals::Ticks expected { | 460 ScaleTickIntervals::Ticks expected { |
461 { 0.0, "0" }, | |
460 }; | 462 }; |
461 compareTicks(ticks, expected); | 463 compareTicks(ticks, expected); |
462 } | 464 } |
463 | 465 |
464 void linear_0_1_m1() | 466 void linear_0_1_m1() |
465 { | 467 { |
466 // senseless input | 468 // senseless input |
467 auto ticks = ScaleTickIntervals::linear({ 0, 1, -1 }); | 469 auto ticks = ScaleTickIntervals::linear({ 0, 1, -1 }); |
468 ScaleTickIntervals::Ticks expected { | 470 ScaleTickIntervals::Ticks expected { |
471 { 0.0, "0" }, | |
469 }; | 472 }; |
470 compareTicks(ticks, expected); | 473 compareTicks(ticks, expected); |
471 } | 474 } |
472 | 475 |
473 void linear_0p465_778_10() | 476 void linear_0p465_778_10() |
474 { | 477 { |
475 // a case that gave unsatisfactory results in real life | 478 // a case that gave unsatisfactory results in real life |
479 // (initially it had the first tick at 1) | |
476 auto ticks = ScaleTickIntervals::linear({ 0.465, 778.08, 10 }); | 480 auto ticks = ScaleTickIntervals::linear({ 0.465, 778.08, 10 }); |
477 ScaleTickIntervals::Ticks expected { | 481 ScaleTickIntervals::Ticks expected { |
482 { 10, "10" }, | |
483 { 90, "90" }, | |
484 { 170, "170" }, | |
485 { 250, "250" }, | |
486 { 330, "330" }, | |
487 { 410, "410" }, | |
488 { 490, "490" }, | |
489 { 570, "570" }, | |
490 { 650, "650" }, | |
491 { 730, "730" }, | |
478 }; | 492 }; |
479 compareTicks(ticks, expected); | 493 compareTicks(ticks, expected); |
480 } | 494 } |
481 | 495 |
482 void log_1_10_2() | 496 void log_1_10_2() |
492 | 506 |
493 void log_0_10_2() | 507 void log_0_10_2() |
494 { | 508 { |
495 auto ticks = ScaleTickIntervals::logarithmic({ 0, 10, 2 }); | 509 auto ticks = ScaleTickIntervals::logarithmic({ 0, 10, 2 }); |
496 ScaleTickIntervals::Ticks expected { | 510 ScaleTickIntervals::Ticks expected { |
497 { 1e-10, "1e-10" }, | 511 { 1e-6, "1e-06" }, |
498 { pow(10.0, -4.5), "3e-05" }, | 512 { 1, "1" }, |
499 { 10.0, "1e+01" }, | |
500 }; | 513 }; |
501 compareTicks(ticks, expected); | 514 compareTicks(ticks, expected); |
502 } | 515 } |
503 | 516 |
504 void log_pi_avogadro_7() | 517 void log_pi_avogadro_7() |
505 { | 518 { |
506 auto ticks = ScaleTickIntervals::logarithmic({ M_PI, 6.022140857e23, 7 }); | 519 auto ticks = ScaleTickIntervals::logarithmic({ M_PI, 6.022140857e23, 7 }); |
507 ScaleTickIntervals::Ticks expected { | 520 ScaleTickIntervals::Ticks expected { |
508 { 3.16228, "3e+00" }, | 521 { 1000, "1e+03" }, |
509 { 6309.57, "6e+03" }, | 522 { 1e+06, "1e+06" }, |
510 { 1.25893e+07, "1e+07" }, | 523 { 1e+09, "1e+09" }, |
511 { 2.51189e+10, "3e+10" }, | 524 { 1e+12, "1e+12" }, |
512 { 5.01187e+13, "5e+13" }, | 525 { 1e+15, "1e+15" }, |
513 { 1e+17, "1e+17" }, | 526 { 1e+18, "1e+18" }, |
514 { 1.99526e+20, "2e+20" }, | 527 { 1e+21, "1e+21" }, |
515 { 3.98107e+23, "4e+23" }, | |
516 }; | 528 }; |
517 compareTicks(ticks, expected, true); | 529 compareTicks(ticks, expected, true); |
518 } | 530 } |
531 | |
532 void log_0p465_778_10() | |
533 { | |
534 auto ticks = ScaleTickIntervals::logarithmic({ 0.465, 778.08, 10 }); | |
535 ScaleTickIntervals::Ticks expected { | |
536 { 0.5, "0.5" }, | |
537 { 1, "1.0" }, | |
538 { 2, "2.0" }, | |
539 { 4, "4.0" }, | |
540 { 8, "8.0" }, | |
541 { 16, "16.0" }, | |
542 { 32, "32.0" }, | |
543 { 64, "64.0" }, | |
544 { 128, "128.0" }, | |
545 { 256, "256.0" }, | |
546 { 512, "512.0" }, | |
547 }; | |
548 compareTicks(ticks, expected); | |
549 } | |
550 | |
519 }; | 551 }; |
520 | 552 |
521 #endif | 553 #endif |
522 | 554 |
523 | 555 |