-
Notifications
You must be signed in to change notification settings - Fork 142
/
indicator_variance_test.go
36 lines (29 loc) · 1.01 KB
/
indicator_variance_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
package techan
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestVarianceIndicator(t *testing.T) {
t.Run("when index is less than 1, returns 0", func(t *testing.T) {
series := mockTimeSeries("0", "10")
stdDev := NewStandardDeviationIndicator(NewClosePriceIndicator(series))
assert.EqualValues(t, "0", stdDev.Calculate(0).String())
})
t.Run("returns the standard deviation when index > 2", func(t *testing.T) {
series := mockTimeSeriesFl(
10,
2,
38,
23,
38,
23,
21)
varInd := NewVarianceIndicator(NewClosePriceIndicator(series))
assert.EqualValues(t, "16.00", varInd.Calculate(1).FormattedString(2))
assert.EqualValues(t, "238.22", varInd.Calculate(2).FormattedString(2))
assert.EqualValues(t, "186.19", varInd.Calculate(3).FormattedString(2))
assert.EqualValues(t, "211.36", varInd.Calculate(4).FormattedString(2))
assert.EqualValues(t, "176.22", varInd.Calculate(5).FormattedString(2))
assert.EqualValues(t, "151.27", varInd.Calculate(6).FormattedString(2))
})
}