forked from gonum/plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
axis_test.go
61 lines (57 loc) · 1.23 KB
/
axis_test.go
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
// 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 labelsOf(ticks []Tick) []string {
var labels []string
for _, t := range ticks {
if t.Label != "" {
labels = append(labels, t.Label)
}
}
return labels
}