Adds support for go mod (finally) (#164)
This commit is contained in:
parent
962b9abdec
commit
c1468e8ae4
89 changed files with 1162 additions and 965 deletions
205
chart_test.go
205
chart_test.go
|
|
@ -8,58 +8,57 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/blend/go-sdk/assert"
|
||||
|
||||
"github.com/wcharczuk/go-chart/drawing"
|
||||
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||
)
|
||||
|
||||
func TestChartGetDPI(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
unset := Chart{}
|
||||
assert.Equal(DefaultDPI, unset.GetDPI())
|
||||
assert.Equal(192, unset.GetDPI(192))
|
||||
testutil.AssertEqual(t, DefaultDPI, unset.GetDPI())
|
||||
testutil.AssertEqual(t, 192, unset.GetDPI(192))
|
||||
|
||||
set := Chart{DPI: 128}
|
||||
assert.Equal(128, set.GetDPI())
|
||||
assert.Equal(128, set.GetDPI(192))
|
||||
testutil.AssertEqual(t, 128, set.GetDPI())
|
||||
testutil.AssertEqual(t, 128, set.GetDPI(192))
|
||||
}
|
||||
|
||||
func TestChartGetFont(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
f, err := GetDefaultFont()
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
unset := Chart{}
|
||||
assert.Nil(unset.GetFont())
|
||||
testutil.AssertNil(t, unset.GetFont())
|
||||
|
||||
set := Chart{Font: f}
|
||||
assert.NotNil(set.GetFont())
|
||||
testutil.AssertNotNil(t, set.GetFont())
|
||||
}
|
||||
|
||||
func TestChartGetWidth(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
unset := Chart{}
|
||||
assert.Equal(DefaultChartWidth, unset.GetWidth())
|
||||
testutil.AssertEqual(t, DefaultChartWidth, unset.GetWidth())
|
||||
|
||||
set := Chart{Width: DefaultChartWidth + 10}
|
||||
assert.Equal(DefaultChartWidth+10, set.GetWidth())
|
||||
testutil.AssertEqual(t, DefaultChartWidth+10, set.GetWidth())
|
||||
}
|
||||
|
||||
func TestChartGetHeight(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
unset := Chart{}
|
||||
assert.Equal(DefaultChartHeight, unset.GetHeight())
|
||||
testutil.AssertEqual(t, DefaultChartHeight, unset.GetHeight())
|
||||
|
||||
set := Chart{Height: DefaultChartHeight + 10}
|
||||
assert.Equal(DefaultChartHeight+10, set.GetHeight())
|
||||
testutil.AssertEqual(t, DefaultChartHeight+10, set.GetHeight())
|
||||
}
|
||||
|
||||
func TestChartGetRanges(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
c := Chart{
|
||||
Series: []Series{
|
||||
|
|
@ -80,14 +79,14 @@ func TestChartGetRanges(t *testing.T) {
|
|||
}
|
||||
|
||||
xrange, yrange, yrangeAlt := c.getRanges()
|
||||
assert.Equal(-2.0, xrange.GetMin())
|
||||
assert.Equal(5.0, xrange.GetMax())
|
||||
testutil.AssertEqual(t, -2.0, xrange.GetMin())
|
||||
testutil.AssertEqual(t, 5.0, xrange.GetMax())
|
||||
|
||||
assert.Equal(-2.1, yrange.GetMin())
|
||||
assert.Equal(4.5, yrange.GetMax())
|
||||
testutil.AssertEqual(t, -2.1, yrange.GetMin())
|
||||
testutil.AssertEqual(t, 4.5, yrange.GetMax())
|
||||
|
||||
assert.Equal(10.0, yrangeAlt.GetMin())
|
||||
assert.Equal(14.0, yrangeAlt.GetMax())
|
||||
testutil.AssertEqual(t, 10.0, yrangeAlt.GetMin())
|
||||
testutil.AssertEqual(t, 14.0, yrangeAlt.GetMax())
|
||||
|
||||
cSet := Chart{
|
||||
XAxis: XAxis{
|
||||
|
|
@ -117,18 +116,18 @@ func TestChartGetRanges(t *testing.T) {
|
|||
}
|
||||
|
||||
xr2, yr2, yra2 := cSet.getRanges()
|
||||
assert.Equal(9.8, xr2.GetMin())
|
||||
assert.Equal(19.8, xr2.GetMax())
|
||||
testutil.AssertEqual(t, 9.8, xr2.GetMin())
|
||||
testutil.AssertEqual(t, 19.8, xr2.GetMax())
|
||||
|
||||
assert.Equal(9.9, yr2.GetMin())
|
||||
assert.Equal(19.9, yr2.GetMax())
|
||||
testutil.AssertEqual(t, 9.9, yr2.GetMin())
|
||||
testutil.AssertEqual(t, 19.9, yr2.GetMax())
|
||||
|
||||
assert.Equal(9.7, yra2.GetMin())
|
||||
assert.Equal(19.7, yra2.GetMax())
|
||||
testutil.AssertEqual(t, 9.7, yra2.GetMin())
|
||||
testutil.AssertEqual(t, 19.7, yra2.GetMax())
|
||||
}
|
||||
|
||||
func TestChartGetRangesUseTicks(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
// this test asserts that ticks should supercede manual ranges when generating the overall ranges.
|
||||
|
||||
|
|
@ -156,15 +155,15 @@ func TestChartGetRangesUseTicks(t *testing.T) {
|
|||
}
|
||||
|
||||
xr, yr, yar := c.getRanges()
|
||||
assert.Equal(-2.0, xr.GetMin())
|
||||
assert.Equal(2.0, xr.GetMax())
|
||||
assert.Equal(0.0, yr.GetMin())
|
||||
assert.Equal(5.0, yr.GetMax())
|
||||
assert.True(yar.IsZero(), yar.String())
|
||||
testutil.AssertEqual(t, -2.0, xr.GetMin())
|
||||
testutil.AssertEqual(t, 2.0, xr.GetMax())
|
||||
testutil.AssertEqual(t, 0.0, yr.GetMin())
|
||||
testutil.AssertEqual(t, 5.0, yr.GetMax())
|
||||
testutil.AssertTrue(t, yar.IsZero(), yar.String())
|
||||
}
|
||||
|
||||
func TestChartGetRangesUseUserRanges(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
c := Chart{
|
||||
YAxis: YAxis{
|
||||
|
|
@ -182,15 +181,15 @@ func TestChartGetRangesUseUserRanges(t *testing.T) {
|
|||
}
|
||||
|
||||
xr, yr, yar := c.getRanges()
|
||||
assert.Equal(-2.0, xr.GetMin())
|
||||
assert.Equal(2.0, xr.GetMax())
|
||||
assert.Equal(-5.0, yr.GetMin())
|
||||
assert.Equal(5.0, yr.GetMax())
|
||||
assert.True(yar.IsZero(), yar.String())
|
||||
testutil.AssertEqual(t, -2.0, xr.GetMin())
|
||||
testutil.AssertEqual(t, 2.0, xr.GetMax())
|
||||
testutil.AssertEqual(t, -5.0, yr.GetMin())
|
||||
testutil.AssertEqual(t, 5.0, yr.GetMax())
|
||||
testutil.AssertTrue(t, yar.IsZero(), yar.String())
|
||||
}
|
||||
|
||||
func TestChartGetBackgroundStyle(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
c := Chart{
|
||||
Background: Style{
|
||||
|
|
@ -199,11 +198,11 @@ func TestChartGetBackgroundStyle(t *testing.T) {
|
|||
}
|
||||
|
||||
bs := c.getBackgroundStyle()
|
||||
assert.Equal(bs.FillColor.String(), drawing.ColorBlack.String())
|
||||
testutil.AssertEqual(t, bs.FillColor.String(), drawing.ColorBlack.String())
|
||||
}
|
||||
|
||||
func TestChartGetCanvasStyle(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
c := Chart{
|
||||
Canvas: Style{
|
||||
|
|
@ -212,19 +211,19 @@ func TestChartGetCanvasStyle(t *testing.T) {
|
|||
}
|
||||
|
||||
bs := c.getCanvasStyle()
|
||||
assert.Equal(bs.FillColor.String(), drawing.ColorBlack.String())
|
||||
testutil.AssertEqual(t, bs.FillColor.String(), drawing.ColorBlack.String())
|
||||
}
|
||||
|
||||
func TestChartGetDefaultCanvasBox(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
c := Chart{}
|
||||
canvasBoxDefault := c.getDefaultCanvasBox()
|
||||
assert.False(canvasBoxDefault.IsZero())
|
||||
assert.Equal(DefaultBackgroundPadding.Top, canvasBoxDefault.Top)
|
||||
assert.Equal(DefaultBackgroundPadding.Left, canvasBoxDefault.Left)
|
||||
assert.Equal(c.GetWidth()-DefaultBackgroundPadding.Right, canvasBoxDefault.Right)
|
||||
assert.Equal(c.GetHeight()-DefaultBackgroundPadding.Bottom, canvasBoxDefault.Bottom)
|
||||
testutil.AssertFalse(t, canvasBoxDefault.IsZero())
|
||||
testutil.AssertEqual(t, DefaultBackgroundPadding.Top, canvasBoxDefault.Top)
|
||||
testutil.AssertEqual(t, DefaultBackgroundPadding.Left, canvasBoxDefault.Left)
|
||||
testutil.AssertEqual(t, c.GetWidth()-DefaultBackgroundPadding.Right, canvasBoxDefault.Right)
|
||||
testutil.AssertEqual(t, c.GetHeight()-DefaultBackgroundPadding.Bottom, canvasBoxDefault.Bottom)
|
||||
|
||||
custom := Chart{
|
||||
Background: Style{
|
||||
|
|
@ -237,15 +236,15 @@ func TestChartGetDefaultCanvasBox(t *testing.T) {
|
|||
},
|
||||
}
|
||||
canvasBoxCustom := custom.getDefaultCanvasBox()
|
||||
assert.False(canvasBoxCustom.IsZero())
|
||||
assert.Equal(DefaultBackgroundPadding.Top+1, canvasBoxCustom.Top)
|
||||
assert.Equal(DefaultBackgroundPadding.Left+1, canvasBoxCustom.Left)
|
||||
assert.Equal(c.GetWidth()-(DefaultBackgroundPadding.Right+1), canvasBoxCustom.Right)
|
||||
assert.Equal(c.GetHeight()-(DefaultBackgroundPadding.Bottom+1), canvasBoxCustom.Bottom)
|
||||
testutil.AssertFalse(t, canvasBoxCustom.IsZero())
|
||||
testutil.AssertEqual(t, DefaultBackgroundPadding.Top+1, canvasBoxCustom.Top)
|
||||
testutil.AssertEqual(t, DefaultBackgroundPadding.Left+1, canvasBoxCustom.Left)
|
||||
testutil.AssertEqual(t, c.GetWidth()-(DefaultBackgroundPadding.Right+1), canvasBoxCustom.Right)
|
||||
testutil.AssertEqual(t, c.GetHeight()-(DefaultBackgroundPadding.Bottom+1), canvasBoxCustom.Bottom)
|
||||
}
|
||||
|
||||
func TestChartGetValueFormatters(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
c := Chart{
|
||||
Series: []Series{
|
||||
|
|
@ -266,16 +265,16 @@ func TestChartGetValueFormatters(t *testing.T) {
|
|||
}
|
||||
|
||||
dxf, dyf, dyaf := c.getValueFormatters()
|
||||
assert.NotNil(dxf)
|
||||
assert.NotNil(dyf)
|
||||
assert.NotNil(dyaf)
|
||||
testutil.AssertNotNil(t, dxf)
|
||||
testutil.AssertNotNil(t, dyf)
|
||||
testutil.AssertNotNil(t, dyaf)
|
||||
}
|
||||
|
||||
func TestChartHasAxes(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
assert.True(Chart{}.hasAxes())
|
||||
assert.False(Chart{XAxis: XAxis{Style: Hidden()}, YAxis: YAxis{Style: Hidden()}, YAxisSecondary: YAxis{Style: Hidden()}}.hasAxes())
|
||||
testutil.AssertTrue(t, Chart{}.hasAxes())
|
||||
testutil.AssertFalse(t, Chart{XAxis: XAxis{Style: Hidden()}, YAxis: YAxis{Style: Hidden()}, YAxisSecondary: YAxis{Style: Hidden()}}.hasAxes())
|
||||
|
||||
x := Chart{
|
||||
XAxis: XAxis{
|
||||
|
|
@ -288,7 +287,7 @@ func TestChartHasAxes(t *testing.T) {
|
|||
Style: Hidden(),
|
||||
},
|
||||
}
|
||||
assert.True(x.hasAxes())
|
||||
testutil.AssertTrue(t, x.hasAxes())
|
||||
|
||||
y := Chart{
|
||||
XAxis: XAxis{
|
||||
|
|
@ -301,7 +300,7 @@ func TestChartHasAxes(t *testing.T) {
|
|||
Style: Hidden(),
|
||||
},
|
||||
}
|
||||
assert.True(y.hasAxes())
|
||||
testutil.AssertTrue(t, y.hasAxes())
|
||||
|
||||
ya := Chart{
|
||||
XAxis: XAxis{
|
||||
|
|
@ -314,14 +313,14 @@ func TestChartHasAxes(t *testing.T) {
|
|||
Style: Shown(),
|
||||
},
|
||||
}
|
||||
assert.True(ya.hasAxes())
|
||||
testutil.AssertTrue(t, ya.hasAxes())
|
||||
}
|
||||
|
||||
func TestChartGetAxesTicks(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
r, err := PNG(1024, 1024)
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
c := Chart{
|
||||
XAxis: XAxis{
|
||||
|
|
@ -337,13 +336,13 @@ func TestChartGetAxesTicks(t *testing.T) {
|
|||
xr, yr, yar := c.getRanges()
|
||||
|
||||
xt, yt, yat := c.getAxesTicks(r, xr, yr, yar, FloatValueFormatter, FloatValueFormatter, FloatValueFormatter)
|
||||
assert.NotEmpty(xt)
|
||||
assert.NotEmpty(yt)
|
||||
assert.NotEmpty(yat)
|
||||
testutil.AssertNotEmpty(t, xt)
|
||||
testutil.AssertNotEmpty(t, yt)
|
||||
testutil.AssertNotEmpty(t, yat)
|
||||
}
|
||||
|
||||
func TestChartSingleSeries(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
now := time.Now()
|
||||
c := Chart{
|
||||
Title: "Hello!",
|
||||
|
|
@ -366,11 +365,11 @@ func TestChartSingleSeries(t *testing.T) {
|
|||
|
||||
buffer := bytes.NewBuffer([]byte{})
|
||||
c.Render(PNG, buffer)
|
||||
assert.NotEmpty(buffer.Bytes())
|
||||
testutil.AssertNotEmpty(t, buffer.Bytes())
|
||||
}
|
||||
|
||||
func TestChartRegressionBadRanges(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
c := Chart{
|
||||
Series: []Series{
|
||||
|
|
@ -382,11 +381,11 @@ func TestChartRegressionBadRanges(t *testing.T) {
|
|||
}
|
||||
buffer := bytes.NewBuffer([]byte{})
|
||||
c.Render(PNG, buffer)
|
||||
assert.True(true, "Render needs to finish.")
|
||||
testutil.AssertTrue(t, true, "Render needs to finish.")
|
||||
}
|
||||
|
||||
func TestChartRegressionBadRangesByUser(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
c := Chart{
|
||||
YAxis: YAxis{
|
||||
|
|
@ -404,11 +403,11 @@ func TestChartRegressionBadRangesByUser(t *testing.T) {
|
|||
}
|
||||
buffer := bytes.NewBuffer([]byte{})
|
||||
c.Render(PNG, buffer)
|
||||
assert.True(true, "Render needs to finish.")
|
||||
testutil.AssertTrue(t, true, "Render needs to finish.")
|
||||
}
|
||||
|
||||
func TestChartValidatesSeries(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
c := Chart{
|
||||
Series: []Series{
|
||||
|
|
@ -419,7 +418,7 @@ func TestChartValidatesSeries(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
assert.Nil(c.validateSeries())
|
||||
testutil.AssertNil(t, c.validateSeries())
|
||||
|
||||
c = Chart{
|
||||
Series: []Series{
|
||||
|
|
@ -429,11 +428,11 @@ func TestChartValidatesSeries(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
assert.NotNil(c.validateSeries())
|
||||
testutil.AssertNotNil(t, c.validateSeries())
|
||||
}
|
||||
|
||||
func TestChartCheckRanges(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
c := Chart{
|
||||
Series: []Series{
|
||||
|
|
@ -445,11 +444,11 @@ func TestChartCheckRanges(t *testing.T) {
|
|||
}
|
||||
|
||||
xr, yr, yra := c.getRanges()
|
||||
assert.Nil(c.checkRanges(xr, yr, yra))
|
||||
testutil.AssertNil(t, c.checkRanges(xr, yr, yra))
|
||||
}
|
||||
|
||||
func TestChartCheckRangesWithRanges(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
c := Chart{
|
||||
XAxis: XAxis{
|
||||
|
|
@ -473,7 +472,7 @@ func TestChartCheckRangesWithRanges(t *testing.T) {
|
|||
}
|
||||
|
||||
xr, yr, yra := c.getRanges()
|
||||
assert.Nil(c.checkRanges(xr, yr, yra))
|
||||
testutil.AssertNil(t, c.checkRanges(xr, yr, yra))
|
||||
}
|
||||
|
||||
func at(i image.Image, x, y int) drawing.Color {
|
||||
|
|
@ -481,7 +480,7 @@ func at(i image.Image, x, y int) drawing.Color {
|
|||
}
|
||||
|
||||
func TestChartE2ELine(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
c := Chart{
|
||||
Height: 50,
|
||||
|
|
@ -506,26 +505,26 @@ func TestChartE2ELine(t *testing.T) {
|
|||
|
||||
var buffer = &bytes.Buffer{}
|
||||
err := c.Render(PNG, buffer)
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
// do color tests ...
|
||||
|
||||
i, err := png.Decode(buffer)
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
// test the bottom and top of the line
|
||||
assert.Equal(drawing.ColorWhite, at(i, 0, 0))
|
||||
assert.Equal(drawing.ColorWhite, at(i, 49, 49))
|
||||
testutil.AssertEqual(t, drawing.ColorWhite, at(i, 0, 0))
|
||||
testutil.AssertEqual(t, drawing.ColorWhite, at(i, 49, 49))
|
||||
|
||||
// test a line mid point
|
||||
defaultSeriesColor := GetDefaultColor(0)
|
||||
assert.Equal(defaultSeriesColor, at(i, 0, 49))
|
||||
assert.Equal(defaultSeriesColor, at(i, 49, 0))
|
||||
assert.Equal(drawing.ColorFromHex("bddbf6"), at(i, 24, 24))
|
||||
testutil.AssertEqual(t, defaultSeriesColor, at(i, 0, 49))
|
||||
testutil.AssertEqual(t, defaultSeriesColor, at(i, 49, 0))
|
||||
testutil.AssertEqual(t, drawing.ColorFromHex("bddbf6"), at(i, 24, 24))
|
||||
}
|
||||
|
||||
func TestChartE2ELineWithFill(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
logBuffer := new(bytes.Buffer)
|
||||
|
||||
|
|
@ -555,22 +554,22 @@ func TestChartE2ELineWithFill(t *testing.T) {
|
|||
Log: NewLogger(OptLoggerStdout(logBuffer), OptLoggerStderr(logBuffer)),
|
||||
}
|
||||
|
||||
assert.Equal(5, len(c.Series[0].(ContinuousSeries).XValues))
|
||||
assert.Equal(5, len(c.Series[0].(ContinuousSeries).YValues))
|
||||
testutil.AssertEqual(t, 5, len(c.Series[0].(ContinuousSeries).XValues))
|
||||
testutil.AssertEqual(t, 5, len(c.Series[0].(ContinuousSeries).YValues))
|
||||
|
||||
var buffer = &bytes.Buffer{}
|
||||
err := c.Render(PNG, buffer)
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
i, err := png.Decode(buffer)
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
// test the bottom and top of the line
|
||||
assert.Equal(drawing.ColorWhite, at(i, 0, 0))
|
||||
assert.Equal(drawing.ColorRed, at(i, 49, 49))
|
||||
testutil.AssertEqual(t, drawing.ColorWhite, at(i, 0, 0))
|
||||
testutil.AssertEqual(t, drawing.ColorRed, at(i, 49, 49))
|
||||
|
||||
// test a line mid point
|
||||
defaultSeriesColor := drawing.ColorBlue
|
||||
assert.Equal(defaultSeriesColor, at(i, 0, 49))
|
||||
assert.Equal(defaultSeriesColor, at(i, 49, 0))
|
||||
testutil.AssertEqual(t, defaultSeriesColor, at(i, 0, 49))
|
||||
testutil.AssertEqual(t, defaultSeriesColor, at(i, 49, 0))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue