go-chart/linear_regression_series_test.go

78 lines
1.7 KiB
Go
Raw Permalink Normal View History

2016-07-27 15:34:15 -04:00
package chart
import (
"testing"
2018-04-05 03:42:38 -04:00
assert "github.com/blend/go-sdk/assert"
2016-07-27 15:34:15 -04:00
)
func TestLinearRegressionSeries(t *testing.T) {
assert := assert.New(t)
mainSeries := ContinuousSeries{
Name: "A test series",
2019-02-13 21:55:13 -05:00
XValues: LinearRange(1.0, 100.0),
YValues: LinearRange(1.0, 100.0),
2016-07-27 15:34:15 -04:00
}
linRegSeries := &LinearRegressionSeries{
InnerSeries: mainSeries,
}
lrx0, lry0 := linRegSeries.GetValues(0)
2016-07-27 15:34:15 -04:00
assert.InDelta(1.0, lrx0, 0.0000001)
assert.InDelta(1.0, lry0, 0.0000001)
lrxn, lryn := linRegSeries.GetLastValues()
2016-07-27 15:34:15 -04:00
assert.InDelta(100.0, lrxn, 0.0000001)
assert.InDelta(100.0, lryn, 0.0000001)
}
func TestLinearRegressionSeriesDesc(t *testing.T) {
assert := assert.New(t)
mainSeries := ContinuousSeries{
Name: "A test series",
2019-02-13 21:55:13 -05:00
XValues: LinearRange(100.0, 1.0),
YValues: LinearRange(100.0, 1.0),
2016-07-27 15:34:15 -04:00
}
linRegSeries := &LinearRegressionSeries{
InnerSeries: mainSeries,
}
lrx0, lry0 := linRegSeries.GetValues(0)
2016-07-27 15:34:15 -04:00
assert.InDelta(100.0, lrx0, 0.0000001)
assert.InDelta(100.0, lry0, 0.0000001)
lrxn, lryn := linRegSeries.GetLastValues()
2016-07-27 15:34:15 -04:00
assert.InDelta(1.0, lrxn, 0.0000001)
assert.InDelta(1.0, lryn, 0.0000001)
}
func TestLinearRegressionSeriesWindowAndOffset(t *testing.T) {
assert := assert.New(t)
mainSeries := ContinuousSeries{
Name: "A test series",
2019-02-13 21:55:13 -05:00
XValues: LinearRange(100.0, 1.0),
YValues: LinearRange(100.0, 1.0),
2016-07-27 15:34:15 -04:00
}
linRegSeries := &LinearRegressionSeries{
InnerSeries: mainSeries,
Offset: 10,
Limit: 10,
2016-07-27 15:34:15 -04:00
}
2016-07-27 15:54:40 -04:00
assert.Equal(10, linRegSeries.Len())
lrx0, lry0 := linRegSeries.GetValues(0)
2016-07-27 15:34:15 -04:00
assert.InDelta(90.0, lrx0, 0.0000001)
assert.InDelta(90.0, lry0, 0.0000001)
lrxn, lryn := linRegSeries.GetLastValues()
2016-07-27 15:34:15 -04:00
assert.InDelta(80.0, lrxn, 0.0000001)
assert.InDelta(80.0, lryn, 0.0000001)
}