Skip to content

Commit

Permalink
hit coverage min, but not quite done yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Charczuk committed Aug 6, 2016
1 parent 22e4431 commit e4e2c84
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 4 deletions.
39 changes: 39 additions & 0 deletions bar_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
11 changes: 8 additions & 3 deletions chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 15 additions & 1 deletion date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
31 changes: 31 additions & 0 deletions legend_test.go
Original file line number Diff line number Diff line change
@@ -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())
}

0 comments on commit e4e2c84

Please sign in to comment.