2016-07-09 23:14:11 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-11-22 19:45:10 -05:00
|
|
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
2016-07-09 23:14:11 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTimeSeriesGetValue(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
2016-07-09 23:14:11 -04:00
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-12 20:12:23 -04:00
|
|
|
x0, y0 := ts.GetValues(0)
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertNotZero(t, x0)
|
|
|
|
testutil.AssertEqual(t, 1.0, y0)
|
2016-07-09 23:14:11 -04:00
|
|
|
}
|
2017-02-03 14:26:53 -05:00
|
|
|
|
|
|
|
func TestTimeSeriesValidate(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
2017-02-03 14:26:53 -05:00
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
}
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertNil(t, cs.Validate())
|
2017-02-03 14:26:53 -05:00
|
|
|
|
|
|
|
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),
|
|
|
|
},
|
|
|
|
}
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertNotNil(t, cs.Validate())
|
2017-02-03 14:26:53 -05:00
|
|
|
|
|
|
|
cs = TimeSeries{
|
|
|
|
Name: "Test Series",
|
|
|
|
YValues: []float64{
|
|
|
|
1.0, 2.0, 3.0, 4.0, 5.0,
|
|
|
|
},
|
|
|
|
}
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertNotNil(t, cs.Validate())
|
2017-02-03 14:26:53 -05:00
|
|
|
}
|