2016-07-28 19:36:30 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
2017-01-13 19:03:45 -05:00
|
|
|
"fmt"
|
2016-07-28 19:36:30 -04:00
|
|
|
"testing"
|
|
|
|
|
2018-04-05 03:42:38 -04:00
|
|
|
assert "github.com/blend/go-sdk/assert"
|
2017-05-12 20:12:23 -04:00
|
|
|
"github.com/wcharczuk/go-chart/seq"
|
2016-07-28 19:36:30 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestContinuousSeries(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
cs := ContinuousSeries{
|
|
|
|
Name: "Test Series",
|
2017-05-12 20:12:23 -04:00
|
|
|
XValues: seq.Range(1.0, 10.0),
|
|
|
|
YValues: seq.Range(1.0, 10.0),
|
2016-07-28 19:36:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal("Test Series", cs.GetName())
|
|
|
|
assert.Equal(10, cs.Len())
|
2017-05-12 20:12:23 -04:00
|
|
|
x0, y0 := cs.GetValues(0)
|
2016-07-28 19:36:30 -04:00
|
|
|
assert.Equal(1.0, x0)
|
|
|
|
assert.Equal(1.0, y0)
|
|
|
|
|
2017-05-12 20:12:23 -04:00
|
|
|
xn, yn := cs.GetValues(9)
|
2016-07-28 19:36:30 -04:00
|
|
|
assert.Equal(10.0, xn)
|
|
|
|
assert.Equal(10.0, yn)
|
|
|
|
|
2017-05-12 20:12:23 -04:00
|
|
|
xn, yn = cs.GetLastValues()
|
2016-07-28 19:36:30 -04:00
|
|
|
assert.Equal(10.0, xn)
|
|
|
|
assert.Equal(10.0, yn)
|
|
|
|
}
|
2017-01-13 19:03:45 -05:00
|
|
|
|
|
|
|
func TestContinuousSeriesValueFormatter(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
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()
|
|
|
|
assert.Equal("0.100000 foo", xf(0.1))
|
|
|
|
assert.Equal("0.100000 bar", yf(0.1))
|
|
|
|
}
|
2017-02-03 14:26:53 -05:00
|
|
|
|
|
|
|
func TestContinuousSeriesValidate(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
cs := ContinuousSeries{
|
|
|
|
Name: "Test Series",
|
2017-05-12 20:12:23 -04:00
|
|
|
XValues: seq.Range(1.0, 10.0),
|
|
|
|
YValues: seq.Range(1.0, 10.0),
|
2017-02-03 14:26:53 -05:00
|
|
|
}
|
|
|
|
assert.Nil(cs.Validate())
|
|
|
|
|
|
|
|
cs = ContinuousSeries{
|
|
|
|
Name: "Test Series",
|
2017-05-12 20:12:23 -04:00
|
|
|
XValues: seq.Range(1.0, 10.0),
|
2017-02-03 14:26:53 -05:00
|
|
|
}
|
|
|
|
assert.NotNil(cs.Validate())
|
|
|
|
|
|
|
|
cs = ContinuousSeries{
|
|
|
|
Name: "Test Series",
|
2017-05-12 20:12:23 -04:00
|
|
|
YValues: seq.Range(1.0, 10.0),
|
2017-02-03 14:26:53 -05:00
|
|
|
}
|
|
|
|
assert.NotNil(cs.Validate())
|
|
|
|
}
|