go-chart/bollinger_band_series_test.go

54 lines
1.0 KiB
Go
Raw Normal View History

2016-07-15 18:17:51 +02:00
package chart
import (
2017-04-29 01:07:36 +02:00
"fmt"
2016-07-15 22:27:45 +02:00
"math"
2016-07-15 18:17:51 +02:00
"testing"
"github.com/blendlabs/go-assert"
2017-05-12 23:17:43 +02:00
"github.com/wcharczuk/go-chart/seq"
2016-07-15 18:17:51 +02:00
)
func TestBollingerBandSeries(t *testing.T) {
assert := assert.New(t)
2017-04-29 01:07:36 +02:00
s1 := mockValuesProvider{
2017-05-12 23:17:43 +02:00
X: seq.Range(1.0, 100.0),
2017-05-13 02:06:45 +02:00
Y: seq.RandomValuesWithMax(100, 1024),
2016-07-15 18:17:51 +02:00
}
bbs := &BollingerBandsSeries{
InnerSeries: s1,
}
xvalues := make([]float64, 100)
y1values := make([]float64, 100)
y2values := make([]float64, 100)
for x := 0; x < 100; x++ {
2017-04-29 01:07:36 +02:00
xvalues[x], y1values[x], y2values[x] = bbs.GetBoundedValues(x)
2016-07-15 18:17:51 +02:00
}
2016-07-19 00:08:50 +02:00
for x := bbs.GetPeriod(); x < 100; x++ {
2017-04-29 01:07:36 +02:00
assert.True(y1values[x] > y2values[x], fmt.Sprintf("%v vs. %v", y1values[x], y2values[x]))
2016-07-15 18:17:51 +02:00
}
}
2016-07-15 22:27:45 +02:00
func TestBollingerBandLastValue(t *testing.T) {
assert := assert.New(t)
2017-04-29 01:07:36 +02:00
s1 := mockValuesProvider{
2017-05-12 23:17:43 +02:00
X: seq.Range(1.0, 100.0),
Y: seq.Range(1.0, 100.0),
2016-07-15 22:27:45 +02:00
}
bbs := &BollingerBandsSeries{
InnerSeries: s1,
}
2017-04-29 01:07:36 +02:00
x, y1, y2 := bbs.GetBoundedLastValues()
2016-07-15 22:27:45 +02:00
assert.Equal(100.0, x)
assert.Equal(101, math.Floor(y1))
assert.Equal(83, math.Floor(y2))
2016-07-15 22:27:45 +02:00
}