2016-07-27 21:34:15 +02:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-04-05 09:42:38 +02:00
|
|
|
assert "github.com/blend/go-sdk/assert"
|
2018-12-06 16:38:58 +01:00
|
|
|
"git.gutmet.org/go-chart.git/seq"
|
2016-07-27 21:34:15 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLinearRegressionSeries(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
mainSeries := ContinuousSeries{
|
|
|
|
Name: "A test series",
|
2017-05-13 02:12:23 +02:00
|
|
|
XValues: seq.Range(1.0, 100.0),
|
|
|
|
YValues: seq.Range(1.0, 100.0),
|
2016-07-27 21:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
linRegSeries := &LinearRegressionSeries{
|
|
|
|
InnerSeries: mainSeries,
|
|
|
|
}
|
|
|
|
|
2017-05-13 02:12:23 +02:00
|
|
|
lrx0, lry0 := linRegSeries.GetValues(0)
|
2016-07-27 21:34:15 +02:00
|
|
|
assert.InDelta(1.0, lrx0, 0.0000001)
|
|
|
|
assert.InDelta(1.0, lry0, 0.0000001)
|
|
|
|
|
2017-05-13 02:12:23 +02:00
|
|
|
lrxn, lryn := linRegSeries.GetLastValues()
|
2016-07-27 21:34:15 +02: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",
|
2017-05-13 02:12:23 +02:00
|
|
|
XValues: seq.Range(100.0, 1.0),
|
|
|
|
YValues: seq.Range(100.0, 1.0),
|
2016-07-27 21:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
linRegSeries := &LinearRegressionSeries{
|
|
|
|
InnerSeries: mainSeries,
|
|
|
|
}
|
|
|
|
|
2017-05-13 02:12:23 +02:00
|
|
|
lrx0, lry0 := linRegSeries.GetValues(0)
|
2016-07-27 21:34:15 +02:00
|
|
|
assert.InDelta(100.0, lrx0, 0.0000001)
|
|
|
|
assert.InDelta(100.0, lry0, 0.0000001)
|
|
|
|
|
2017-05-13 02:12:23 +02:00
|
|
|
lrxn, lryn := linRegSeries.GetLastValues()
|
2016-07-27 21:34:15 +02: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",
|
2017-05-13 02:12:23 +02:00
|
|
|
XValues: seq.Range(100.0, 1.0),
|
|
|
|
YValues: seq.Range(100.0, 1.0),
|
2016-07-27 21:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
linRegSeries := &LinearRegressionSeries{
|
|
|
|
InnerSeries: mainSeries,
|
|
|
|
Offset: 10,
|
2017-04-19 05:20:29 +02:00
|
|
|
Limit: 10,
|
2016-07-27 21:34:15 +02:00
|
|
|
}
|
|
|
|
|
2016-07-27 21:54:40 +02:00
|
|
|
assert.Equal(10, linRegSeries.Len())
|
|
|
|
|
2017-05-13 02:12:23 +02:00
|
|
|
lrx0, lry0 := linRegSeries.GetValues(0)
|
2016-07-27 21:34:15 +02:00
|
|
|
assert.InDelta(90.0, lrx0, 0.0000001)
|
|
|
|
assert.InDelta(90.0, lry0, 0.0000001)
|
|
|
|
|
2017-05-13 02:12:23 +02:00
|
|
|
lrxn, lryn := linRegSeries.GetLastValues()
|
2016-07-27 21:34:15 +02:00
|
|
|
assert.InDelta(80.0, lrxn, 0.0000001)
|
|
|
|
assert.InDelta(80.0, lryn, 0.0000001)
|
|
|
|
}
|