File: axis-division-rounded.t

package info (click to toggle)
libchart-clicker-perl 2.90-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 696 kB
  • ctags: 109
  • sloc: perl: 4,379; makefile: 2
file content (89 lines) | stat: -rw-r--r-- 2,614 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use Test::More;

BEGIN {
    use_ok('Chart::Clicker::Axis');
}
my $label = 'Foo';

# Small Range
{
    my $axis = Chart::Clicker::Axis->new(
        label              => $label,
        orientation        => 'vertical',
        position           => 'left',
        tick_division_type => 'LinearRounded'
    );

    ok( defined( $axis->range() ), 'Has range' );

    $axis->range->lower(3);
    $axis->range->upper(105);
    is( $axis->ticks, '6', 'Default number of ticks' );
    is_deeply( $axis->divvy(), [ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ], 'Nicely rounded tick values - medium scale' );
}

# Larger Range
{
    my $axis = Chart::Clicker::Axis->new(
        label              => $label,
        orientation        => 'vertical',
        position           => 'left',
        tick_division_type => 'LinearRounded'
    );
    $axis->range->lower(1);
    $axis->range->upper(999123421);
    is_deeply(
        $axis->divvy(),
        [ 0, 100000000, 200000000, 300000000, 400000000, 500000000,
          600000000, 700000000, 800000000, 900000000, 1000000000],

        'Nicely rounded tick values - large scale 5 ticks'
    );
}

# Large range, small tick count
{
    my $axis = Chart::Clicker::Axis->new(
        label              => $label,
        orientation        => 'vertical',
        position           => 'left',
        tick_division_type => 'LinearRounded'
    );
    $axis->range->lower(1);
    $axis->range->upper(999123421);
    $axis->ticks(3);
    is_deeply( $axis->divvy(), [ 0, 250000000, 500000000, 750000000, 1000000000 ],
        'Nicely rounded tick values - large scale 3 ticks' );
}

# Very small range below 1
{
    my $axis = Chart::Clicker::Axis->new(
        label              => $label,
        orientation        => 'vertical',
        position           => 'left',
        tick_division_type => 'LinearRounded'
    );
    $axis->range->lower(0.0072);
    $axis->range->upper(0.0078);
    $axis->ticks(3);
    is_deeply( $axis->divvy(), [ 0.0072, 0.0073, 0.0074, 0.0075, 0.0076, 0.0077, 0.0078 ],
        'Nicely rounded tick values - large scale 3 ticks' );
}

# Very small range above 1
{
    my $axis = Chart::Clicker::Axis->new(
        label              => $label,
        orientation        => 'vertical',
        position           => 'left',
        tick_division_type => 'LinearRounded'
    );
    $axis->range->lower(1.5672);
    $axis->range->upper(1.5679);
    $axis->ticks(4);
    is_deeply( $axis->divvy(), [ 1.5672, 1.5673, 1.5674, 1.5675, 1.5676, 1.5677, 1.5678, 1.5679 ],
        'Nicely rounded tick values - large scale 3 ticks' );
}

done_testing;