hit coverage min, but not quite done yet.
This commit is contained in:
parent
22e4431c82
commit
e4e2c846e3
4 changed files with 94 additions and 5 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -334,14 +334,19 @@ func TestChartSingleSeries(t *testing.T) {
|
|||
now := time.Now()
|
||||
c := Chart{
|
||||
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",
|
||||
|
|
16
date_test.go
16
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)
|
||||
}
|
||||
|
|
31
legend_test.go
Normal file
31
legend_test.go
Normal file
|
@ -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())
|
||||
}
|
Loading…
Reference in a new issue