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()
|
|
|
|
|
|
|
|
candleSeries := CandlestickSeries{
|
2017-05-15 01:33:48 +02:00
|
|
|
XValues: xdata,
|
|
|
|
YValues: ydata,
|
2017-05-14 22:34:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
values := candleSeries.CandleValues()
|
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
|
|
|
}
|