go-chart/time_series_test.go
Will Charczuk 03708a90ef Helper API refactor (#40)
* api cleaup

* updates

* wtf

* updates

* snapshot.

* tweaks

* snapshot

* api tweaks.

* updates

* updates

* updates

* changes.

* updates

* updates

* sequence => seq

* dont need to use curl, just using wget

* fixing examples
2017-05-12 17:12:23 -07:00

70 lines
1.3 KiB
Go

package chart
import (
"testing"
"time"
"github.com/blendlabs/go-assert"
)
func TestTimeSeriesGetValue(t *testing.T) {
assert := assert.New(t)
ts := TimeSeries{
Name: "Test",
XValues: []time.Time{
time.Now().AddDate(0, 0, -5),
time.Now().AddDate(0, 0, -4),
time.Now().AddDate(0, 0, -3),
time.Now().AddDate(0, 0, -2),
time.Now().AddDate(0, 0, -1),
},
YValues: []float64{
1.0, 2.0, 3.0, 4.0, 5.0,
},
}
x0, y0 := ts.GetValues(0)
assert.NotZero(x0)
assert.Equal(1.0, y0)
}
func TestTimeSeriesValidate(t *testing.T) {
assert := assert.New(t)
cs := TimeSeries{
Name: "Test Series",
XValues: []time.Time{
time.Now().AddDate(0, 0, -5),
time.Now().AddDate(0, 0, -4),
time.Now().AddDate(0, 0, -3),
time.Now().AddDate(0, 0, -2),
time.Now().AddDate(0, 0, -1),
},
YValues: []float64{
1.0, 2.0, 3.0, 4.0, 5.0,
},
}
assert.Nil(cs.Validate())
cs = TimeSeries{
Name: "Test Series",
XValues: []time.Time{
time.Now().AddDate(0, 0, -5),
time.Now().AddDate(0, 0, -4),
time.Now().AddDate(0, 0, -3),
time.Now().AddDate(0, 0, -2),
time.Now().AddDate(0, 0, -1),
},
}
assert.NotNil(cs.Validate())
cs = TimeSeries{
Name: "Test Series",
YValues: []float64{
1.0, 2.0, 3.0, 4.0, 5.0,
},
}
assert.NotNil(cs.Validate())
}