-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathstats_test.go
More file actions
236 lines (183 loc) · 5.11 KB
/
stats_test.go
File metadata and controls
236 lines (183 loc) · 5.11 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package main
import (
"testing"
)
// ========================================
// Continuous Stats Tests
// ========================================
func TestContinuousStats_Summary(t *testing.T) {
cs := &ContinuousStats{}
data := []string{"10.5", "20.3", "15.7", "25.2", "18.9"}
cs.summary(data)
// Verify data was processed
summaryData := cs.getSummaryData()
if len(summaryData) == 0 {
t.Error("Expected summary data, got empty")
}
}
func TestContinuousStats_EmptyData(t *testing.T) {
cs := &ContinuousStats{}
data := []string{}
cs.summary(data)
summaryData := cs.getSummaryData()
if len(summaryData) == 0 {
t.Log("Empty data handled correctly")
}
}
func TestContinuousStats_SingleValue(t *testing.T) {
cs := &ContinuousStats{}
data := []string{"42.0"}
cs.summary(data)
summaryData := cs.getSummaryData()
if len(summaryData) == 0 {
t.Error("Should handle single value")
}
}
func TestContinuousStats_WithNaN(t *testing.T) {
cs := &ContinuousStats{}
data := []string{"10.5", "NaN", "15.7", "invalid", "18.9"}
cs.summary(data)
// Should handle invalid/NaN values gracefully
summaryData := cs.getSummaryData()
if len(summaryData) == 0 {
t.Error("Should produce summary even with invalid values")
}
}
// ========================================
// Discrete Stats Tests
// ========================================
func TestDiscreteStats_Summary(t *testing.T) {
ds := &DiscreteStats{}
data := []string{"Apple", "Banana", "Apple", "Orange", "Banana", "Apple"}
ds.summary(data)
summaryData := ds.getSummaryData()
if len(summaryData) == 0 {
t.Error("Expected summary data, got empty")
}
}
func TestDiscreteStats_EmptyData(t *testing.T) {
ds := &DiscreteStats{}
data := []string{}
ds.summary(data)
summaryData := ds.getSummaryData()
if len(summaryData) == 0 {
t.Log("Empty data handled correctly")
}
}
func TestDiscreteStats_UniqueValues(t *testing.T) {
ds := &DiscreteStats{}
data := []string{"A", "B", "C", "D", "E"}
ds.summary(data)
summaryData := ds.getSummaryData()
if len(summaryData) == 0 {
t.Error("Should handle all unique values")
}
}
func TestDiscreteStats_RepeatedValues(t *testing.T) {
ds := &DiscreteStats{}
data := []string{"X", "X", "X", "X", "X"}
ds.summary(data)
summaryData := ds.getSummaryData()
if len(summaryData) == 0 {
t.Error("Should handle repeated values")
}
}
// ========================================
// Stats Interface Tests
// ========================================
func TestStatsSummary_Interface(t *testing.T) {
// Test that both types implement the interface
var _ statsSummary = &ContinuousStats{}
var _ statsSummary = &DiscreteStats{}
t.Log("Both stats types implement statsSummary interface")
}
func TestGetSummaryStr(t *testing.T) {
cs := &ContinuousStats{}
data := []string{"10", "20", "30"}
str := cs.getSummaryStr(data)
if len(str) == 0 {
t.Error("getSummaryStr should return non-empty string")
}
}
// ========================================
// Performance Tests
// ========================================
func BenchmarkContinuousStats(b *testing.B) {
data := make([]string, 1000)
for i := 0; i < 1000; i++ {
data[i] = F2S(float64(i) * 1.5)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
cs := &ContinuousStats{}
cs.summary(data)
}
}
func BenchmarkDiscreteStats(b *testing.B) {
data := make([]string, 1000)
categories := []string{"A", "B", "C", "D", "E"}
for i := 0; i < 1000; i++ {
data[i] = categories[i%len(categories)]
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
ds := &DiscreteStats{}
ds.summary(data)
}
}
// ========================================
// Plot Tests
// ========================================
func TestContinuousStats_GetPlot(t *testing.T) {
cs := &ContinuousStats{}
data := []string{"10", "20", "15", "25", "30", "18", "22", "27", "12", "16"}
cs.summary(data)
plot := cs.getPlot()
if len(plot) == 0 {
t.Error("Expected plot output, got empty string")
}
if plot == "No data to plot" {
t.Error("Should generate plot for valid data")
}
t.Logf("Plot output:\n%s", plot)
}
func TestContinuousStats_GetPlot_EmptyData(t *testing.T) {
cs := &ContinuousStats{}
data := []string{}
cs.summary(data)
plot := cs.getPlot()
if plot != "No data to plot" {
t.Errorf("Expected 'No data to plot', got: %s", plot)
}
}
func TestContinuousStats_GetPlot_IdenticalValues(t *testing.T) {
cs := &ContinuousStats{}
data := []string{"42", "42", "42", "42", "42"}
cs.summary(data)
plot := cs.getPlot()
if plot != "All values are identical" {
t.Errorf("Expected 'All values are identical', got: %s", plot)
}
}
func TestDiscreteStats_GetPlot(t *testing.T) {
ds := &DiscreteStats{}
data := []string{"A", "B", "A", "C", "A", "B", "A", "D", "A", "B"}
ds.summary(data)
plot := ds.getPlot()
if len(plot) == 0 {
t.Error("Expected plot output, got empty string")
}
if plot == "No data to plot" {
t.Error("Should generate plot for valid data")
}
t.Logf("Plot output:\n%s", plot)
}
func TestDiscreteStats_GetPlot_EmptyData(t *testing.T) {
ds := &DiscreteStats{}
data := []string{}
ds.summary(data)
plot := ds.getPlot()
if plot != "No data to plot" {
t.Errorf("Expected 'No data to plot', got: %s", plot)
}
}