go-chart/market_hours_range_test.go

74 lines
2.0 KiB
Go
Raw Normal View History

2016-07-23 20:50:30 +02:00
package chart
import (
"testing"
"time"
assert "github.com/blendlabs/go-assert"
"github.com/wcharczuk/go-chart/util"
2016-07-23 20:50:30 +02:00
)
func TestMarketHoursRangeGetDelta(t *testing.T) {
assert := assert.New(t)
r := &MarketHoursRange{
Min: time.Date(2016, 07, 19, 9, 30, 0, 0, util.Date.Eastern()),
Max: time.Date(2016, 07, 22, 16, 00, 0, 0, util.Date.Eastern()),
MarketOpen: util.NYSEOpen(),
MarketClose: util.NYSEClose(),
HolidayProvider: util.Date.IsNYSEHoliday,
2016-07-23 20:50:30 +02:00
}
assert.NotZero(r.GetDelta())
}
2016-07-24 18:04:07 +02:00
func TestMarketHoursRangeTranslate(t *testing.T) {
assert := assert.New(t)
r := &MarketHoursRange{
Min: time.Date(2016, 07, 18, 9, 30, 0, 0, util.Date.Eastern()),
Max: time.Date(2016, 07, 22, 16, 00, 0, 0, util.Date.Eastern()),
MarketOpen: util.NYSEOpen(),
MarketClose: util.NYSEClose(),
HolidayProvider: util.Date.IsNYSEHoliday,
2016-07-24 18:04:07 +02:00
Domain: 1000,
}
weds := time.Date(2016, 07, 20, 9, 30, 0, 0, util.Date.Eastern())
2016-07-24 18:04:07 +02:00
assert.Equal(0, r.Translate(util.Time.ToFloat64(r.Min)))
assert.Equal(400, r.Translate(util.Time.ToFloat64(weds)))
assert.Equal(1000, r.Translate(util.Time.ToFloat64(r.Max)))
2016-07-24 18:04:07 +02:00
}
func TestMarketHoursRangeGetTicks(t *testing.T) {
assert := assert.New(t)
2016-08-01 09:50:32 +02:00
r, err := PNG(1024, 1024)
assert.Nil(err)
f, err := GetDefaultFont()
assert.Nil(err)
defaults := Style{
Font: f,
FontSize: 10,
FontColor: ColorBlack,
}
ra := &MarketHoursRange{
Min: util.Date.On(util.NYSEOpen(), util.Date.Date(2016, 07, 18, util.Date.Eastern())),
Max: util.Date.On(util.NYSEClose(), util.Date.Date(2016, 07, 22, util.Date.Eastern())),
MarketOpen: util.NYSEOpen(),
MarketClose: util.NYSEClose(),
HolidayProvider: util.Date.IsNYSEHoliday,
2016-08-01 09:50:32 +02:00
Domain: 1024,
2016-07-24 18:04:07 +02:00
}
2016-08-01 09:50:32 +02:00
ticks := ra.GetTicks(r, defaults, TimeValueFormatter)
2016-07-24 18:04:07 +02:00
assert.NotEmpty(ticks)
2016-08-01 09:50:32 +02:00
assert.Len(ticks, 5)
assert.NotEqual(util.Time.ToFloat64(ra.Min), ticks[0].Value)
2016-07-24 18:04:07 +02:00
assert.NotEmpty(ticks[0].Label)
}