go-chart/bollinger_band_series_test.go

53 lines
1,006 B
Go
Raw Normal View History

2016-07-15 12:17:51 -04:00
package chart
import (
"fmt"
2016-07-15 16:27:45 -04:00
"math"
2016-07-15 12:17:51 -04:00
"testing"
2018-04-05 03:42:38 -04:00
"github.com/blend/go-sdk/assert"
2016-07-15 12:17:51 -04:00
)
func TestBollingerBandSeries(t *testing.T) {
assert := assert.New(t)
s1 := mockValuesProvider{
2019-02-13 21:55:13 -05:00
X: LinearRange(1.0, 100.0),
Y: RandomValuesWithMax(100, 1024),
2016-07-15 12:17:51 -04:00
}
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)
2016-07-15 12:17:51 -04:00
}
2016-07-18 18:08:50 -04:00
for x := bbs.GetPeriod(); x < 100; x++ {
assert.True(y1values[x] > y2values[x], fmt.Sprintf("%v vs. %v", y1values[x], y2values[x]))
2016-07-15 12:17:51 -04:00
}
}
2016-07-15 16:27:45 -04:00
func TestBollingerBandLastValue(t *testing.T) {
assert := assert.New(t)
s1 := mockValuesProvider{
2019-02-13 21:55:13 -05:00
X: LinearRange(1.0, 100.0),
Y: LinearRange(1.0, 100.0),
2016-07-15 16:27:45 -04:00
}
bbs := &BollingerBandsSeries{
InnerSeries: s1,
}
x, y1, y2 := bbs.GetBoundedLastValues()
2016-07-15 16:27:45 -04:00
assert.Equal(100.0, x)
assert.Equal(101, math.Floor(y1))
assert.Equal(83, math.Floor(y2))
2016-07-15 16:27:45 -04:00
}