2016-07-23 14:50:30 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
assert "github.com/blendlabs/go-assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMarketHoursRangeGetDelta(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
r := &MarketHoursRange{
|
2016-07-31 19:54:09 -04:00
|
|
|
Min: time.Date(2016, 07, 19, 9, 30, 0, 0, Date.Eastern()),
|
|
|
|
Max: time.Date(2016, 07, 22, 16, 00, 0, 0, Date.Eastern()),
|
|
|
|
MarketOpen: NYSEOpen,
|
|
|
|
MarketClose: NYSEClose,
|
|
|
|
HolidayProvider: Date.IsNYSEHoliday,
|
2016-07-23 14:50:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert.NotZero(r.GetDelta())
|
|
|
|
}
|
2016-07-24 12:04:07 -04:00
|
|
|
|
|
|
|
func TestMarketHoursRangeTranslate(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
r := &MarketHoursRange{
|
2016-07-31 19:54:09 -04:00
|
|
|
Min: time.Date(2016, 07, 18, 9, 30, 0, 0, Date.Eastern()),
|
|
|
|
Max: time.Date(2016, 07, 22, 16, 00, 0, 0, Date.Eastern()),
|
|
|
|
MarketOpen: NYSEOpen,
|
|
|
|
MarketClose: NYSEClose,
|
|
|
|
HolidayProvider: Date.IsNYSEHoliday,
|
2016-07-24 12:04:07 -04:00
|
|
|
Domain: 1000,
|
|
|
|
}
|
|
|
|
|
2016-07-31 19:54:09 -04:00
|
|
|
weds := time.Date(2016, 07, 20, 9, 30, 0, 0, Date.Eastern())
|
2016-07-24 12:04:07 -04:00
|
|
|
|
|
|
|
assert.Equal(0, r.Translate(TimeToFloat64(r.Min)))
|
|
|
|
assert.Equal(400, r.Translate(TimeToFloat64(weds)))
|
|
|
|
assert.Equal(1000, r.Translate(TimeToFloat64(r.Max)))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMarketHoursRangeGetTicks(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
r := &MarketHoursRange{
|
2016-07-31 19:54:09 -04:00
|
|
|
Min: time.Date(2016, 07, 18, 9, 30, 0, 0, Date.Eastern()),
|
|
|
|
Max: time.Date(2016, 07, 22, 16, 00, 0, 0, Date.Eastern()),
|
|
|
|
MarketOpen: NYSEOpen,
|
|
|
|
MarketClose: NYSEClose,
|
|
|
|
HolidayProvider: Date.IsNYSEHoliday,
|
2016-07-24 12:04:07 -04:00
|
|
|
Domain: 1000,
|
|
|
|
}
|
|
|
|
|
|
|
|
ticks := r.GetTicks(TimeValueFormatter)
|
|
|
|
assert.NotEmpty(ticks)
|
2016-07-31 19:54:09 -04:00
|
|
|
assert.Len(ticks, 24)
|
2016-07-24 16:48:10 -04:00
|
|
|
assert.NotEqual(TimeToFloat64(r.Min), ticks[0].Value)
|
2016-07-24 12:04:07 -04:00
|
|
|
assert.NotEmpty(ticks[0].Label)
|
|
|
|
}
|