forked from wcharczuk/go-chart
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bollinger_band_series_test.go
53 lines (41 loc) · 1.01 KB
/
bollinger_band_series_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
package chart
import (
"fmt"
"math"
"testing"
"github.com/blend/go-sdk/assert"
"github.com/beevee/go-chart/seq"
)
func TestBollingerBandSeries(t *testing.T) {
assert := assert.New(t)
s1 := mockValuesProvider{
X: seq.Range(1.0, 100.0),
Y: seq.RandomValuesWithMax(100, 1024),
}
bbs := &BollingerBandsSeries{
InnerSeries: s1,
}
xvalues := make([]float64, 100)
y1values := make([]float64, 100)
y2values := make([]float64, 100)
for x := 0; x < 100; x++ {
xvalues[x], y1values[x], y2values[x] = bbs.GetBoundedValues(x)
}
for x := bbs.GetPeriod(); x < 100; x++ {
assert.True(y1values[x] > y2values[x], fmt.Sprintf("%v vs. %v", y1values[x], y2values[x]))
}
}
func TestBollingerBandLastValue(t *testing.T) {
assert := assert.New(t)
s1 := mockValuesProvider{
X: seq.Range(1.0, 100.0),
Y: seq.Range(1.0, 100.0),
}
bbs := &BollingerBandsSeries{
InnerSeries: s1,
}
x, y1, y2 := bbs.GetBoundedLastValues()
assert.Equal(100.0, x)
assert.Equal(101, math.Floor(y1))
assert.Equal(83, math.Floor(y2))
}