-
Notifications
You must be signed in to change notification settings - Fork 4
/
tick_test.go
56 lines (50 loc) · 1.12 KB
/
tick_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
package unichart
import (
"testing"
"github.com/stretchr/testify/require"
)
type TickInput struct {
min float64
max float64
num int
expectedResult []float64
}
// TestNiceTicks tests `niceTicks` function output
func TestNiceTicks(t *testing.T) {
inputs := []TickInput{
{
min: 0,
max: 10,
num: 3,
expectedResult: []float64{0.0, 5.0, 10.0},
},
{
min: 0,
max: 10,
num: 2,
expectedResult: []float64{0.0, 10.0},
},
{
min: 0,
max: 10,
num: 5,
expectedResult: []float64{0.0, 2.0, 4.0, 6.0, 8.0, 10.0},
},
{
min: -10,
max: 10,
num: 8,
expectedResult: []float64{-10.0, -8.0, -6.0, -4.0, -2.0, 0.0, 2.0, 4.0, 6.0, 8.0, 10.0},
},
{
min: 1,
max: 5,
num: 10,
expectedResult: []float64{1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0},
},
}
for _, i := range inputs {
result := niceTicks(i.min, i.max, i.num)
require.ElementsMatch(t, i.expectedResult, result)
}
}