forked from gonum/plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaxis_test.go
More file actions
101 lines (96 loc) · 2.1 KB
/
axis_test.go
File metadata and controls
101 lines (96 loc) · 2.1 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright ©2015 The gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package plot
import (
"math"
"reflect"
"testing"
)
func TestAxisSmallTick(t *testing.T) {
d := DefaultTicks{}
for _, test := range []struct {
min, max float64
want []string
}{
{
min: -1.9846500878911073,
max: 0.4370974820125605,
want: []string{"-1.6", "-0.8", "0"},
},
{
min: -1.985e-15,
max: 0.4371e-15,
want: []string{"-1.6e-15", "-8e-16", "0"},
},
{
min: -1.985e15,
max: 0.4371e15,
want: []string{"-1.6e+15", "-8e+14", "0"},
},
{
min: math.MaxFloat64 / 4,
max: math.MaxFloat64 / 3,
want: []string{"4.8e+307", "5.2e+307", "5.6e+307"},
},
{
min: 0.00010,
max: 0.00015,
want: []string{"0.0001", "0.00011", "0.00012", "0.00013", "0.00014"},
},
} {
ticks := d.Ticks(test.min, test.max)
got := labelsOf(ticks)
if !reflect.DeepEqual(got, test.want) {
t.Errorf("tick labels mismatch:\ngot: %q\nwant:%q", got, test.want)
}
}
}
func TestIntTick(t *testing.T) {
i := IntTicks{}
for _, test := range []struct {
addMinTick bool
addMaxTick bool
min, max float64
want []string
}{
{
addMinTick: false,
addMaxTick: false,
min: 1.0,
max: 99999.0,
want: []string{"30000", "60000", "90000"},
},
{
addMinTick: true,
addMaxTick: false,
min: 1.0,
max: 99999.0,
want: []string{"1", "30000", "60000", "90000"},
},
{
addMinTick: true,
addMaxTick: true,
min: 1.0,
max: 99999.0,
want: []string{"1", "30000", "60000", "90000", "99999"},
},
} {
i.AddMinTick = test.addMinTick
i.AddMaxTick = test.addMaxTick
ticks := i.Ticks(test.min, test.max)
got := labelsOf(ticks)
if !reflect.DeepEqual(got, test.want) {
t.Errorf("tick labels mismatch:\ngot: %q\nwant:%q", got, test.want)
}
}
}
func labelsOf(ticks []Tick) []string {
var labels []string
for _, t := range ticks {
if t.Label != "" {
labels = append(labels, t.Label)
}
}
return labels
}