go-chart/continuous_series_test.go

73 lines
1.6 KiB
Go
Raw Normal View History

2016-07-28 19:36:30 -04:00
package chart
import (
"fmt"
2016-07-28 19:36:30 -04:00
"testing"
"github.com/wcharczuk/go-chart/v2/testutil"
2016-07-28 19:36:30 -04:00
)
func TestContinuousSeries(t *testing.T) {
// replaced new assertions helper
2016-07-28 19:36:30 -04:00
cs := ContinuousSeries{
Name: "Test Series",
2019-02-13 21:55:13 -05:00
XValues: LinearRange(1.0, 10.0),
YValues: LinearRange(1.0, 10.0),
2016-07-28 19:36:30 -04:00
}
testutil.AssertEqual(t, "Test Series", cs.GetName())
testutil.AssertEqual(t, 10, cs.Len())
x0, y0 := cs.GetValues(0)
testutil.AssertEqual(t, 1.0, x0)
testutil.AssertEqual(t, 1.0, y0)
2016-07-28 19:36:30 -04:00
xn, yn := cs.GetValues(9)
testutil.AssertEqual(t, 10.0, xn)
testutil.AssertEqual(t, 10.0, yn)
2016-07-28 19:36:30 -04:00
xn, yn = cs.GetLastValues()
testutil.AssertEqual(t, 10.0, xn)
testutil.AssertEqual(t, 10.0, yn)
2016-07-28 19:36:30 -04:00
}
func TestContinuousSeriesValueFormatter(t *testing.T) {
// replaced new assertions helper
cs := ContinuousSeries{
XValueFormatter: func(v interface{}) string {
return fmt.Sprintf("%f foo", v)
},
YValueFormatter: func(v interface{}) string {
return fmt.Sprintf("%f bar", v)
},
}
xf, yf := cs.GetValueFormatters()
testutil.AssertEqual(t, "0.100000 foo", xf(0.1))
testutil.AssertEqual(t, "0.100000 bar", yf(0.1))
}
2017-02-03 14:26:53 -05:00
func TestContinuousSeriesValidate(t *testing.T) {
// replaced new assertions helper
2017-02-03 14:26:53 -05:00
cs := ContinuousSeries{
Name: "Test Series",
2019-02-13 21:55:13 -05:00
XValues: LinearRange(1.0, 10.0),
YValues: LinearRange(1.0, 10.0),
2017-02-03 14:26:53 -05:00
}
testutil.AssertNil(t, cs.Validate())
2017-02-03 14:26:53 -05:00
cs = ContinuousSeries{
Name: "Test Series",
2019-02-13 21:55:13 -05:00
XValues: LinearRange(1.0, 10.0),
2017-02-03 14:26:53 -05:00
}
testutil.AssertNotNil(t, cs.Validate())
2017-02-03 14:26:53 -05:00
cs = ContinuousSeries{
Name: "Test Series",
2019-02-13 21:55:13 -05:00
YValues: LinearRange(1.0, 10.0),
2017-02-03 14:26:53 -05:00
}
testutil.AssertNotNil(t, cs.Validate())
2017-02-03 14:26:53 -05:00
}