go-chart/candlestick_series_test.go

53 lines
1.1 KiB
Go
Raw Normal View History

2017-05-14 22:34:46 +02:00
package chart
import (
"math/rand"
"testing"
"time"
assert "github.com/blendlabs/go-assert"
"github.com/wcharczuk/go-chart/util"
)
func generateDummyStockData() (times []time.Time, prices []float64) {
2017-05-15 01:33:48 +02:00
start := util.Date.On(util.NYSEOpen(), time.Date(2017, 05, 15, 0, 0, 0, 0, util.Date.Eastern()))
cursor := start
2017-05-14 22:34:46 +02:00
for day := 0; day < 60; day++ {
2017-05-15 01:33:48 +02:00
if util.Date.IsWeekendDay(cursor.Weekday()) {
cursor = start.AddDate(0, 0, day)
continue
}
2017-05-14 22:34:46 +02:00
for hour := 0; hour < 7; hour++ {
for minute := 0; minute < 60; minute++ {
times = append(times, cursor)
prices = append(prices, rand.Float64()*256)
cursor = cursor.Add(time.Minute)
}
cursor = cursor.Add(time.Hour)
}
2017-05-15 01:33:48 +02:00
cursor = start.AddDate(0, 0, day)
2017-05-14 22:34:46 +02:00
}
2017-05-15 01:33:48 +02:00
2017-05-14 22:34:46 +02:00
return
}
func TestCandlestickSeriesCandleValues(t *testing.T) {
assert := assert.New(t)
xdata, ydata := generateDummyStockData()
2017-05-17 02:50:17 +02:00
candleSeries := &CandlestickSeries{
InnerSeries: TimeSeries{
XValues: xdata,
YValues: ydata,
},
2017-05-14 22:34:46 +02:00
}
2017-05-17 02:50:17 +02:00
values := candleSeries.GetCandleValues()
2017-05-15 01:33:48 +02:00
assert.Len(values, 43) // should be 60 days per the generator.
2017-05-14 22:34:46 +02:00
}