-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmath_helpers_test.go
More file actions
70 lines (61 loc) · 1.98 KB
/
Copy pathmath_helpers_test.go
File metadata and controls
70 lines (61 loc) · 1.98 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
package nara
import "testing"
func TestTrimmedMeanInt64_Empty(t *testing.T) {
result := TrimmedMeanInt64([]int64{})
if result != 0 {
t.Errorf("Expected 0 for empty slice, got %d", result)
}
}
func TestTrimmedMeanInt64_SingleValue(t *testing.T) {
result := TrimmedMeanInt64([]int64{42})
if result != 42 {
t.Errorf("Expected 42 for single value, got %d", result)
}
}
func TestTrimmedMeanInt64_RemovesOutliers(t *testing.T) {
// Values: 100, 100, 100, 100, 1000000 (outlier)
// Median: 100, so outlier (1000000 > 500) gets filtered
result := TrimmedMeanInt64([]int64{100, 100, 100, 100, 1000000})
if result != 100 {
t.Errorf("Expected 100 (outlier removed), got %d", result)
}
}
func TestTrimmedMeanInt64_NormalValues(t *testing.T) {
// All values within range, should average normally
result := TrimmedMeanInt64([]int64{10, 12, 11, 13, 14})
// Median: 12, bounds: [2, 60], all pass, avg = 60/5 = 12
if result != 12 {
t.Errorf("Expected 12, got %d", result)
}
}
func TestTrimmedMeanInt64_ZeroMedian(t *testing.T) {
// When median is 0, keep values in [-10, 10]
result := TrimmedMeanInt64([]int64{0, 0, 0, 5, -5, 100})
// 100 should be filtered out
// avg of 0, 0, 0, 5, -5 = 0
if result != 0 {
t.Errorf("Expected 0 for zero median case, got %d", result)
}
}
func TestTrimmedMeanInt64_NegativeMedian(t *testing.T) {
// Negative values
result := TrimmedMeanInt64([]int64{-10, -10, -10, -12, -8})
// Median: -10, bounds: [-50, -2]
// All values in range, avg = -50/5 = -10
if result != -10 {
t.Errorf("Expected -10 for negative values, got %d", result)
}
}
func TestTrimmedMeanPositive_FiltersZeros(t *testing.T) {
// Zeros should be filtered before computing
result := TrimmedMeanPositive([]int64{0, 0, 100, 100, 100})
if result != 100 {
t.Errorf("Expected 100 (zeros filtered), got %d", result)
}
}
func TestTrimmedMeanPositive_AllZeros(t *testing.T) {
result := TrimmedMeanPositive([]int64{0, 0, 0})
if result != 0 {
t.Errorf("Expected 0 for all zeros, got %d", result)
}
}