diff --git a/bar_chart_test.go b/bar_chart_test.go index 3085f4d..75d9886 100644 --- a/bar_chart_test.go +++ b/bar_chart_test.go @@ -8,6 +8,32 @@ import ( assert "github.com/blendlabs/go-assert" ) +func TestBarChartRender(t *testing.T) { + assert := assert.New(t) + + bc := BarChart{ + Width: 1024, + Title: "Test Title", + TitleStyle: StyleShow(), + XAxis: StyleShow(), + YAxis: YAxis{ + Style: StyleShow(), + }, + Bars: []Value{ + {Value: 1.0, Label: "One"}, + {Value: 2.0, Label: "Two"}, + {Value: 3.0, Label: "Three"}, + {Value: 4.0, Label: "Four"}, + {Value: 5.0, Label: "Five"}, + }, + } + + buf := bytes.NewBuffer([]byte{}) + err := bc.Render(PNG, buf) + assert.Nil(err) + assert.NotZero(buf.Len()) +} + func TestBarChartProps(t *testing.T) { assert := assert.New(t) @@ -255,5 +281,18 @@ func TestBarChartCalculateEffectiveBarWidth(t *testing.T) { assert.Equal(spacing, bs) assert.Equal(barWidth, bw) assert.Equal(cb.Width()+1, total) - +} + +func TestBarChatGetTitleFontSize(t *testing.T) { + assert := assert.New(t) + size := BarChart{Width: 2049, Height: 2049}.getTitleFontSize() + assert.Equal(48, size) + size = BarChart{Width: 1025, Height: 1025}.getTitleFontSize() + assert.Equal(24, size) + size = BarChart{Width: 513, Height: 513}.getTitleFontSize() + assert.Equal(18, size) + size = BarChart{Width: 257, Height: 257}.getTitleFontSize() + assert.Equal(12, size) + size = BarChart{Width: 128, Height: 128}.getTitleFontSize() + assert.Equal(10, size) } diff --git a/chart_test.go b/chart_test.go index e313fdf..fdaf7c3 100644 --- a/chart_test.go +++ b/chart_test.go @@ -333,15 +333,20 @@ func TestChartSingleSeries(t *testing.T) { assert := assert.New(t) now := time.Now() c := Chart{ - Title: "Hello!", - Width: 1024, - Height: 400, + Title: "Hello!", + TitleStyle: StyleShow(), + Width: 1024, + Height: 400, YAxis: YAxis{ + Style: StyleShow(), Range: &ContinuousRange{ Min: 0.0, Max: 4.0, }, }, + XAxis: XAxis{ + Style: StyleShow(), + }, Series: []Series{ TimeSeries{ Name: "goog", diff --git a/date_test.go b/date_test.go index 7403f35..70194f7 100644 --- a/date_test.go +++ b/date_test.go @@ -45,7 +45,6 @@ func TestDateOn(t *testing.T) { assert.Equal(3, ts.Second()) assert.Equal(2, ts.Nanosecond()) assert.Equal(time.UTC, ts.Location()) - } func TestDateNoonOn(t *testing.T) { @@ -222,3 +221,18 @@ func TestDateNextDayOfWeek(t *testing.T) { assert.Equal(time.UTC, nextSunday.Location()) assert.Equal(time.UTC, nextMonday.Location()) } + +func TestDateIsNYSEHoliday(t *testing.T) { + assert := assert.New(t) + + cursor := time.Date(2013, 01, 01, 0, 0, 0, 0, time.UTC) + end := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC) + var holidays int + for Date.Before(cursor, end) { + if Date.IsNYSEHoliday(cursor) { + holidays++ + } + cursor = cursor.AddDate(0, 0, 1) + } + assert.Equal(holidays, 55) +} diff --git a/legend_test.go b/legend_test.go new file mode 100644 index 0000000..720506c --- /dev/null +++ b/legend_test.go @@ -0,0 +1,31 @@ +package chart + +import ( + "bytes" + "testing" + + "github.com/blendlabs/go-assert" +) + +func TestLegend(t *testing.T) { + assert := assert.New(t) + + graph := Chart{ + Series: []Series{ + ContinuousSeries{ + Name: "A test series", + XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, + YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, + }, + }, + } + + //note we have to do this as a separate step because we need a reference to graph + graph.Elements = []Renderable{ + Legend(&graph), + } + buf := bytes.NewBuffer([]byte{}) + err := graph.Render(PNG, buf) + assert.Nil(err) + assert.NotZero(buf.Len()) +}