-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatswithgo_saraogee_test.go
More file actions
157 lines (150 loc) · 3.39 KB
/
Copy pathstatswithgo_saraogee_test.go
File metadata and controls
157 lines (150 loc) · 3.39 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package main
import (
"testing"
"github.com/montanaflynn/stats"
)
// Benchmarks by adding all the data and performing the regressions without rounding - same as in Python/R
func BenchmarkRegressAll(b *testing.B) {
data1 := []stats.Coordinate{
{X: 10, Y: 8.04},
{X: 8, Y: 6.95},
{X: 13, Y: 7.58},
{X: 9, Y: 8.81},
{X: 11, Y: 8.33},
{X: 14, Y: 9.96},
{X: 6, Y: 7.24},
{X: 4, Y: 4.26},
{X: 12, Y: 10.84},
{X: 7, Y: 4.82},
{X: 5, Y: 5.68},
}
data2 := []stats.Coordinate{
{X: 10, Y: 9.14},
{X: 8, Y: 8.14},
{X: 13, Y: 8.74},
{X: 9, Y: 8.77},
{X: 11, Y: 9.26},
{X: 14, Y: 8.1},
{X: 6, Y: 6.13},
{X: 4, Y: 3.1},
{X: 12, Y: 9.13},
{X: 7, Y: 7.26},
{X: 5, Y: 4.74},
}
data3 := []stats.Coordinate{
{X: 10, Y: 7.46},
{X: 8, Y: 6.77},
{X: 13, Y: 12.74},
{X: 9, Y: 7.11},
{X: 11, Y: 7.81},
{X: 14, Y: 8.84},
{X: 6, Y: 6.08},
{X: 4, Y: 5.39},
{X: 12, Y: 8.15},
{X: 7, Y: 6.42},
{X: 5, Y: 5.73},
}
data4 := []stats.Coordinate{
{X: 8, Y: 6.58},
{X: 8, Y: 5.76},
{X: 8, Y: 7.71},
{X: 8, Y: 8.84},
{X: 8, Y: 8.47},
{X: 8, Y: 7.04},
{X: 8, Y: 5.25},
{X: 19, Y: 12.5},
{X: 8, Y: 5.56},
{X: 8, Y: 7.91},
{X: 8, Y: 6.89},
}
Regress(data1)
Regress(data2)
Regress(data3)
Regress(data4)
}
// Unit test for Regress function ensuring that the gradient and intercepts are 0.5 and 3 for each dataset.
// Error messages identify which value is incorrect (gradient/intercept) for each of the four datasets.
func TestRegress(t *testing.T) {
gradient_all := 0.5
intercept_all := 3.0
data1 := []stats.Coordinate{
{X: 10, Y: 8.04},
{X: 8, Y: 6.95},
{X: 13, Y: 7.58},
{X: 9, Y: 8.81},
{X: 11, Y: 8.33},
{X: 14, Y: 9.96},
{X: 6, Y: 7.24},
{X: 4, Y: 4.26},
{X: 12, Y: 10.84},
{X: 7, Y: 4.82},
{X: 5, Y: 5.68},
}
data2 := []stats.Coordinate{
{X: 10, Y: 9.14},
{X: 8, Y: 8.14},
{X: 13, Y: 8.74},
{X: 9, Y: 8.77},
{X: 11, Y: 9.26},
{X: 14, Y: 8.1},
{X: 6, Y: 6.13},
{X: 4, Y: 3.1},
{X: 12, Y: 9.13},
{X: 7, Y: 7.26},
{X: 5, Y: 4.74},
}
data3 := []stats.Coordinate{
{X: 10, Y: 7.46},
{X: 8, Y: 6.77},
{X: 13, Y: 12.74},
{X: 9, Y: 7.11},
{X: 11, Y: 7.81},
{X: 14, Y: 8.84},
{X: 6, Y: 6.08},
{X: 4, Y: 5.39},
{X: 12, Y: 8.15},
{X: 7, Y: 6.42},
{X: 5, Y: 5.73},
}
data4 := []stats.Coordinate{
{X: 8, Y: 6.58},
{X: 8, Y: 5.76},
{X: 8, Y: 7.71},
{X: 8, Y: 8.84},
{X: 8, Y: 8.47},
{X: 8, Y: 7.04},
{X: 8, Y: 5.25},
{X: 19, Y: 12.5},
{X: 8, Y: 5.56},
{X: 8, Y: 7.91},
{X: 8, Y: 6.89},
}
gradient1, intercept1 := Regress(data1)
gradient2, intercept2 := Regress(data2)
gradient3, intercept3 := Regress(data3)
gradient4, intercept4 := Regress(data4)
if gradient1 != gradient_all {
t.Error("The gradient in the 1st dataset is incorrect")
}
if gradient2 != gradient_all {
t.Error("The gradient in the 2nd dataset is incorrect")
}
if gradient3 != gradient_all {
t.Error("The gradient in the 3rd dataset is incorrect")
}
if gradient4 != gradient_all {
t.Error("The gradient in the 4th dataset is incorrect")
}
if intercept1 != intercept_all {
t.Error("The intercept in the 1st dataset is incorrect")
}
if intercept2 != intercept_all {
t.Error("The intercept in the 2nd dataset is incorrect")
}
if intercept3 != intercept_all {
t.Error("The intercept in the 3rd dataset is incorrect")
}
if intercept4 != intercept_all {
t.Error("The intercept in the 4th dataset is incorrect")
}
}