2016-07-27 15:34:15 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-11-22 19:45:10 -05:00
|
|
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
2016-07-27 15:34:15 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLinearRegressionSeries(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
2016-07-27 15:34:15 -04:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2017-05-12 20:12:23 -04:00
|
|
|
lrx0, lry0 := linRegSeries.GetValues(0)
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertInDelta(t, 1.0, lrx0, 0.0000001)
|
|
|
|
testutil.AssertInDelta(t, 1.0, lry0, 0.0000001)
|
2016-07-27 15:34:15 -04:00
|
|
|
|
2017-05-12 20:12:23 -04:00
|
|
|
lrxn, lryn := linRegSeries.GetLastValues()
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertInDelta(t, 100.0, lrxn, 0.0000001)
|
|
|
|
testutil.AssertInDelta(t, 100.0, lryn, 0.0000001)
|
2016-07-27 15:34:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLinearRegressionSeriesDesc(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
2016-07-27 15:34:15 -04:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2017-05-12 20:12:23 -04:00
|
|
|
lrx0, lry0 := linRegSeries.GetValues(0)
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertInDelta(t, 100.0, lrx0, 0.0000001)
|
|
|
|
testutil.AssertInDelta(t, 100.0, lry0, 0.0000001)
|
2016-07-27 15:34:15 -04:00
|
|
|
|
2017-05-12 20:12:23 -04:00
|
|
|
lrxn, lryn := linRegSeries.GetLastValues()
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertInDelta(t, 1.0, lrxn, 0.0000001)
|
|
|
|
testutil.AssertInDelta(t, 1.0, lryn, 0.0000001)
|
2016-07-27 15:34:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLinearRegressionSeriesWindowAndOffset(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
2016-07-27 15:34:15 -04:00
|
|
|
|
|
|
|
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,
|
2017-04-18 23:20:29 -04:00
|
|
|
Limit: 10,
|
2016-07-27 15:34:15 -04:00
|
|
|
}
|
|
|
|
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertEqual(t, 10, linRegSeries.Len())
|
2016-07-27 15:54:40 -04:00
|
|
|
|
2017-05-12 20:12:23 -04:00
|
|
|
lrx0, lry0 := linRegSeries.GetValues(0)
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertInDelta(t, 90.0, lrx0, 0.0000001)
|
|
|
|
testutil.AssertInDelta(t, 90.0, lry0, 0.0000001)
|
2016-07-27 15:34:15 -04:00
|
|
|
|
2017-05-12 20:12:23 -04:00
|
|
|
lrxn, lryn := linRegSeries.GetLastValues()
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertInDelta(t, 80.0, lrxn, 0.0000001)
|
|
|
|
testutil.AssertInDelta(t, 80.0, lryn, 0.0000001)
|
2016-07-27 15:34:15 -04:00
|
|
|
}
|