go-chart/sequence/time_test.go

84 lines
2.2 KiB
Go
Raw Normal View History

2017-04-30 00:12:39 -04:00
package sequence
2016-07-29 21:24:25 -04:00
import (
"testing"
2016-07-31 19:54:09 -04:00
"time"
2016-07-29 21:24:25 -04:00
assert "github.com/blendlabs/go-assert"
2017-04-30 01:44:17 -04:00
"github.com/wcharczuk/go-chart/util"
2016-07-29 21:24:25 -04:00
)
2017-04-30 01:44:17 -04:00
func TestTimeMarketHours(t *testing.T) {
2016-07-29 21:24:25 -04:00
assert := assert.New(t)
2017-04-30 01:44:17 -04:00
today := time.Date(2016, 07, 01, 12, 0, 0, 0, util.Date.Eastern())
mh := Time.MarketHours(today, today, util.NYSEOpen(), util.NYSEClose(), util.Date.IsNYSEHoliday)
2016-08-01 03:50:32 -04:00
assert.Len(mh, 8)
2017-04-30 01:44:17 -04:00
assert.Equal(util.Date.Eastern(), mh[0].Location())
2016-08-01 03:50:32 -04:00
}
2017-04-30 01:44:17 -04:00
func TestTimeMarketHourQuarters(t *testing.T) {
2016-08-01 03:50:32 -04:00
assert := assert.New(t)
2017-04-30 01:44:17 -04:00
today := time.Date(2016, 07, 01, 12, 0, 0, 0, util.Date.Eastern())
mh := Time.MarketHourQuarters(today, today, util.NYSEOpen(), util.NYSEClose(), util.Date.IsNYSEHoliday)
2016-08-01 03:50:32 -04:00
assert.Len(mh, 4)
assert.Equal(9, mh[0].Hour())
assert.Equal(30, mh[0].Minute())
2017-04-30 01:44:17 -04:00
assert.Equal(util.Date.Eastern(), mh[0].Location())
2016-08-01 03:50:32 -04:00
assert.Equal(12, mh[1].Hour())
assert.Equal(00, mh[1].Minute())
2017-04-30 01:44:17 -04:00
assert.Equal(util.Date.Eastern(), mh[1].Location())
2016-08-01 03:50:32 -04:00
assert.Equal(14, mh[2].Hour())
assert.Equal(00, mh[2].Minute())
2017-04-30 01:44:17 -04:00
assert.Equal(util.Date.Eastern(), mh[2].Location())
2016-07-31 19:54:09 -04:00
}
2017-02-28 20:55:48 -05:00
2017-04-30 01:44:17 -04:00
func TestTimeHours(t *testing.T) {
2017-02-28 20:55:48 -05:00
assert := assert.New(t)
today := time.Date(2016, 07, 01, 12, 0, 0, 0, time.UTC)
2017-04-30 01:44:17 -04:00
seq := Time.Hours(today, 24)
2017-02-28 20:55:48 -05:00
2017-04-30 01:44:17 -04:00
end := Time.End(seq)
2017-02-28 20:55:48 -05:00
assert.Len(seq, 24)
assert.Equal(2016, end.Year())
assert.Equal(07, int(end.Month()))
assert.Equal(02, end.Day())
assert.Equal(11, end.Hour())
}
func TestSequenceHoursFill(t *testing.T) {
assert := assert.New(t)
xdata := []time.Time{
time.Date(2016, 07, 01, 12, 0, 0, 0, time.UTC),
time.Date(2016, 07, 01, 13, 0, 0, 0, time.UTC),
time.Date(2016, 07, 01, 14, 0, 0, 0, time.UTC),
time.Date(2016, 07, 02, 4, 0, 0, 0, time.UTC),
time.Date(2016, 07, 02, 5, 0, 0, 0, time.UTC),
time.Date(2016, 07, 03, 12, 0, 0, 0, time.UTC),
time.Date(2016, 07, 03, 14, 0, 0, 0, time.UTC),
}
ydata := []float64{
1.1,
1.2,
1.4,
0.8,
2.1,
0.4,
0.6,
}
2017-04-30 01:44:17 -04:00
filledTimes, filledValues := Time.HoursFilled(xdata, ydata)
assert.Len(filledTimes, util.Date.DiffHours(Time.Start(xdata), Time.End(xdata))+1)
2017-02-28 20:55:48 -05:00
assert.Equal(len(filledValues), len(filledTimes))
assert.NotZero(filledValues[0])
assert.NotZero(filledValues[len(filledValues)-1])
assert.NotZero(filledValues[16])
}