go-chart/tick_test.go

61 lines
1.1 KiB
Go
Raw Permalink Normal View History

2016-07-11 08:06:14 +02:00
package chart
2016-07-11 08:27:38 +02:00
2017-01-10 02:57:45 +01:00
import (
"testing"
2018-04-05 09:42:38 +02:00
assert "github.com/blend/go-sdk/assert"
2017-01-10 02:57:45 +01:00
)
func TestGenerateContinuousTicks(t *testing.T) {
assert := assert.New(t)
f, err := GetDefaultFont()
assert.Nil(err)
r, err := PNG(1024, 1024)
assert.Nil(err)
r.SetFont(f)
ra := &ContinuousRange{
Min: 0.0,
Max: 10.0,
Domain: 256,
}
vf := FloatValueFormatter
ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf)
assert.NotEmpty(ticks)
assert.Len(ticks, 11)
2017-01-10 02:57:45 +01:00
assert.Equal(0.0, ticks[0].Value)
assert.Equal(10, ticks[len(ticks)-1].Value)
}
func TestGenerateContinuousTicksDescending(t *testing.T) {
2016-07-11 08:27:38 +02:00
assert := assert.New(t)
2017-01-10 02:57:45 +01:00
f, err := GetDefaultFont()
assert.Nil(err)
r, err := PNG(1024, 1024)
assert.Nil(err)
r.SetFont(f)
ra := &ContinuousRange{
2017-01-10 22:50:17 +01:00
Min: 0.0,
Max: 10.0,
Domain: 256,
Descending: true,
2017-01-10 02:57:45 +01:00
}
2016-07-30 21:59:59 +02:00
2017-01-10 02:57:45 +01:00
vf := FloatValueFormatter
2016-07-30 21:59:59 +02:00
2017-01-10 02:57:45 +01:00
ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf)
assert.NotEmpty(ticks)
assert.Len(ticks, 11)
2017-01-10 02:57:45 +01:00
assert.Equal(10.0, ticks[0].Value)
2017-01-10 22:50:17 +01:00
assert.Equal(9.0, ticks[1].Value)
assert.Equal(1.0, ticks[len(ticks)-2].Value)
2017-01-10 02:57:45 +01:00
assert.Equal(0.0, ticks[len(ticks)-1].Value)
2016-07-11 08:27:38 +02:00
}