forked from montanaflynn/stats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregression_test.go
More file actions
118 lines (106 loc) · 2 KB
/
regression_test.go
File metadata and controls
118 lines (106 loc) · 2 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package stats
import (
"testing"
)
func TestLinearRegression(t *testing.T) {
data := []Coordinate{
{1, 2.3},
{2, 3.3},
{3, 3.7},
{4, 4.3},
{5, 5.3},
}
r, _ := LinearRegression(data)
a := 2.3800000000000026
if r[0].Y != a {
t.Errorf("%v != %v", r, a)
}
a = 3.0800000000000014
if r[1].Y != a {
t.Errorf("%v != %v", r, a)
}
a = 3.7800000000000002
if r[2].Y != a {
t.Errorf("%v != %v", r, a)
}
a = 4.479999999999999
if r[3].Y != a {
t.Errorf("%v != %v", r, a)
}
a = 5.179999999999998
if r[4].Y != a {
t.Errorf("%v != %v", r, a)
}
_, err := LinearRegression([]Coordinate{})
if err == nil {
t.Errorf("Empty slice should have returned an error")
}
}
func TestExponentialRegression(t *testing.T) {
data := []Coordinate{
{1, 2.3},
{2, 3.3},
{3, 3.7},
{4, 4.3},
{5, 5.3},
}
r, _ := ExponentialRegression(data)
a, _ := Round(r[0].Y, 3)
if a != 2.515 {
t.Errorf("%v != %v", r, 2.515)
}
a, _ = Round(r[1].Y, 3)
if a != 3.032 {
t.Errorf("%v != %v", r, 3.032)
}
a, _ = Round(r[2].Y, 3)
if a != 3.655 {
t.Errorf("%v != %v", r, 3.655)
}
a, _ = Round(r[3].Y, 3)
if a != 4.407 {
t.Errorf("%v != %v", r, 4.407)
}
a, _ = Round(r[4].Y, 3)
if a != 5.313 {
t.Errorf("%v != %v", r, 5.313)
}
_, err := ExponentialRegression([]Coordinate{})
if err == nil {
t.Errorf("Empty slice should have returned an error")
}
}
func TestLogarithmicRegression(t *testing.T) {
data := []Coordinate{
{1, 2.3},
{2, 3.3},
{3, 3.7},
{4, 4.3},
{5, 5.3},
}
r, _ := LogarithmicRegression(data)
a := 2.1520822363811702
if r[0].Y != a {
t.Errorf("%v != %v", r, a)
}
a = 3.3305559222492214
if r[1].Y != a {
t.Errorf("%v != %v", r, a)
}
a = 4.019918836568674
if r[2].Y != a {
t.Errorf("%v != %v", r, a)
}
a = 4.509029608117273
if r[3].Y != a {
t.Errorf("%v != %v", r, a)
}
a = 4.888413396683663
if r[4].Y != a {
t.Errorf("%v != %v", r, a)
}
_, err := LogarithmicRegression([]Coordinate{})
if err == nil {
t.Errorf("Empty slice should have returned an error")
}
}