go-chart/tick_test.go

61 lines
1.3 KiB
Go
Raw Permalink Normal View History

2016-07-11 02:06:14 -04:00
package chart
2016-07-11 02:27:38 -04:00
2017-01-09 20:57:45 -05:00
import (
"testing"
"github.com/wcharczuk/go-chart/v2/testutil"
2017-01-09 20:57:45 -05:00
)
func TestGenerateContinuousTicks(t *testing.T) {
// replaced new assertions helper
2017-01-09 20:57:45 -05:00
f, err := GetDefaultFont()
testutil.AssertNil(t, err)
2017-01-09 20:57:45 -05:00
r, err := PNG(1024, 1024)
testutil.AssertNil(t, err)
2017-01-09 20:57:45 -05:00
r.SetFont(f)
ra := &ContinuousRange{
Min: 0.0,
Max: 10.0,
Domain: 256,
}
vf := FloatValueFormatter
ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf)
testutil.AssertNotEmpty(t, ticks)
testutil.AssertLen(t, ticks, 11)
testutil.AssertEqual(t, 0.0, ticks[0].Value)
testutil.AssertEqual(t, 10, ticks[len(ticks)-1].Value)
2017-01-09 20:57:45 -05:00
}
func TestGenerateContinuousTicksDescending(t *testing.T) {
// replaced new assertions helper
2016-07-11 02:27:38 -04:00
2017-01-09 20:57:45 -05:00
f, err := GetDefaultFont()
testutil.AssertNil(t, err)
2017-01-09 20:57:45 -05:00
r, err := PNG(1024, 1024)
testutil.AssertNil(t, err)
2017-01-09 20:57:45 -05:00
r.SetFont(f)
ra := &ContinuousRange{
2017-01-10 16:50:17 -05:00
Min: 0.0,
Max: 10.0,
Domain: 256,
Descending: true,
2017-01-09 20:57:45 -05:00
}
2016-07-30 15:59:59 -04:00
2017-01-09 20:57:45 -05:00
vf := FloatValueFormatter
2016-07-30 15:59:59 -04:00
2017-01-09 20:57:45 -05:00
ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf)
testutil.AssertNotEmpty(t, ticks)
testutil.AssertLen(t, ticks, 11)
testutil.AssertEqual(t, 10.0, ticks[0].Value)
testutil.AssertEqual(t, 9.0, ticks[1].Value)
testutil.AssertEqual(t, 1.0, ticks[len(ticks)-2].Value)
testutil.AssertEqual(t, 0.0, ticks[len(ticks)-1].Value)
2016-07-11 02:27:38 -04:00
}