-
Notifications
You must be signed in to change notification settings - Fork 22
/
stats_test.go
81 lines (53 loc) · 1.4 KB
/
stats_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
78
79
80
81
package indicators
import "testing"
import "reflect"
func TestAvg(t *testing.T) {
var v float64
v = Avg([]float64{1, 2, 3, 4, 5, 6, 7, 8, 9})
if v != 5 {
t.Error("Expected 5, got ", v)
}
}
func TestSum(t *testing.T) {
var v float64
v = Sum([]float64{1, 2, 3, 4, 5, 6, 7, 8, 9})
if v != 45 {
t.Error("Expected 45, got ", v)
}
}
func TestStd(t *testing.T) {
var v float64
v = Std([]float64{1, 2, 3, 4, 5, 6, 7, 8, 9})
if v > 2.738 && v < 2.739 {
t.Error("Expected 2.738, got ", v)
}
}
func TestAddToAll(t *testing.T) {
var v []float64
vTest := mfloat{1, 2, 3, 4, 5, 6, 7, 8, 9}
vResult := []float64{3, 4, 5, 6, 7, 8, 9, 10, 11}
v = vTest.AddToAll(2)
if !reflect.DeepEqual(v, vResult) {
t.Error("Expected [3,4,5,6,7,8,9,10,11], got ", v)
}
}
func TestSubSlices(t *testing.T) {
var testResult []float64
slice1 := []float64{5, 4, 3, 2, 1}
slice2 := []float64{5, 3, 4, 1, 10}
result := []float64{0, 1, -1, 1, -9}
testResult = SubSlices(slice1, slice2)
if !reflect.DeepEqual(result, testResult) {
t.Error("Expected [0, 1, -1, 1, -9], got ", testResult)
}
}
func TestAddSlices(t *testing.T) {
var testResult []float64
slice1 := []float64{5, 4, 3, 2, 1}
slice2 := []float64{5, 3, 4, 1, 10}
result := []float64{10, 7, 7, 3, 11}
testResult = AddSlices(slice1, slice2)
if !reflect.DeepEqual(result, testResult) {
t.Error("Expected [10, 7, 7, 3, 11], got ", testResult)
}
}