forked from wcharczuk/go-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linear_regression_series_test.go
77 lines (59 loc) · 1.89 KB
/
linear_regression_series_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package chart
import (
"testing"
"github.com/wcharczuk/go-chart/v2/testutil"
)
func TestLinearRegressionSeries(t *testing.T) {
// replaced new assertions helper
mainSeries := ContinuousSeries{
Name: "A test series",
XValues: LinearRange(1.0, 100.0),
YValues: LinearRange(1.0, 100.0),
}
linRegSeries := &LinearRegressionSeries{
InnerSeries: mainSeries,
}
lrx0, lry0 := linRegSeries.GetValues(0)
testutil.AssertInDelta(t, 1.0, lrx0, 0.0000001)
testutil.AssertInDelta(t, 1.0, lry0, 0.0000001)
lrxn, lryn := linRegSeries.GetLastValues()
testutil.AssertInDelta(t, 100.0, lrxn, 0.0000001)
testutil.AssertInDelta(t, 100.0, lryn, 0.0000001)
}
func TestLinearRegressionSeriesDesc(t *testing.T) {
// replaced new assertions helper
mainSeries := ContinuousSeries{
Name: "A test series",
XValues: LinearRange(100.0, 1.0),
YValues: LinearRange(100.0, 1.0),
}
linRegSeries := &LinearRegressionSeries{
InnerSeries: mainSeries,
}
lrx0, lry0 := linRegSeries.GetValues(0)
testutil.AssertInDelta(t, 100.0, lrx0, 0.0000001)
testutil.AssertInDelta(t, 100.0, lry0, 0.0000001)
lrxn, lryn := linRegSeries.GetLastValues()
testutil.AssertInDelta(t, 1.0, lrxn, 0.0000001)
testutil.AssertInDelta(t, 1.0, lryn, 0.0000001)
}
func TestLinearRegressionSeriesWindowAndOffset(t *testing.T) {
// replaced new assertions helper
mainSeries := ContinuousSeries{
Name: "A test series",
XValues: LinearRange(100.0, 1.0),
YValues: LinearRange(100.0, 1.0),
}
linRegSeries := &LinearRegressionSeries{
InnerSeries: mainSeries,
Offset: 10,
Limit: 10,
}
testutil.AssertEqual(t, 10, linRegSeries.Len())
lrx0, lry0 := linRegSeries.GetValues(0)
testutil.AssertInDelta(t, 90.0, lrx0, 0.0000001)
testutil.AssertInDelta(t, 90.0, lry0, 0.0000001)
lrxn, lryn := linRegSeries.GetLastValues()
testutil.AssertInDelta(t, 80.0, lrxn, 0.0000001)
testutil.AssertInDelta(t, 80.0, lryn, 0.0000001)
}