diff --git a/.circleci/config.yml b/.circleci/config.yml index 0b7654d..007a11c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,15 +3,12 @@ jobs: build: working_directory: /go/src/github.com/wcharczuk/go-chart docker: - - image: circleci/golang:1.11 + - image: circleci/golang:1.15 steps: - checkout - run: name: new-install command: make new-install - run: - name: ci - command: make ci - - store_artifacts: - path: coverage.html - destination: coverage.html \ No newline at end of file + name: Continuous Integration + command: make \ No newline at end of file diff --git a/Makefile b/Makefile index a393b6f..e0928c3 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,10 @@ -all: test - -ci: profanity coverage +all: new-install test new-install: @go get -v -u ./... - @go get -v -u github.com/blend/go-sdk/cmd/coverage - @go get -v -u github.com/blend/go-sdk/cmd/profanity generate: @go generate ./... test: - @go test ./... - -.PHONY: profanity -profanity: - @profanity - -coverage: - @coverage + @go test ./... \ No newline at end of file diff --git a/_examples/horizontal_stacked_bar/main.go b/_examples/horizontal_stacked_bar/main.go index 4447c03..5151524 100644 --- a/_examples/horizontal_stacked_bar/main.go +++ b/_examples/horizontal_stacked_bar/main.go @@ -3,8 +3,8 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { diff --git a/_examples/stacked_bar_labels/main.go b/_examples/stacked_bar_labels/main.go index a04e77b..a62103f 100644 --- a/_examples/stacked_bar_labels/main.go +++ b/_examples/stacked_bar_labels/main.go @@ -3,8 +3,8 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { diff --git a/annotation_series_test.go b/annotation_series_test.go index f5cd2da..1a33900 100644 --- a/annotation_series_test.go +++ b/annotation_series_test.go @@ -4,13 +4,12 @@ import ( "image/color" "testing" - "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 TestAnnotationSeriesMeasure(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper as := AnnotationSeries{ Annotations: []Value2{ @@ -22,10 +21,10 @@ func TestAnnotationSeriesMeasure(t *testing.T) { } r, err := PNG(110, 110) - assert.Nil(err) + testutil.AssertNil(t, err) f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) xrange := &ContinuousRange{ Min: 1.0, @@ -50,15 +49,15 @@ func TestAnnotationSeriesMeasure(t *testing.T) { } box := as.Measure(r, cb, xrange, yrange, sd) - assert.False(box.IsZero()) - assert.Equal(-5.0, box.Top) - assert.Equal(5.0, box.Left) - assert.Equal(146.0, box.Right) //the top,left annotation sticks up 5px and out ~44px. - assert.Equal(115.0, box.Bottom) + testutil.AssertFalse(t, box.IsZero()) + testutil.AssertEqual(t, -5.0, box.Top) + testutil.AssertEqual(t, 5.0, box.Left) + testutil.AssertEqual(t, 146.0, box.Right) //the top,left annotation sticks up 5px and out ~44px. + testutil.AssertEqual(t, 115.0, box.Bottom) } func TestAnnotationSeriesRender(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper as := AnnotationSeries{ Style: Style{ @@ -74,10 +73,10 @@ func TestAnnotationSeriesRender(t *testing.T) { } r, err := PNG(110, 110) - assert.Nil(err) + testutil.AssertNil(t, err) f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) xrange := &ContinuousRange{ Min: 1.0, @@ -104,13 +103,13 @@ func TestAnnotationSeriesRender(t *testing.T) { as.Render(r, cb, xrange, yrange, sd) rr, isRaster := r.(*rasterRenderer) - assert.True(isRaster) - assert.NotNil(rr) + testutil.AssertTrue(t, isRaster) + testutil.AssertNotNil(t, rr) c := rr.i.At(38, 70) converted, isRGBA := color.RGBAModel.Convert(c).(color.RGBA) - assert.True(isRGBA) - assert.Equal(0, converted.R) - assert.Equal(0, converted.G) - assert.Equal(0, converted.B) + testutil.AssertTrue(t, isRGBA) + testutil.AssertEqual(t, 0, converted.R) + testutil.AssertEqual(t, 0, converted.G) + testutil.AssertEqual(t, 0, converted.B) } diff --git a/bar_chart_test.go b/bar_chart_test.go index 8a25cae..e62ef83 100644 --- a/bar_chart_test.go +++ b/bar_chart_test.go @@ -5,11 +5,11 @@ import ( "math" "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestBarChartRender(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{ Width: 1024, @@ -25,12 +25,12 @@ func TestBarChartRender(t *testing.T) { buf := bytes.NewBuffer([]byte{}) err := bc.Render(PNG, buf) - assert.Nil(err) - assert.NotZero(buf.Len()) + testutil.AssertNil(t, err) + testutil.AssertNotZero(t, buf.Len()) } func TestBarChartRenderZero(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{ Width: 1024, @@ -43,64 +43,64 @@ func TestBarChartRenderZero(t *testing.T) { buf := bytes.NewBuffer([]byte{}) err := bc.Render(PNG, buf) - assert.NotNil(err) + testutil.AssertNotNil(t, err) } func TestBarChartProps(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{} - assert.Equal(DefaultDPI, bc.GetDPI()) + testutil.AssertEqual(t, DefaultDPI, bc.GetDPI()) bc.DPI = 100 - assert.Equal(100, bc.GetDPI()) + testutil.AssertEqual(t, 100, bc.GetDPI()) - assert.Nil(bc.GetFont()) + testutil.AssertNil(t, bc.GetFont()) f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) bc.Font = f - assert.NotNil(bc.GetFont()) + testutil.AssertNotNil(t, bc.GetFont()) - assert.Equal(DefaultChartWidth, bc.GetWidth()) + testutil.AssertEqual(t, DefaultChartWidth, bc.GetWidth()) bc.Width = DefaultChartWidth - 1 - assert.Equal(DefaultChartWidth-1, bc.GetWidth()) + testutil.AssertEqual(t, DefaultChartWidth-1, bc.GetWidth()) - assert.Equal(DefaultChartHeight, bc.GetHeight()) + testutil.AssertEqual(t, DefaultChartHeight, bc.GetHeight()) bc.Height = DefaultChartHeight - 1 - assert.Equal(DefaultChartHeight-1, bc.GetHeight()) + testutil.AssertEqual(t, DefaultChartHeight-1, bc.GetHeight()) - assert.Equal(DefaultBarSpacing, bc.GetBarSpacing()) + testutil.AssertEqual(t, DefaultBarSpacing, bc.GetBarSpacing()) bc.BarSpacing = 150 - assert.Equal(150, bc.GetBarSpacing()) + testutil.AssertEqual(t, 150, bc.GetBarSpacing()) - assert.Equal(DefaultBarWidth, bc.GetBarWidth()) + testutil.AssertEqual(t, DefaultBarWidth, bc.GetBarWidth()) bc.BarWidth = 75 - assert.Equal(75, bc.GetBarWidth()) + testutil.AssertEqual(t, 75, bc.GetBarWidth()) } func TestBarChartRenderNoBars(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{} err := bc.Render(PNG, bytes.NewBuffer([]byte{})) - assert.NotNil(err) + testutil.AssertNotNil(t, err) } func TestBarChartGetRanges(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{} yr := bc.getRanges() - assert.NotNil(yr) - assert.False(yr.IsZero()) + testutil.AssertNotNil(t, yr) + testutil.AssertFalse(t, yr.IsZero()) - assert.Equal(-math.MaxFloat64, yr.GetMax()) - assert.Equal(math.MaxFloat64, yr.GetMin()) + testutil.AssertEqual(t, -math.MaxFloat64, yr.GetMax()) + testutil.AssertEqual(t, math.MaxFloat64, yr.GetMin()) } func TestBarChartGetRangesBarsMinMax(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{ Bars: []Value{ @@ -110,15 +110,15 @@ func TestBarChartGetRangesBarsMinMax(t *testing.T) { } yr := bc.getRanges() - assert.NotNil(yr) - assert.False(yr.IsZero()) + testutil.AssertNotNil(t, yr) + testutil.AssertFalse(t, yr.IsZero()) - assert.Equal(10, yr.GetMax()) - assert.Equal(1, yr.GetMin()) + testutil.AssertEqual(t, 10, yr.GetMax()) + testutil.AssertEqual(t, 1, yr.GetMin()) } func TestBarChartGetRangesMinMax(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{ YAxis: YAxis{ @@ -138,15 +138,15 @@ func TestBarChartGetRangesMinMax(t *testing.T) { } yr := bc.getRanges() - assert.NotNil(yr) - assert.False(yr.IsZero()) + testutil.AssertNotNil(t, yr) + testutil.AssertFalse(t, yr.IsZero()) - assert.Equal(15, yr.GetMax()) - assert.Equal(5, yr.GetMin()) + testutil.AssertEqual(t, 15, yr.GetMax()) + testutil.AssertEqual(t, 5, yr.GetMin()) } func TestBarChartGetRangesTicksMinMax(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{ YAxis: YAxis{ @@ -162,56 +162,56 @@ func TestBarChartGetRangesTicksMinMax(t *testing.T) { } yr := bc.getRanges() - assert.NotNil(yr) - assert.False(yr.IsZero()) + testutil.AssertNotNil(t, yr) + testutil.AssertFalse(t, yr.IsZero()) - assert.Equal(11, yr.GetMax()) - assert.Equal(7, yr.GetMin()) + testutil.AssertEqual(t, 11, yr.GetMax()) + testutil.AssertEqual(t, 7, yr.GetMin()) } func TestBarChartHasAxes(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{} - assert.True(bc.hasAxes()) + testutil.AssertTrue(t, bc.hasAxes()) bc.YAxis = YAxis{ Style: Hidden(), } - assert.False(bc.hasAxes()) + testutil.AssertFalse(t, bc.hasAxes()) } func TestBarChartGetDefaultCanvasBox(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{} b := bc.getDefaultCanvasBox() - assert.False(b.IsZero()) + testutil.AssertFalse(t, b.IsZero()) } func TestBarChartSetRangeDomains(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{} cb := bc.box() yr := bc.getRanges() yr2 := bc.setRangeDomains(cb, yr) - assert.NotZero(yr2.GetDomain()) + testutil.AssertNotZero(t, yr2.GetDomain()) } func TestBarChartGetValueFormatters(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{} vf := bc.getValueFormatters() - assert.NotNil(vf) - assert.Equal("1234.00", vf(1234.0)) + testutil.AssertNotNil(t, vf) + testutil.AssertEqual(t, "1234.00", vf(1234.0)) bc.YAxis.ValueFormatter = func(_ interface{}) string { return "test" } - assert.Equal("test", bc.getValueFormatters()(1234)) + testutil.AssertEqual(t, "test", bc.getValueFormatters()(1234)) } func TestBarChartGetAxesTicks(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{ Bars: []Value{ @@ -222,21 +222,21 @@ func TestBarChartGetAxesTicks(t *testing.T) { } r, err := PNG(128, 128) - assert.Nil(err) + testutil.AssertNil(t, err) yr := bc.getRanges() yf := bc.getValueFormatters() bc.YAxis.Style.Hidden = true ticks := bc.getAxesTicks(r, yr, yf) - assert.Empty(ticks) + testutil.AssertEmpty(t, ticks) bc.YAxis.Style.Hidden = false ticks = bc.getAxesTicks(r, yr, yf) - assert.Len(ticks, 2) + testutil.AssertLen(t, ticks, 2) } func TestBarChartCalculateEffectiveBarSpacing(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{ Width: 1024, @@ -251,15 +251,15 @@ func TestBarChartCalculateEffectiveBarSpacing(t *testing.T) { } spacing := bc.calculateEffectiveBarSpacing(bc.box()) - assert.NotZero(spacing) + testutil.AssertNotZero(t, spacing) bc.BarWidth = 250 spacing = bc.calculateEffectiveBarSpacing(bc.box()) - assert.Zero(spacing) + testutil.AssertZero(t, spacing) } func TestBarChartCalculateEffectiveBarWidth(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BarChart{ Width: 1024, @@ -276,35 +276,35 @@ func TestBarChartCalculateEffectiveBarWidth(t *testing.T) { cb := bc.box() spacing := bc.calculateEffectiveBarSpacing(bc.box()) - assert.NotZero(spacing) + testutil.AssertNotZero(t, spacing) barWidth := bc.calculateEffectiveBarWidth(bc.box(), spacing) - assert.Equal(10, barWidth) + testutil.AssertEqual(t, 10, barWidth) bc.BarWidth = 250 spacing = bc.calculateEffectiveBarSpacing(bc.box()) - assert.Zero(spacing) + testutil.AssertZero(t, spacing) barWidth = bc.calculateEffectiveBarWidth(bc.box(), spacing) - assert.Equal(199, barWidth) + testutil.AssertEqual(t, 199, barWidth) - assert.Equal(cb.Width()+1, bc.calculateTotalBarWidth(barWidth, spacing)) + testutil.AssertEqual(t, cb.Width()+1, bc.calculateTotalBarWidth(barWidth, spacing)) bw, bs, total := bc.calculateScaledTotalWidth(cb) - assert.Equal(spacing, bs) - assert.Equal(barWidth, bw) - assert.Equal(cb.Width()+1, total) + testutil.AssertEqual(t, spacing, bs) + testutil.AssertEqual(t, barWidth, bw) + testutil.AssertEqual(t, cb.Width()+1, total) } func TestBarChatGetTitleFontSize(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper size := BarChart{Width: 2049, Height: 2049}.getTitleFontSize() - assert.Equal(48, size) + testutil.AssertEqual(t, 48, size) size = BarChart{Width: 1025, Height: 1025}.getTitleFontSize() - assert.Equal(24, size) + testutil.AssertEqual(t, 24, size) size = BarChart{Width: 513, Height: 513}.getTitleFontSize() - assert.Equal(18, size) + testutil.AssertEqual(t, 18, size) size = BarChart{Width: 257, Height: 257}.getTitleFontSize() - assert.Equal(12, size) + testutil.AssertEqual(t, 12, size) size = BarChart{Width: 128, Height: 128}.getTitleFontSize() - assert.Equal(10, size) + testutil.AssertEqual(t, 10, size) } diff --git a/bollinger_band_series_test.go b/bollinger_band_series_test.go index d679960..b33b0ec 100644 --- a/bollinger_band_series_test.go +++ b/bollinger_band_series_test.go @@ -5,11 +5,11 @@ import ( "math" "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestBollingerBandSeries(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper s1 := mockValuesProvider{ X: LinearRange(1.0, 100.0), @@ -29,12 +29,12 @@ func TestBollingerBandSeries(t *testing.T) { } for x := bbs.GetPeriod(); x < 100; x++ { - assert.True(y1values[x] > y2values[x], fmt.Sprintf("%v vs. %v", y1values[x], y2values[x])) + testutil.AssertTrue(t, y1values[x] > y2values[x], fmt.Sprintf("%v vs. %v", y1values[x], y2values[x])) } } func TestBollingerBandLastValue(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper s1 := mockValuesProvider{ X: LinearRange(1.0, 100.0), @@ -46,7 +46,7 @@ func TestBollingerBandLastValue(t *testing.T) { } x, y1, y2 := bbs.GetBoundedLastValues() - assert.Equal(100.0, x) - assert.Equal(101, math.Floor(y1)) - assert.Equal(83, math.Floor(y2)) + testutil.AssertEqual(t, 100.0, x) + testutil.AssertEqual(t, 101, math.Floor(y1)) + testutil.AssertEqual(t, 83, math.Floor(y2)) } diff --git a/box_test.go b/box_test.go index 4bc3f71..e62d5b7 100644 --- a/box_test.go +++ b/box_test.go @@ -4,131 +4,131 @@ import ( "math" "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestBoxClone(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper a := Box{Top: 5, Left: 5, Right: 15, Bottom: 15} b := a.Clone() - assert.True(a.Equals(b)) - assert.True(b.Equals(a)) + testutil.AssertTrue(t, a.Equals(b)) + testutil.AssertTrue(t, b.Equals(a)) } func TestBoxEquals(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper a := Box{Top: 5, Left: 5, Right: 15, Bottom: 15} b := Box{Top: 10, Left: 10, Right: 30, Bottom: 30} c := Box{Top: 5, Left: 5, Right: 15, Bottom: 15} - assert.True(a.Equals(a)) - assert.True(a.Equals(c)) - assert.True(c.Equals(a)) - assert.False(a.Equals(b)) - assert.False(c.Equals(b)) - assert.False(b.Equals(a)) - assert.False(b.Equals(c)) + testutil.AssertTrue(t, a.Equals(a)) + testutil.AssertTrue(t, a.Equals(c)) + testutil.AssertTrue(t, c.Equals(a)) + testutil.AssertFalse(t, a.Equals(b)) + testutil.AssertFalse(t, c.Equals(b)) + testutil.AssertFalse(t, b.Equals(a)) + testutil.AssertFalse(t, b.Equals(c)) } func TestBoxIsBiggerThan(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper a := Box{Top: 5, Left: 5, Right: 25, Bottom: 25} b := Box{Top: 10, Left: 10, Right: 20, Bottom: 20} // only half bigger c := Box{Top: 1, Left: 1, Right: 30, Bottom: 30} //bigger - assert.True(a.IsBiggerThan(b)) - assert.False(a.IsBiggerThan(c)) - assert.True(c.IsBiggerThan(a)) + testutil.AssertTrue(t, a.IsBiggerThan(b)) + testutil.AssertFalse(t, a.IsBiggerThan(c)) + testutil.AssertTrue(t, c.IsBiggerThan(a)) } func TestBoxIsSmallerThan(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper a := Box{Top: 5, Left: 5, Right: 25, Bottom: 25} b := Box{Top: 10, Left: 10, Right: 20, Bottom: 20} // only half bigger c := Box{Top: 1, Left: 1, Right: 30, Bottom: 30} //bigger - assert.False(a.IsSmallerThan(b)) - assert.True(a.IsSmallerThan(c)) - assert.False(c.IsSmallerThan(a)) + testutil.AssertFalse(t, a.IsSmallerThan(b)) + testutil.AssertTrue(t, a.IsSmallerThan(c)) + testutil.AssertFalse(t, c.IsSmallerThan(a)) } func TestBoxGrow(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper a := Box{Top: 1, Left: 2, Right: 15, Bottom: 15} b := Box{Top: 4, Left: 5, Right: 30, Bottom: 35} c := a.Grow(b) - assert.False(c.Equals(b)) - assert.False(c.Equals(a)) - assert.Equal(1, c.Top) - assert.Equal(2, c.Left) - assert.Equal(30, c.Right) - assert.Equal(35, c.Bottom) + testutil.AssertFalse(t, c.Equals(b)) + testutil.AssertFalse(t, c.Equals(a)) + testutil.AssertEqual(t, 1, c.Top) + testutil.AssertEqual(t, 2, c.Left) + testutil.AssertEqual(t, 30, c.Right) + testutil.AssertEqual(t, 35, c.Bottom) } func TestBoxFit(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper a := Box{Top: 64, Left: 64, Right: 192, Bottom: 192} b := Box{Top: 16, Left: 16, Right: 256, Bottom: 170} c := Box{Top: 16, Left: 16, Right: 170, Bottom: 256} fab := a.Fit(b) - assert.Equal(a.Left, fab.Left) - assert.Equal(a.Right, fab.Right) - assert.True(fab.Top < fab.Bottom) - assert.True(fab.Left < fab.Right) - assert.True(math.Abs(b.Aspect()-fab.Aspect()) < 0.02) + testutil.AssertEqual(t, a.Left, fab.Left) + testutil.AssertEqual(t, a.Right, fab.Right) + testutil.AssertTrue(t, fab.Top < fab.Bottom) + testutil.AssertTrue(t, fab.Left < fab.Right) + testutil.AssertTrue(t, math.Abs(b.Aspect()-fab.Aspect()) < 0.02) fac := a.Fit(c) - assert.Equal(a.Top, fac.Top) - assert.Equal(a.Bottom, fac.Bottom) - assert.True(math.Abs(c.Aspect()-fac.Aspect()) < 0.02) + testutil.AssertEqual(t, a.Top, fac.Top) + testutil.AssertEqual(t, a.Bottom, fac.Bottom) + testutil.AssertTrue(t, math.Abs(c.Aspect()-fac.Aspect()) < 0.02) } func TestBoxConstrain(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper a := Box{Top: 64, Left: 64, Right: 192, Bottom: 192} b := Box{Top: 16, Left: 16, Right: 256, Bottom: 170} c := Box{Top: 16, Left: 16, Right: 170, Bottom: 256} cab := a.Constrain(b) - assert.Equal(64, cab.Top) - assert.Equal(64, cab.Left) - assert.Equal(192, cab.Right) - assert.Equal(170, cab.Bottom) + testutil.AssertEqual(t, 64, cab.Top) + testutil.AssertEqual(t, 64, cab.Left) + testutil.AssertEqual(t, 192, cab.Right) + testutil.AssertEqual(t, 170, cab.Bottom) cac := a.Constrain(c) - assert.Equal(64, cac.Top) - assert.Equal(64, cac.Left) - assert.Equal(170, cac.Right) - assert.Equal(192, cac.Bottom) + testutil.AssertEqual(t, 64, cac.Top) + testutil.AssertEqual(t, 64, cac.Left) + testutil.AssertEqual(t, 170, cac.Right) + testutil.AssertEqual(t, 192, cac.Bottom) } func TestBoxOuterConstrain(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper box := NewBox(0, 0, 100, 100) canvas := NewBox(5, 5, 95, 95) taller := NewBox(-10, 5, 50, 50) c := canvas.OuterConstrain(box, taller) - assert.Equal(15, c.Top, c.String()) - assert.Equal(5, c.Left, c.String()) - assert.Equal(95, c.Right, c.String()) - assert.Equal(95, c.Bottom, c.String()) + testutil.AssertEqual(t, 15, c.Top, c.String()) + testutil.AssertEqual(t, 5, c.Left, c.String()) + testutil.AssertEqual(t, 95, c.Right, c.String()) + testutil.AssertEqual(t, 95, c.Bottom, c.String()) wider := NewBox(5, 5, 110, 50) d := canvas.OuterConstrain(box, wider) - assert.Equal(5, d.Top, d.String()) - assert.Equal(5, d.Left, d.String()) - assert.Equal(85, d.Right, d.String()) - assert.Equal(95, d.Bottom, d.String()) + testutil.AssertEqual(t, 5, d.Top, d.String()) + testutil.AssertEqual(t, 5, d.Left, d.String()) + testutil.AssertEqual(t, 85, d.Right, d.String()) + testutil.AssertEqual(t, 95, d.Bottom, d.String()) } func TestBoxShift(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper b := Box{ Top: 5, @@ -138,14 +138,14 @@ func TestBoxShift(t *testing.T) { } shifted := b.Shift(1, 2) - assert.Equal(7, shifted.Top) - assert.Equal(6, shifted.Left) - assert.Equal(11, shifted.Right) - assert.Equal(12, shifted.Bottom) + testutil.AssertEqual(t, 7, shifted.Top) + testutil.AssertEqual(t, 6, shifted.Left) + testutil.AssertEqual(t, 11, shifted.Right) + testutil.AssertEqual(t, 12, shifted.Bottom) } func TestBoxCenter(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper b := Box{ Top: 10, @@ -154,12 +154,12 @@ func TestBoxCenter(t *testing.T) { Bottom: 30, } cx, cy := b.Center() - assert.Equal(15, cx) - assert.Equal(20, cy) + testutil.AssertEqual(t, 15, cx) + testutil.AssertEqual(t, 20, cy) } func TestBoxCornersCenter(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BoxCorners{ TopLeft: Point{5, 5}, @@ -169,12 +169,12 @@ func TestBoxCornersCenter(t *testing.T) { } cx, cy := bc.Center() - assert.Equal(10, cx) - assert.Equal(10, cy) + testutil.AssertEqual(t, 10, cx) + testutil.AssertEqual(t, 10, cy) } func TestBoxCornersRotate(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper bc := BoxCorners{ TopLeft: Point{5, 5}, @@ -184,5 +184,5 @@ func TestBoxCornersRotate(t *testing.T) { } rotated := bc.Rotate(45) - assert.True(rotated.TopLeft.Equals(Point{10, 3}), rotated.String()) + testutil.AssertTrue(t, rotated.TopLeft.Equals(Point{10, 3}), rotated.String()) } diff --git a/chart_test.go b/chart_test.go index 55db3e0..8026848 100644 --- a/chart_test.go +++ b/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)) } diff --git a/cmd/chart/main.go b/cmd/chart/main.go index 623aeeb..82ed907 100644 --- a/cmd/chart/main.go +++ b/cmd/chart/main.go @@ -7,7 +7,7 @@ import ( "os" "strings" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) var ( diff --git a/colors.go b/colors.go index 87dd4f0..b51f9ea 100644 --- a/colors.go +++ b/colors.go @@ -1,6 +1,6 @@ package chart -import "github.com/wcharczuk/go-chart/drawing" +import "github.com/wcharczuk/go-chart/v2/drawing" var ( // ColorWhite is white. diff --git a/concat_series_test.go b/concat_series_test.go index fb6a55f..9424fb2 100644 --- a/concat_series_test.go +++ b/concat_series_test.go @@ -3,11 +3,11 @@ package chart import ( "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestConcatSeries(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper s1 := ContinuousSeries{ XValues: LinearRange(1.0, 10.0), @@ -25,17 +25,17 @@ func TestConcatSeries(t *testing.T) { } cs := ConcatSeries([]Series{s1, s2, s3}) - assert.Equal(30, cs.Len()) + testutil.AssertEqual(t, 30, cs.Len()) x0, y0 := cs.GetValue(0) - assert.Equal(1.0, x0) - assert.Equal(1.0, y0) + testutil.AssertEqual(t, 1.0, x0) + testutil.AssertEqual(t, 1.0, y0) xm, ym := cs.GetValue(19) - assert.Equal(20.0, xm) - assert.Equal(1.0, ym) + testutil.AssertEqual(t, 20.0, xm) + testutil.AssertEqual(t, 1.0, ym) xn, yn := cs.GetValue(29) - assert.Equal(30.0, xn) - assert.Equal(10.0, yn) + testutil.AssertEqual(t, 30.0, xn) + testutil.AssertEqual(t, 10.0, yn) } diff --git a/continuous_range_test.go b/continuous_range_test.go index 07079f9..5d0f436 100644 --- a/continuous_range_test.go +++ b/continuous_range_test.go @@ -3,11 +3,11 @@ package chart import ( "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestRangeTranslate(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := []float64{1.0, 2.0, 2.5, 2.7, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0} r := ContinuousRange{Domain: 1000} r.Min, r.Max = MinMax(values...) @@ -16,7 +16,7 @@ func TestRangeTranslate(t *testing.T) { // value = ~5.0 // domain = ~1000 // 5/8 * 1000 ~= - assert.Equal(0, r.Translate(1.0)) - assert.Equal(1000, r.Translate(8.0)) - assert.Equal(572, r.Translate(5.0)) + testutil.AssertEqual(t, 0, r.Translate(1.0)) + testutil.AssertEqual(t, 1000, r.Translate(8.0)) + testutil.AssertEqual(t, 572, r.Translate(5.0)) } diff --git a/continuous_series_test.go b/continuous_series_test.go index 17b6612..783c236 100644 --- a/continuous_series_test.go +++ b/continuous_series_test.go @@ -4,11 +4,11 @@ import ( "fmt" "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestContinuousSeries(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper cs := ContinuousSeries{ Name: "Test Series", @@ -16,23 +16,23 @@ func TestContinuousSeries(t *testing.T) { YValues: LinearRange(1.0, 10.0), } - assert.Equal("Test Series", cs.GetName()) - assert.Equal(10, cs.Len()) + testutil.AssertEqual(t, "Test Series", cs.GetName()) + testutil.AssertEqual(t, 10, cs.Len()) x0, y0 := cs.GetValues(0) - assert.Equal(1.0, x0) - assert.Equal(1.0, y0) + testutil.AssertEqual(t, 1.0, x0) + testutil.AssertEqual(t, 1.0, y0) xn, yn := cs.GetValues(9) - assert.Equal(10.0, xn) - assert.Equal(10.0, yn) + testutil.AssertEqual(t, 10.0, xn) + testutil.AssertEqual(t, 10.0, yn) xn, yn = cs.GetLastValues() - assert.Equal(10.0, xn) - assert.Equal(10.0, yn) + testutil.AssertEqual(t, 10.0, xn) + testutil.AssertEqual(t, 10.0, yn) } func TestContinuousSeriesValueFormatter(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper cs := ContinuousSeries{ XValueFormatter: func(v interface{}) string { @@ -44,29 +44,29 @@ func TestContinuousSeriesValueFormatter(t *testing.T) { } xf, yf := cs.GetValueFormatters() - assert.Equal("0.100000 foo", xf(0.1)) - assert.Equal("0.100000 bar", yf(0.1)) + testutil.AssertEqual(t, "0.100000 foo", xf(0.1)) + testutil.AssertEqual(t, "0.100000 bar", yf(0.1)) } func TestContinuousSeriesValidate(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper cs := ContinuousSeries{ Name: "Test Series", XValues: LinearRange(1.0, 10.0), YValues: LinearRange(1.0, 10.0), } - assert.Nil(cs.Validate()) + testutil.AssertNil(t, cs.Validate()) cs = ContinuousSeries{ Name: "Test Series", XValues: LinearRange(1.0, 10.0), } - assert.NotNil(cs.Validate()) + testutil.AssertNotNil(t, cs.Validate()) cs = ContinuousSeries{ Name: "Test Series", YValues: LinearRange(1.0, 10.0), } - assert.NotNil(cs.Validate()) + testutil.AssertNotNil(t, cs.Validate()) } diff --git a/donut_chart_test.go b/donut_chart_test.go index db84560..388f65d 100644 --- a/donut_chart_test.go +++ b/donut_chart_test.go @@ -4,11 +4,11 @@ import ( "bytes" "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestDonutChart(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper pie := DonutChart{ Canvas: Style{ @@ -27,11 +27,11 @@ func TestDonutChart(t *testing.T) { b := bytes.NewBuffer([]byte{}) pie.Render(PNG, b) - assert.NotZero(b.Len()) + testutil.AssertNotZero(t, b.Len()) } func TestDonutChartDropsZeroValues(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper pie := DonutChart{ Canvas: Style{ @@ -46,11 +46,11 @@ func TestDonutChartDropsZeroValues(t *testing.T) { b := bytes.NewBuffer([]byte{}) err := pie.Render(PNG, b) - assert.Nil(err) + testutil.AssertNil(t, err) } func TestDonutChartAllZeroValues(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper pie := DonutChart{ Canvas: Style{ @@ -65,5 +65,5 @@ func TestDonutChartAllZeroValues(t *testing.T) { b := bytes.NewBuffer([]byte{}) err := pie.Render(PNG, b) - assert.NotNil(err) + testutil.AssertNotNil(t, err) } diff --git a/drawing/color_test.go b/drawing/color_test.go index 1b38ba6..15c3244 100644 --- a/drawing/color_test.go +++ b/drawing/color_test.go @@ -5,49 +5,49 @@ import ( "image/color" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestColorFromHex(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper white := ColorFromHex("FFFFFF") - assert.Equal(ColorWhite, white) + testutil.AssertEqual(t, ColorWhite, white) shortWhite := ColorFromHex("FFF") - assert.Equal(ColorWhite, shortWhite) + testutil.AssertEqual(t, ColorWhite, shortWhite) black := ColorFromHex("000000") - assert.Equal(ColorBlack, black) + testutil.AssertEqual(t, ColorBlack, black) shortBlack := ColorFromHex("000") - assert.Equal(ColorBlack, shortBlack) + testutil.AssertEqual(t, ColorBlack, shortBlack) red := ColorFromHex("FF0000") - assert.Equal(ColorRed, red) + testutil.AssertEqual(t, ColorRed, red) shortRed := ColorFromHex("F00") - assert.Equal(ColorRed, shortRed) + testutil.AssertEqual(t, ColorRed, shortRed) green := ColorFromHex("00FF00") - assert.Equal(ColorGreen, green) + testutil.AssertEqual(t, ColorGreen, green) shortGreen := ColorFromHex("0F0") - assert.Equal(ColorGreen, shortGreen) + testutil.AssertEqual(t, ColorGreen, shortGreen) blue := ColorFromHex("0000FF") - assert.Equal(ColorBlue, blue) + testutil.AssertEqual(t, ColorBlue, blue) shortBlue := ColorFromHex("00F") - assert.Equal(ColorBlue, shortBlue) + testutil.AssertEqual(t, ColorBlue, shortBlue) } func TestColorFromAlphaMixedRGBA(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper black := ColorFromAlphaMixedRGBA(color.Black.RGBA()) - assert.True(black.Equals(ColorBlack), black.String()) + testutil.AssertTrue(t, black.Equals(ColorBlack), black.String()) white := ColorFromAlphaMixedRGBA(color.White.RGBA()) - assert.True(white.Equals(ColorWhite), white.String()) + testutil.AssertTrue(t, white.Equals(ColorWhite), white.String()) } diff --git a/drawing/curve_test.go b/drawing/curve_test.go index 3e792eb..31abe8e 100644 --- a/drawing/curve_test.go +++ b/drawing/curve_test.go @@ -3,7 +3,7 @@ package drawing import ( "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) type point struct { @@ -23,7 +23,7 @@ func (ml mockLine) Len() int { } func TestTraceQuad(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper // Quad // x1, y1, cpx1, cpy2, x2, y2 float64 @@ -31,5 +31,5 @@ func TestTraceQuad(t *testing.T) { quad := []float64{10, 20, 20, 20, 20, 10} liner := &mockLine{} TraceQuad(liner, quad, 0.5) - assert.NotZero(liner.Len()) + testutil.AssertNotZero(t, liner.Len()) } diff --git a/ema_series_test.go b/ema_series_test.go index 90f0eae..184319b 100644 --- a/ema_series_test.go +++ b/ema_series_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) var ( @@ -73,13 +73,13 @@ var ( ) func TestEMASeries(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper mockSeries := mockValuesProvider{ emaXValues, emaYValues, } - assert.Equal(50, mockSeries.Len()) + testutil.AssertEqual(t, 50, mockSeries.Len()) ema := &EMASeries{ InnerSeries: mockSeries, @@ -87,7 +87,7 @@ func TestEMASeries(t *testing.T) { } sig := ema.GetSigma() - assert.Equal(2.0/(26.0+1), sig) + testutil.AssertEqual(t, 2.0/(26.0+1), sig) var yvalues []float64 for x := 0; x < ema.Len(); x++ { @@ -96,10 +96,10 @@ func TestEMASeries(t *testing.T) { } for index, yv := range yvalues { - assert.InDelta(yv, emaExpected[index], emaDelta) + testutil.AssertInDelta(t, yv, emaExpected[index], emaDelta) } lvx, lvy := ema.GetLastValues() - assert.Equal(50.0, lvx) - assert.InDelta(lvy, emaExpected[49], emaDelta) + testutil.AssertEqual(t, 50.0, lvx) + testutil.AssertInDelta(t, lvy, emaExpected[49], emaDelta) } diff --git a/examples/annotations/main.go b/examples/annotations/main.go index 87be119..20bf01f 100644 --- a/examples/annotations/main.go +++ b/examples/annotations/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/axes/main.go b/examples/axes/main.go index 491ff8e..a675bde 100644 --- a/examples/axes/main.go +++ b/examples/axes/main.go @@ -5,7 +5,7 @@ package main import ( "os" - chart "github.com/wcharczuk/go-chart" + chart "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/axes_labels/main.go b/examples/axes_labels/main.go index e714884..a68ac34 100644 --- a/examples/axes_labels/main.go +++ b/examples/axes_labels/main.go @@ -5,7 +5,7 @@ package main import ( "os" - chart "github.com/wcharczuk/go-chart" + chart "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/bar_chart/main.go b/examples/bar_chart/main.go index e89c463..2a7895f 100644 --- a/examples/bar_chart/main.go +++ b/examples/bar_chart/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/bar_chart_base_value/main.go b/examples/bar_chart_base_value/main.go index 84ad9c4..f17b6b8 100644 --- a/examples/bar_chart_base_value/main.go +++ b/examples/bar_chart_base_value/main.go @@ -5,8 +5,8 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { diff --git a/examples/basic/main.go b/examples/basic/main.go index 20839cf..aeca5a8 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/benchmark_line_charts/main.go b/examples/benchmark_line_charts/main.go index 975670c..1a70417 100644 --- a/examples/benchmark_line_charts/main.go +++ b/examples/benchmark_line_charts/main.go @@ -8,7 +8,7 @@ import ( "os" "time" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func random(min, max float64) float64 { diff --git a/examples/css_classes/main.go b/examples/css_classes/main.go index 2ec5def..b5e65cf 100644 --- a/examples/css_classes/main.go +++ b/examples/css_classes/main.go @@ -5,7 +5,7 @@ import ( "log" "net/http" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) // Note: Additional examples on how to add Stylesheets are in the custom_stylesheets example diff --git a/examples/custom_formatters/main.go b/examples/custom_formatters/main.go index b215389..d2b6b90 100644 --- a/examples/custom_formatters/main.go +++ b/examples/custom_formatters/main.go @@ -6,7 +6,7 @@ import ( "fmt" "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/custom_padding/main.go b/examples/custom_padding/main.go index 1561497..14c23ec 100644 --- a/examples/custom_padding/main.go +++ b/examples/custom_padding/main.go @@ -5,8 +5,8 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { diff --git a/examples/custom_ranges/main.go b/examples/custom_ranges/main.go index 75a5142..61ef67b 100644 --- a/examples/custom_ranges/main.go +++ b/examples/custom_ranges/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/custom_styles/main.go b/examples/custom_styles/main.go index c8c3da7..08889ea 100644 --- a/examples/custom_styles/main.go +++ b/examples/custom_styles/main.go @@ -5,8 +5,8 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { diff --git a/examples/custom_stylesheets/main.go b/examples/custom_stylesheets/main.go index e5138cb..1af1058 100644 --- a/examples/custom_stylesheets/main.go +++ b/examples/custom_stylesheets/main.go @@ -5,7 +5,7 @@ import ( "log" "net/http" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) const style = "svg .background { fill: white; }" + diff --git a/examples/custom_ticks/main.go b/examples/custom_ticks/main.go index fa93c00..f95f64d 100644 --- a/examples/custom_ticks/main.go +++ b/examples/custom_ticks/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/descending/main.go b/examples/descending/main.go index c066808..62ae7f7 100644 --- a/examples/descending/main.go +++ b/examples/descending/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/donut_chart/main.go b/examples/donut_chart/main.go index 98f3de5..8b504ad 100644 --- a/examples/donut_chart/main.go +++ b/examples/donut_chart/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/image_writer/main.go b/examples/image_writer/main.go index 13bf013..4981d21 100644 --- a/examples/image_writer/main.go +++ b/examples/image_writer/main.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/legend/main.go b/examples/legend/main.go index fcdaaa5..83b5665 100644 --- a/examples/legend/main.go +++ b/examples/legend/main.go @@ -5,7 +5,7 @@ package main import ( "os" - chart "github.com/wcharczuk/go-chart" + chart "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/legend_left/main.go b/examples/legend_left/main.go index 33c71db..a6dc413 100644 --- a/examples/legend_left/main.go +++ b/examples/legend_left/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/linear_regression/main.go b/examples/linear_regression/main.go index fbea690..ebe0125 100644 --- a/examples/linear_regression/main.go +++ b/examples/linear_regression/main.go @@ -5,7 +5,7 @@ package main import ( "os" - chart "github.com/wcharczuk/go-chart" + chart "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/min_max/main.go b/examples/min_max/main.go index 359be16..f2c5479 100644 --- a/examples/min_max/main.go +++ b/examples/min_max/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/pie_chart/main.go b/examples/pie_chart/main.go index 2268776..5bd7c3f 100644 --- a/examples/pie_chart/main.go +++ b/examples/pie_chart/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/poly_regression/main.go b/examples/poly_regression/main.go index e41b0f2..040fcc0 100644 --- a/examples/poly_regression/main.go +++ b/examples/poly_regression/main.go @@ -5,7 +5,7 @@ package main import ( "os" - chart "github.com/wcharczuk/go-chart" + chart "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/request_timings/main.go b/examples/request_timings/main.go index 6c6df03..9ca0159 100644 --- a/examples/request_timings/main.go +++ b/examples/request_timings/main.go @@ -9,7 +9,7 @@ import ( "strconv" "time" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/rerender/main.go b/examples/rerender/main.go index ca4da0c..155486b 100644 --- a/examples/rerender/main.go +++ b/examples/rerender/main.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) var lock sync.Mutex diff --git a/examples/scatter/main.go b/examples/scatter/main.go index 5ef7675..b9ce850 100644 --- a/examples/scatter/main.go +++ b/examples/scatter/main.go @@ -6,8 +6,8 @@ import ( _ "net/http/pprof" - "github.com/wcharczuk/go-chart" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func drawChart(res http.ResponseWriter, req *http.Request) { diff --git a/examples/simple_moving_average/main.go b/examples/simple_moving_average/main.go index 35c90c7..742d15c 100644 --- a/examples/simple_moving_average/main.go +++ b/examples/simple_moving_average/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/stacked_bar/main.go b/examples/stacked_bar/main.go index 4fc1465..b9537e3 100644 --- a/examples/stacked_bar/main.go +++ b/examples/stacked_bar/main.go @@ -3,7 +3,7 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/stock_analysis/main.go b/examples/stock_analysis/main.go index a99804d..b7ccadc 100644 --- a/examples/stock_analysis/main.go +++ b/examples/stock_analysis/main.go @@ -6,8 +6,8 @@ import ( "os" "time" - "github.com/wcharczuk/go-chart" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { diff --git a/examples/text_rotation/main.go b/examples/text_rotation/main.go index f90ce49..28fe0ab 100644 --- a/examples/text_rotation/main.go +++ b/examples/text_rotation/main.go @@ -5,8 +5,8 @@ package main import ( "os" - "github.com/wcharczuk/go-chart" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { diff --git a/examples/timeseries/main.go b/examples/timeseries/main.go index 3cffd22..1540ccd 100644 --- a/examples/timeseries/main.go +++ b/examples/timeseries/main.go @@ -4,7 +4,7 @@ import ( "net/http" "time" - chart "github.com/wcharczuk/go-chart" + chart "github.com/wcharczuk/go-chart/v2" ) func drawChart(res http.ResponseWriter, req *http.Request) { diff --git a/examples/twoaxis/main.go b/examples/twoaxis/main.go index 87eeea6..d86f362 100644 --- a/examples/twoaxis/main.go +++ b/examples/twoaxis/main.go @@ -6,7 +6,7 @@ import ( "fmt" "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/twopoint/main.go b/examples/twopoint/main.go index e66a709..ad46905 100644 --- a/examples/twopoint/main.go +++ b/examples/twopoint/main.go @@ -7,7 +7,7 @@ import ( "log" "os" - "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/first_value_annotation_test.go b/first_value_annotation_test.go index 1f1d4cf..3675763 100644 --- a/first_value_annotation_test.go +++ b/first_value_annotation_test.go @@ -3,11 +3,11 @@ package chart import ( "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestFirstValueAnnotation(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper series := ContinuousSeries{ XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, @@ -15,8 +15,8 @@ func TestFirstValueAnnotation(t *testing.T) { } fva := FirstValueAnnotation(series) - assert.NotEmpty(fva.Annotations) + testutil.AssertNotEmpty(t, fva.Annotations) fvaa := fva.Annotations[0] - assert.Equal(1, fvaa.XValue) - assert.Equal(5, fvaa.YValue) + testutil.AssertEqual(t, 1, fvaa.XValue) + testutil.AssertEqual(t, 5, fvaa.YValue) } diff --git a/font.go b/font.go index a82880c..401143b 100644 --- a/font.go +++ b/font.go @@ -4,7 +4,7 @@ import ( "sync" "github.com/golang/freetype/truetype" - "github.com/wcharczuk/go-chart/roboto" + "github.com/wcharczuk/go-chart/v2/roboto" ) var ( diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3824b21 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/wcharczuk/go-chart/v2 + +go 1.15 + +require ( + github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 + golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..066121a --- /dev/null +++ b/go.sum @@ -0,0 +1,5 @@ +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= +golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM= +golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/grid_line_test.go b/grid_line_test.go index cbaedec..0e96d91 100644 --- a/grid_line_test.go +++ b/grid_line_test.go @@ -3,11 +3,11 @@ package chart import ( "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestGenerateGridLines(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper ticks := []Tick{ {Value: 1.0, Label: "1.0"}, @@ -17,8 +17,8 @@ func TestGenerateGridLines(t *testing.T) { } gl := GenerateGridLines(ticks, Style{}, Style{}) - assert.Len(gl, 2) + testutil.AssertLen(t, gl, 2) - assert.Equal(2.0, gl[0].Value) - assert.Equal(3.0, gl[1].Value) + testutil.AssertEqual(t, 2.0, gl[0].Value) + testutil.AssertEqual(t, 3.0, gl[1].Value) } diff --git a/histogram_series_test.go b/histogram_series_test.go index bd4f2d0..ff0ee54 100644 --- a/histogram_series_test.go +++ b/histogram_series_test.go @@ -3,11 +3,11 @@ package chart import ( "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestHistogramSeries(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper cs := ContinuousSeries{ Name: "Test Series", @@ -22,10 +22,10 @@ func TestHistogramSeries(t *testing.T) { for x := 0; x < hs.Len(); x++ { csx, csy := cs.GetValues(0) hsx, hsy1, hsy2 := hs.GetBoundedValues(0) - assert.Equal(csx, hsx) - assert.True(hsy1 > 0) - assert.True(hsy2 <= 0) - assert.True(csy < 0 || (csy > 0 && csy == hsy1)) - assert.True(csy > 0 || (csy < 0 && csy == hsy2)) + testutil.AssertEqual(t, csx, hsx) + testutil.AssertTrue(t, hsy1 > 0) + testutil.AssertTrue(t, hsy2 <= 0) + testutil.AssertTrue(t, csy < 0 || (csy > 0 && csy == hsy1)) + testutil.AssertTrue(t, csy > 0 || (csy < 0 && csy == hsy2)) } } diff --git a/jet.go b/jet.go index a948525..cce8c85 100644 --- a/jet.go +++ b/jet.go @@ -1,6 +1,6 @@ package chart -import "github.com/wcharczuk/go-chart/drawing" +import "github.com/wcharczuk/go-chart/v2/drawing" // Jet is a color map provider based on matlab's jet color map. func Jet(v, vmin, vmax float64) drawing.Color { diff --git a/last_value_annotation_series_test.go b/last_value_annotation_series_test.go index 651105d..59fc1b3 100644 --- a/last_value_annotation_series_test.go +++ b/last_value_annotation_series_test.go @@ -3,11 +3,11 @@ package chart import ( "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestLastValueAnnotationSeries(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper series := ContinuousSeries{ XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, @@ -15,8 +15,8 @@ func TestLastValueAnnotationSeries(t *testing.T) { } lva := LastValueAnnotationSeries(series) - assert.NotEmpty(lva.Annotations) + testutil.AssertNotEmpty(t, lva.Annotations) lvaa := lva.Annotations[0] - assert.Equal(5, lvaa.XValue) - assert.Equal(1, lvaa.YValue) + testutil.AssertEqual(t, 5, lvaa.XValue) + testutil.AssertEqual(t, 1, lvaa.YValue) } diff --git a/legend.go b/legend.go index 9d16ced..fbd48ed 100644 --- a/legend.go +++ b/legend.go @@ -1,7 +1,7 @@ package chart import ( - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2/drawing" ) // Legend returns a legend renderable function. diff --git a/legend_test.go b/legend_test.go index 7f8fae8..cfc9cfa 100644 --- a/legend_test.go +++ b/legend_test.go @@ -4,11 +4,11 @@ import ( "bytes" "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestLegend(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper graph := Chart{ Series: []Series{ @@ -26,6 +26,6 @@ func TestLegend(t *testing.T) { } buf := bytes.NewBuffer([]byte{}) err := graph.Render(PNG, buf) - assert.Nil(err) - assert.NotZero(buf.Len()) + testutil.AssertNil(t, err) + testutil.AssertNotZero(t, buf.Len()) } diff --git a/linear_regression_series_test.go b/linear_regression_series_test.go index 0d04718..3c13d1c 100644 --- a/linear_regression_series_test.go +++ b/linear_regression_series_test.go @@ -3,11 +3,11 @@ package chart import ( "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestLinearRegressionSeries(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper mainSeries := ContinuousSeries{ Name: "A test series", @@ -20,16 +20,16 @@ func TestLinearRegressionSeries(t *testing.T) { } lrx0, lry0 := linRegSeries.GetValues(0) - assert.InDelta(1.0, lrx0, 0.0000001) - assert.InDelta(1.0, lry0, 0.0000001) + testutil.AssertInDelta(t, 1.0, lrx0, 0.0000001) + testutil.AssertInDelta(t, 1.0, lry0, 0.0000001) lrxn, lryn := linRegSeries.GetLastValues() - assert.InDelta(100.0, lrxn, 0.0000001) - assert.InDelta(100.0, lryn, 0.0000001) + testutil.AssertInDelta(t, 100.0, lrxn, 0.0000001) + testutil.AssertInDelta(t, 100.0, lryn, 0.0000001) } func TestLinearRegressionSeriesDesc(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper mainSeries := ContinuousSeries{ Name: "A test series", @@ -42,16 +42,16 @@ func TestLinearRegressionSeriesDesc(t *testing.T) { } lrx0, lry0 := linRegSeries.GetValues(0) - assert.InDelta(100.0, lrx0, 0.0000001) - assert.InDelta(100.0, lry0, 0.0000001) + testutil.AssertInDelta(t, 100.0, lrx0, 0.0000001) + testutil.AssertInDelta(t, 100.0, lry0, 0.0000001) lrxn, lryn := linRegSeries.GetLastValues() - assert.InDelta(1.0, lrxn, 0.0000001) - assert.InDelta(1.0, lryn, 0.0000001) + testutil.AssertInDelta(t, 1.0, lrxn, 0.0000001) + testutil.AssertInDelta(t, 1.0, lryn, 0.0000001) } func TestLinearRegressionSeriesWindowAndOffset(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper mainSeries := ContinuousSeries{ Name: "A test series", @@ -65,13 +65,13 @@ func TestLinearRegressionSeriesWindowAndOffset(t *testing.T) { Limit: 10, } - assert.Equal(10, linRegSeries.Len()) + testutil.AssertEqual(t, 10, linRegSeries.Len()) lrx0, lry0 := linRegSeries.GetValues(0) - assert.InDelta(90.0, lrx0, 0.0000001) - assert.InDelta(90.0, lry0, 0.0000001) + testutil.AssertInDelta(t, 90.0, lrx0, 0.0000001) + testutil.AssertInDelta(t, 90.0, lry0, 0.0000001) lrxn, lryn := linRegSeries.GetLastValues() - assert.InDelta(80.0, lrxn, 0.0000001) - assert.InDelta(80.0, lryn, 0.0000001) + testutil.AssertInDelta(t, 80.0, lrxn, 0.0000001) + testutil.AssertInDelta(t, 80.0, lryn, 0.0000001) } diff --git a/macd_series_test.go b/macd_series_test.go index fa7c7fd..6471f6d 100644 --- a/macd_series_test.go +++ b/macd_series_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) var ( @@ -63,13 +63,13 @@ var ( ) func TestMACDSeries(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper mockSeries := mockValuesProvider{ emaXValues, emaYValues, } - assert.Equal(50, mockSeries.Len()) + testutil.AssertEqual(t, 50, mockSeries.Len()) mas := &MACDSeries{ InnerSeries: mockSeries, @@ -81,8 +81,8 @@ func TestMACDSeries(t *testing.T) { yvalues = append(yvalues, y) } - assert.NotEmpty(yvalues) + testutil.AssertNotEmpty(t, yvalues) for index, vy := range yvalues { - assert.InDelta(vy, macdExpected[index], emaDelta, fmt.Sprintf("delta @ %d actual: %0.9f expected: %0.9f", index, vy, macdExpected[index])) + testutil.AssertInDelta(t, vy, macdExpected[index], emaDelta, fmt.Sprintf("delta @ %d actual: %0.9f expected: %0.9f", index, vy, macdExpected[index])) } } diff --git a/matrix/matrix_test.go b/matrix/matrix_test.go index eb14e33..17b8be5 100644 --- a/matrix/matrix_test.go +++ b/matrix/matrix_test.go @@ -3,139 +3,139 @@ package matrix import ( "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestNew(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := New(10, 5) rows, cols := m.Size() - assert.Equal(10, rows) - assert.Equal(5, cols) - assert.Zero(m.Get(0, 0)) - assert.Zero(m.Get(9, 4)) + testutil.AssertEqual(t, 10, rows) + testutil.AssertEqual(t, 5, cols) + testutil.AssertZero(t, m.Get(0, 0)) + testutil.AssertZero(t, m.Get(9, 4)) } func TestNewWithValues(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := New(5, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) rows, cols := m.Size() - assert.Equal(5, rows) - assert.Equal(2, cols) - assert.Equal(1, m.Get(0, 0)) - assert.Equal(10, m.Get(4, 1)) + testutil.AssertEqual(t, 5, rows) + testutil.AssertEqual(t, 2, cols) + testutil.AssertEqual(t, 1, m.Get(0, 0)) + testutil.AssertEqual(t, 10, m.Get(4, 1)) } func TestIdentitiy(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper id := Identity(5) rows, cols := id.Size() - assert.Equal(5, rows) - assert.Equal(5, cols) - assert.Equal(1, id.Get(0, 0)) - assert.Equal(1, id.Get(1, 1)) - assert.Equal(1, id.Get(2, 2)) - assert.Equal(1, id.Get(3, 3)) - assert.Equal(1, id.Get(4, 4)) - assert.Equal(0, id.Get(0, 1)) - assert.Equal(0, id.Get(1, 0)) - assert.Equal(0, id.Get(4, 0)) - assert.Equal(0, id.Get(0, 4)) + testutil.AssertEqual(t, 5, rows) + testutil.AssertEqual(t, 5, cols) + testutil.AssertEqual(t, 1, id.Get(0, 0)) + testutil.AssertEqual(t, 1, id.Get(1, 1)) + testutil.AssertEqual(t, 1, id.Get(2, 2)) + testutil.AssertEqual(t, 1, id.Get(3, 3)) + testutil.AssertEqual(t, 1, id.Get(4, 4)) + testutil.AssertEqual(t, 0, id.Get(0, 1)) + testutil.AssertEqual(t, 0, id.Get(1, 0)) + testutil.AssertEqual(t, 0, id.Get(4, 0)) + testutil.AssertEqual(t, 0, id.Get(0, 4)) } func TestNewFromArrays(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 2, 3, 4}, {5, 6, 7, 8}, }) - assert.NotNil(m) + testutil.AssertNotNil(t, m) rows, cols := m.Size() - assert.Equal(2, rows) - assert.Equal(4, cols) + testutil.AssertEqual(t, 2, rows) + testutil.AssertEqual(t, 4, cols) } func TestOnes(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper ones := Ones(5, 10) rows, cols := ones.Size() - assert.Equal(5, rows) - assert.Equal(10, cols) + testutil.AssertEqual(t, 5, rows) + testutil.AssertEqual(t, 10, cols) for row := 0; row < rows; row++ { for col := 0; col < cols; col++ { - assert.Equal(1, ones.Get(row, col)) + testutil.AssertEqual(t, 1, ones.Get(row, col)) } } } func TestMatrixEpsilon(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper ones := Ones(2, 2) ones = ones.WithEpsilon(0.001) - assert.Equal(0.001, ones.Epsilon()) + testutil.AssertEqual(t, 0.001, ones.Epsilon()) } func TestMatrixArrays(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 2, 3}, {4, 5, 6}, }) - assert.NotNil(m) + testutil.AssertNotNil(t, m) arrays := m.Arrays() - assert.Equal(arrays, [][]float64{ + testutil.AssertEqual(t, arrays, [][]float64{ {1, 2, 3}, {4, 5, 6}, }) } func TestMatrixIsSquare(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper - assert.False(NewFromArrays([][]float64{ + testutil.AssertFalse(t, NewFromArrays([][]float64{ {1, 2, 3}, {4, 5, 6}, }).IsSquare()) - assert.False(NewFromArrays([][]float64{ + testutil.AssertFalse(t, NewFromArrays([][]float64{ {1, 2}, {3, 4}, {5, 6}, }).IsSquare()) - assert.True(NewFromArrays([][]float64{ + testutil.AssertTrue(t, NewFromArrays([][]float64{ {1, 2}, {3, 4}, }).IsSquare()) } func TestMatrixIsSymmetric(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper - assert.False(NewFromArrays([][]float64{ + testutil.AssertFalse(t, NewFromArrays([][]float64{ {1, 2, 3}, {2, 1, 2}, }).IsSymmetric()) - assert.False(NewFromArrays([][]float64{ + testutil.AssertFalse(t, NewFromArrays([][]float64{ {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, }).IsSymmetric()) - assert.True(NewFromArrays([][]float64{ + testutil.AssertTrue(t, NewFromArrays([][]float64{ {1, 2, 3}, {2, 1, 2}, {3, 2, 1}, @@ -144,7 +144,7 @@ func TestMatrixIsSymmetric(t *testing.T) { } func TestMatrixGet(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 2, 3}, @@ -152,19 +152,19 @@ func TestMatrixGet(t *testing.T) { {7, 8, 9}, }) - assert.Equal(1, m.Get(0, 0)) - assert.Equal(2, m.Get(0, 1)) - assert.Equal(3, m.Get(0, 2)) - assert.Equal(4, m.Get(1, 0)) - assert.Equal(5, m.Get(1, 1)) - assert.Equal(6, m.Get(1, 2)) - assert.Equal(7, m.Get(2, 0)) - assert.Equal(8, m.Get(2, 1)) - assert.Equal(9, m.Get(2, 2)) + testutil.AssertEqual(t, 1, m.Get(0, 0)) + testutil.AssertEqual(t, 2, m.Get(0, 1)) + testutil.AssertEqual(t, 3, m.Get(0, 2)) + testutil.AssertEqual(t, 4, m.Get(1, 0)) + testutil.AssertEqual(t, 5, m.Get(1, 1)) + testutil.AssertEqual(t, 6, m.Get(1, 2)) + testutil.AssertEqual(t, 7, m.Get(2, 0)) + testutil.AssertEqual(t, 8, m.Get(2, 1)) + testutil.AssertEqual(t, 9, m.Get(2, 2)) } func TestMatrixSet(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 2, 3}, @@ -173,11 +173,11 @@ func TestMatrixSet(t *testing.T) { }) m.Set(1, 1, 99) - assert.Equal(99, m.Get(1, 1)) + testutil.AssertEqual(t, 99, m.Get(1, 1)) } func TestMatrixCol(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 2, 3}, @@ -185,13 +185,13 @@ func TestMatrixCol(t *testing.T) { {7, 8, 9}, }) - assert.Equal([]float64{1, 4, 7}, m.Col(0)) - assert.Equal([]float64{2, 5, 8}, m.Col(1)) - assert.Equal([]float64{3, 6, 9}, m.Col(2)) + testutil.AssertEqual(t, []float64{1, 4, 7}, m.Col(0)) + testutil.AssertEqual(t, []float64{2, 5, 8}, m.Col(1)) + testutil.AssertEqual(t, []float64{3, 6, 9}, m.Col(2)) } func TestMatrixRow(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 2, 3}, @@ -199,13 +199,13 @@ func TestMatrixRow(t *testing.T) { {7, 8, 9}, }) - assert.Equal([]float64{1, 2, 3}, m.Row(0)) - assert.Equal([]float64{4, 5, 6}, m.Row(1)) - assert.Equal([]float64{7, 8, 9}, m.Row(2)) + testutil.AssertEqual(t, []float64{1, 2, 3}, m.Row(0)) + testutil.AssertEqual(t, []float64{4, 5, 6}, m.Row(1)) + testutil.AssertEqual(t, []float64{7, 8, 9}, m.Row(2)) } func TestMatrixSwapRows(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 2, 3}, @@ -215,13 +215,13 @@ func TestMatrixSwapRows(t *testing.T) { m.SwapRows(0, 1) - assert.Equal([]float64{4, 5, 6}, m.Row(0)) - assert.Equal([]float64{1, 2, 3}, m.Row(1)) - assert.Equal([]float64{7, 8, 9}, m.Row(2)) + testutil.AssertEqual(t, []float64{4, 5, 6}, m.Row(0)) + testutil.AssertEqual(t, []float64{1, 2, 3}, m.Row(1)) + testutil.AssertEqual(t, []float64{7, 8, 9}, m.Row(2)) } func TestMatrixCopy(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 2, 3}, @@ -230,12 +230,12 @@ func TestMatrixCopy(t *testing.T) { }) m2 := m.Copy() - assert.False(m == m2) - assert.True(m.Equals(m2)) + testutil.AssertFalse(t, m == m2) + testutil.AssertTrue(t, m.Equals(m2)) } func TestMatrixDiagonalVector(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 4, 7}, @@ -244,11 +244,11 @@ func TestMatrixDiagonalVector(t *testing.T) { }) diag := m.DiagonalVector() - assert.Equal([]float64{1, 2, 3}, diag) + testutil.AssertEqual(t, []float64{1, 2, 3}, diag) } func TestMatrixDiagonalVectorLandscape(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 4, 7, 99}, @@ -256,11 +256,11 @@ func TestMatrixDiagonalVectorLandscape(t *testing.T) { }) diag := m.DiagonalVector() - assert.Equal([]float64{1, 2}, diag) + testutil.AssertEqual(t, []float64{1, 2}, diag) } func TestMatrixDiagonalVectorPortrait(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 4}, @@ -269,11 +269,11 @@ func TestMatrixDiagonalVectorPortrait(t *testing.T) { }) diag := m.DiagonalVector() - assert.Equal([]float64{1, 2}, diag) + testutil.AssertEqual(t, []float64{1, 2}, diag) } func TestMatrixDiagonal(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 4, 7}, @@ -287,11 +287,11 @@ func TestMatrixDiagonal(t *testing.T) { {0, 0, 3}, }) - assert.True(m.Diagonal().Equals(m2)) + testutil.AssertTrue(t, m.Diagonal().Equals(m2)) } func TestMatrixEquals(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 4, 7}, @@ -299,16 +299,16 @@ func TestMatrixEquals(t *testing.T) { {7, 8, 3}, }) - assert.False(m.Equals(nil)) + testutil.AssertFalse(t, m.Equals(nil)) var nilMatrix *Matrix - assert.True(nilMatrix.Equals(nil)) - assert.False(m.Equals(New(1, 1))) - assert.False(m.Equals(New(3, 3))) - assert.True(m.Equals(New(3, 3, 1, 4, 7, 4, 2, 8, 7, 8, 3))) + testutil.AssertTrue(t, nilMatrix.Equals(nil)) + testutil.AssertFalse(t, m.Equals(New(1, 1))) + testutil.AssertFalse(t, m.Equals(New(3, 3))) + testutil.AssertTrue(t, m.Equals(New(3, 3, 1, 4, 7, 4, 2, 8, 7, 8, 3))) } func TestMatrixL(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 2, 3}, @@ -317,11 +317,11 @@ func TestMatrixL(t *testing.T) { }) l := m.L() - assert.True(l.Equals(New(3, 3, 1, 2, 3, 0, 5, 6, 0, 0, 9))) + testutil.AssertTrue(t, l.Equals(New(3, 3, 1, 2, 3, 0, 5, 6, 0, 0, 9))) } func TestMatrixU(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 2, 3}, @@ -330,11 +330,11 @@ func TestMatrixU(t *testing.T) { }) u := m.U() - assert.True(u.Equals(New(3, 3, 0, 0, 0, 4, 0, 0, 7, 8, 0))) + testutil.AssertTrue(t, u.Equals(New(3, 3, 0, 0, 0, 4, 0, 0, 7, 8, 0))) } func TestMatrixString(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 2, 3}, @@ -342,11 +342,11 @@ func TestMatrixString(t *testing.T) { {7, 8, 9}, }) - assert.Equal("1 2 3 \n4 5 6 \n7 8 9 \n", m.String()) + testutil.AssertEqual(t, "1 2 3 \n4 5 6 \n7 8 9 \n", m.String()) } func TestMatrixLU(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 3, 5}, @@ -355,13 +355,13 @@ func TestMatrixLU(t *testing.T) { }) l, u, p := m.LU() - assert.NotNil(l) - assert.NotNil(u) - assert.NotNil(p) + testutil.AssertNotNil(t, l) + testutil.AssertNotNil(t, u) + testutil.AssertNotNil(t, p) } func TestMatrixQR(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {12, -51, 4}, @@ -370,12 +370,12 @@ func TestMatrixQR(t *testing.T) { }) q, r := m.QR() - assert.NotNil(q) - assert.NotNil(r) + testutil.AssertNotNil(t, q) + testutil.AssertNotNil(t, r) } func TestMatrixTranspose(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper m := NewFromArrays([][]float64{ {1, 2, 3}, @@ -387,10 +387,10 @@ func TestMatrixTranspose(t *testing.T) { m2 := m.Transpose() rows, cols := m2.Size() - assert.Equal(3, rows) - assert.Equal(4, cols) + testutil.AssertEqual(t, 3, rows) + testutil.AssertEqual(t, 4, cols) - assert.Equal(1, m2.Get(0, 0)) - assert.Equal(10, m2.Get(0, 3)) - assert.Equal(3, m2.Get(2, 0)) + testutil.AssertEqual(t, 1, m2.Get(0, 0)) + testutil.AssertEqual(t, 10, m2.Get(0, 3)) + testutil.AssertEqual(t, 3, m2.Get(2, 0)) } diff --git a/matrix/regression_test.go b/matrix/regression_test.go index 5bd282b..d43c0f4 100644 --- a/matrix/regression_test.go +++ b/matrix/regression_test.go @@ -3,20 +3,20 @@ package matrix import ( "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestPoly(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper var xGiven = []float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} var yGiven = []float64{1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321} var degree = 2 c, err := Poly(xGiven, yGiven, degree) - assert.Nil(err) - assert.Len(c, 3) + testutil.AssertNil(t, err) + testutil.AssertLen(t, c, 3) - assert.InDelta(c[0], 0.999999999, DefaultEpsilon) - assert.InDelta(c[1], 2, DefaultEpsilon) - assert.InDelta(c[2], 3, DefaultEpsilon) + testutil.AssertInDelta(t, c[0], 0.999999999, DefaultEpsilon) + testutil.AssertInDelta(t, c[1], 2, DefaultEpsilon) + testutil.AssertInDelta(t, c[2], 3, DefaultEpsilon) } diff --git a/percent_change_series_test.go b/percent_change_series_test.go index 3114bb2..dbc9413 100644 --- a/percent_change_series_test.go +++ b/percent_change_series_test.go @@ -3,11 +3,11 @@ package chart import ( "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestPercentageDifferenceSeries(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper cs := ContinuousSeries{ XValues: LinearRange(1.0, 10.0), @@ -19,17 +19,17 @@ func TestPercentageDifferenceSeries(t *testing.T) { InnerSeries: cs, } - assert.Equal("Test Series", pcs.GetName()) - assert.Equal(10, pcs.Len()) + testutil.AssertEqual(t, "Test Series", pcs.GetName()) + testutil.AssertEqual(t, 10, pcs.Len()) x0, y0 := pcs.GetValues(0) - assert.Equal(1.0, x0) - assert.Equal(0, y0) + testutil.AssertEqual(t, 1.0, x0) + testutil.AssertEqual(t, 0, y0) xn, yn := pcs.GetValues(9) - assert.Equal(10.0, xn) - assert.Equal(9.0, yn) + testutil.AssertEqual(t, 10.0, xn) + testutil.AssertEqual(t, 9.0, yn) xn, yn = pcs.GetLastValues() - assert.Equal(10.0, xn) - assert.Equal(9.0, yn) + testutil.AssertEqual(t, 10.0, xn) + testutil.AssertEqual(t, 9.0, yn) } diff --git a/pie_chart_test.go b/pie_chart_test.go index 960941e..1d9f17a 100644 --- a/pie_chart_test.go +++ b/pie_chart_test.go @@ -4,11 +4,11 @@ import ( "bytes" "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestPieChart(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper pie := PieChart{ Canvas: Style{ @@ -27,11 +27,11 @@ func TestPieChart(t *testing.T) { b := bytes.NewBuffer([]byte{}) pie.Render(PNG, b) - assert.NotZero(b.Len()) + testutil.AssertNotZero(t, b.Len()) } func TestPieChartDropsZeroValues(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper pie := PieChart{ Canvas: Style{ @@ -46,11 +46,11 @@ func TestPieChartDropsZeroValues(t *testing.T) { b := bytes.NewBuffer([]byte{}) err := pie.Render(PNG, b) - assert.Nil(err) + testutil.AssertNil(t, err) } func TestPieChartAllZeroValues(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper pie := PieChart{ Canvas: Style{ @@ -65,5 +65,5 @@ func TestPieChartAllZeroValues(t *testing.T) { b := bytes.NewBuffer([]byte{}) err := pie.Render(PNG, b) - assert.NotNil(err) + testutil.AssertNotNil(t, err) } diff --git a/polynomial_regression_series.go b/polynomial_regression_series.go index ec12025..22cd3c1 100644 --- a/polynomial_regression_series.go +++ b/polynomial_regression_series.go @@ -4,7 +4,7 @@ import ( "fmt" "math" - "github.com/wcharczuk/go-chart/matrix" + "github.com/wcharczuk/go-chart/v2/matrix" ) // Interface Assertions. diff --git a/polynomial_regression_test.go b/polynomial_regression_test.go index 6495f56..8535c74 100644 --- a/polynomial_regression_test.go +++ b/polynomial_regression_test.go @@ -3,12 +3,12 @@ package chart import ( "testing" - assert "github.com/blend/go-sdk/assert" - "github.com/wcharczuk/go-chart/matrix" + "github.com/wcharczuk/go-chart/v2/matrix" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestPolynomialRegression(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper var xv []float64 var yv []float64 @@ -30,6 +30,6 @@ func TestPolynomialRegression(t *testing.T) { for i := 0; i < 100; i++ { _, y := poly.GetValues(i) - assert.InDelta(float64(i*i), y, matrix.DefaultEpsilon) + testutil.AssertInDelta(t, float64(i*i), y, matrix.DefaultEpsilon) } } diff --git a/raster_renderer.go b/raster_renderer.go index 1368641..4de2655 100644 --- a/raster_renderer.go +++ b/raster_renderer.go @@ -7,7 +7,7 @@ import ( "math" "github.com/golang/freetype/truetype" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2/drawing" ) // PNG returns a new png/raster renderer. diff --git a/renderer.go b/renderer.go index 68a668b..589c773 100644 --- a/renderer.go +++ b/renderer.go @@ -4,7 +4,7 @@ import ( "io" "github.com/golang/freetype/truetype" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2/drawing" ) // Renderer represents the basic methods required to draw a chart. diff --git a/seq_test.go b/seq_test.go index bd0ce22..3cd7f9c 100644 --- a/seq_test.go +++ b/seq_test.go @@ -3,134 +3,134 @@ package chart import ( "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestSeqEach(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := Seq{NewArray(1, 2, 3, 4)} values.Each(func(i int, v float64) { - assert.Equal(i, v-1) + testutil.AssertEqual(t, i, v-1) }) } func TestSeqMap(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := Seq{NewArray(1, 2, 3, 4)} mapped := values.Map(func(i int, v float64) float64 { - assert.Equal(i, v-1) + testutil.AssertEqual(t, i, v-1) return v * 2 }) - assert.Equal(4, mapped.Len()) + testutil.AssertEqual(t, 4, mapped.Len()) } func TestSeqFoldLeft(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := Seq{NewArray(1, 2, 3, 4)} ten := values.FoldLeft(func(_ int, vp, v float64) float64 { return vp + v }) - assert.Equal(10, ten) + testutil.AssertEqual(t, 10, ten) orderTest := Seq{NewArray(10, 3, 2, 1)} four := orderTest.FoldLeft(func(_ int, vp, v float64) float64 { return vp - v }) - assert.Equal(4, four) + testutil.AssertEqual(t, 4, four) } func TestSeqFoldRight(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := Seq{NewArray(1, 2, 3, 4)} ten := values.FoldRight(func(_ int, vp, v float64) float64 { return vp + v }) - assert.Equal(10, ten) + testutil.AssertEqual(t, 10, ten) orderTest := Seq{NewArray(10, 3, 2, 1)} notFour := orderTest.FoldRight(func(_ int, vp, v float64) float64 { return vp - v }) - assert.Equal(-14, notFour) + testutil.AssertEqual(t, -14, notFour) } func TestSeqSum(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := Seq{NewArray(1, 2, 3, 4)} - assert.Equal(10, values.Sum()) + testutil.AssertEqual(t, 10, values.Sum()) } func TestSeqAverage(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := Seq{NewArray(1, 2, 3, 4)} - assert.Equal(2.5, values.Average()) + testutil.AssertEqual(t, 2.5, values.Average()) valuesOdd := Seq{NewArray(1, 2, 3, 4, 5)} - assert.Equal(3, valuesOdd.Average()) + testutil.AssertEqual(t, 3, valuesOdd.Average()) } func TestSequenceVariance(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := Seq{NewArray(1, 2, 3, 4, 5)} - assert.Equal(2, values.Variance()) + testutil.AssertEqual(t, 2, values.Variance()) } func TestSequenceNormalize(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper normalized := ValueSequence(1, 2, 3, 4, 5).Normalize().Values() - assert.NotEmpty(normalized) - assert.Len(normalized, 5) - assert.Equal(0, normalized[0]) - assert.Equal(0.25, normalized[1]) - assert.Equal(1, normalized[4]) + testutil.AssertNotEmpty(t, normalized) + testutil.AssertLen(t, normalized, 5) + testutil.AssertEqual(t, 0, normalized[0]) + testutil.AssertEqual(t, 0.25, normalized[1]) + testutil.AssertEqual(t, 1, normalized[4]) } func TestLinearRange(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := LinearRange(1, 100) - assert.Len(values, 100) - assert.Equal(1, values[0]) - assert.Equal(100, values[99]) + testutil.AssertLen(t, values, 100) + testutil.AssertEqual(t, 1, values[0]) + testutil.AssertEqual(t, 100, values[99]) } func TestLinearRangeWithStep(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := LinearRangeWithStep(0, 100, 5) - assert.Equal(100, values[20]) - assert.Len(values, 21) + testutil.AssertEqual(t, 100, values[20]) + testutil.AssertLen(t, values, 21) } func TestLinearRangeReversed(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := LinearRange(10.0, 1.0) - assert.Equal(10, len(values)) - assert.Equal(10.0, values[0]) - assert.Equal(1.0, values[9]) + testutil.AssertEqual(t, 10, len(values)) + testutil.AssertEqual(t, 10.0, values[0]) + testutil.AssertEqual(t, 1.0, values[9]) } func TestLinearSequenceRegression(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper // note; this assumes a 1.0 step is implicitly set in the constructor. linearProvider := NewLinearSequence().WithStart(1.0).WithEnd(100.0) - assert.Equal(1, linearProvider.Start()) - assert.Equal(100, linearProvider.End()) - assert.Equal(100, linearProvider.Len()) + testutil.AssertEqual(t, 1, linearProvider.Start()) + testutil.AssertEqual(t, 100, linearProvider.End()) + testutil.AssertEqual(t, 100, linearProvider.Len()) values := Seq{linearProvider}.Values() - assert.Len(values, 100) - assert.Equal(1.0, values[0]) - assert.Equal(100, values[99]) + testutil.AssertLen(t, values, 100) + testutil.AssertEqual(t, 1.0, values[0]) + testutil.AssertEqual(t, 100, values[99]) } diff --git a/sma_series_test.go b/sma_series_test.go index 27e0c68..5de32a9 100644 --- a/sma_series_test.go +++ b/sma_series_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) type mockValuesProvider struct { @@ -28,13 +28,13 @@ func (m mockValuesProvider) GetValues(index int) (x, y float64) { } func TestSMASeriesGetValue(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper mockSeries := mockValuesProvider{ LinearRange(1.0, 10.0), LinearRange(10, 1.0), } - assert.Equal(10, mockSeries.Len()) + testutil.AssertEqual(t, 10, mockSeries.Len()) mas := &SMASeries{ InnerSeries: mockSeries, @@ -47,25 +47,25 @@ func TestSMASeriesGetValue(t *testing.T) { yvalues = append(yvalues, y) } - assert.Equal(10.0, yvalues[0]) - assert.Equal(9.5, yvalues[1]) - assert.Equal(9.0, yvalues[2]) - assert.Equal(8.5, yvalues[3]) - assert.Equal(8.0, yvalues[4]) - assert.Equal(7.5, yvalues[5]) - assert.Equal(7.0, yvalues[6]) - assert.Equal(6.5, yvalues[7]) - assert.Equal(6.0, yvalues[8]) + testutil.AssertEqual(t, 10.0, yvalues[0]) + testutil.AssertEqual(t, 9.5, yvalues[1]) + testutil.AssertEqual(t, 9.0, yvalues[2]) + testutil.AssertEqual(t, 8.5, yvalues[3]) + testutil.AssertEqual(t, 8.0, yvalues[4]) + testutil.AssertEqual(t, 7.5, yvalues[5]) + testutil.AssertEqual(t, 7.0, yvalues[6]) + testutil.AssertEqual(t, 6.5, yvalues[7]) + testutil.AssertEqual(t, 6.0, yvalues[8]) } func TestSMASeriesGetLastValueWindowOverlap(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper mockSeries := mockValuesProvider{ LinearRange(1.0, 10.0), LinearRange(10, 1.0), } - assert.Equal(10, mockSeries.Len()) + testutil.AssertEqual(t, 10, mockSeries.Len()) mas := &SMASeries{ InnerSeries: mockSeries, @@ -79,19 +79,19 @@ func TestSMASeriesGetLastValueWindowOverlap(t *testing.T) { } lx, ly := mas.GetLastValues() - assert.Equal(10.0, lx) - assert.Equal(5.5, ly) - assert.Equal(yvalues[len(yvalues)-1], ly) + testutil.AssertEqual(t, 10.0, lx) + testutil.AssertEqual(t, 5.5, ly) + testutil.AssertEqual(t, yvalues[len(yvalues)-1], ly) } func TestSMASeriesGetLastValue(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper mockSeries := mockValuesProvider{ LinearRange(1.0, 100.0), LinearRange(100, 1.0), } - assert.Equal(100, mockSeries.Len()) + testutil.AssertEqual(t, 100, mockSeries.Len()) mas := &SMASeries{ InnerSeries: mockSeries, @@ -105,7 +105,7 @@ func TestSMASeriesGetLastValue(t *testing.T) { } lx, ly := mas.GetLastValues() - assert.Equal(100.0, lx) - assert.Equal(6, ly) - assert.Equal(yvalues[len(yvalues)-1], ly) + testutil.AssertEqual(t, 100.0, lx) + testutil.AssertEqual(t, 6, ly) + testutil.AssertEqual(t, yvalues[len(yvalues)-1], ly) } diff --git a/stringutil_test.go b/stringutil_test.go index 63ab412..bc22b23 100644 --- a/stringutil_test.go +++ b/stringutil_test.go @@ -3,20 +3,20 @@ package chart import ( "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestSplitCSV(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper - assert.Empty(SplitCSV("")) - assert.Equal([]string{"foo"}, SplitCSV("foo")) - assert.Equal([]string{"foo", "bar"}, SplitCSV("foo,bar")) - assert.Equal([]string{"foo", "bar"}, SplitCSV("foo, bar")) - assert.Equal([]string{"foo", "bar"}, SplitCSV(" foo , bar ")) - assert.Equal([]string{"foo", "bar", "baz"}, SplitCSV("foo,bar,baz")) - assert.Equal([]string{"foo", "bar", "baz,buzz"}, SplitCSV("foo,bar,\"baz,buzz\"")) - assert.Equal([]string{"foo", "bar", "baz,'buzz'"}, SplitCSV("foo,bar,\"baz,'buzz'\"")) - assert.Equal([]string{"foo", "bar", "baz,'buzz"}, SplitCSV("foo,bar,\"baz,'buzz\"")) - assert.Equal([]string{"foo", "bar", "baz,\"buzz\""}, SplitCSV("foo,bar,'baz,\"buzz\"'")) + testutil.AssertEmpty(t, SplitCSV("")) + testutil.AssertEqual(t, []string{"foo"}, SplitCSV("foo")) + testutil.AssertEqual(t, []string{"foo", "bar"}, SplitCSV("foo,bar")) + testutil.AssertEqual(t, []string{"foo", "bar"}, SplitCSV("foo, bar")) + testutil.AssertEqual(t, []string{"foo", "bar"}, SplitCSV(" foo , bar ")) + testutil.AssertEqual(t, []string{"foo", "bar", "baz"}, SplitCSV("foo,bar,baz")) + testutil.AssertEqual(t, []string{"foo", "bar", "baz,buzz"}, SplitCSV("foo,bar,\"baz,buzz\"")) + testutil.AssertEqual(t, []string{"foo", "bar", "baz,'buzz'"}, SplitCSV("foo,bar,\"baz,'buzz'\"")) + testutil.AssertEqual(t, []string{"foo", "bar", "baz,'buzz"}, SplitCSV("foo,bar,\"baz,'buzz\"")) + testutil.AssertEqual(t, []string{"foo", "bar", "baz,\"buzz\""}, SplitCSV("foo,bar,'baz,\"buzz\"'")) } diff --git a/style.go b/style.go index fe1f35a..c601d6d 100644 --- a/style.go +++ b/style.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/golang/freetype/truetype" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2/drawing" ) const ( diff --git a/style_test.go b/style_test.go index ae4d8bd..5cc1c08 100644 --- a/style_test.go +++ b/style_test.go @@ -3,121 +3,121 @@ package chart import ( "testing" - "github.com/blend/go-sdk/assert" "github.com/golang/freetype/truetype" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestStyleIsZero(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper zero := Style{} - assert.True(zero.IsZero()) + testutil.AssertTrue(t, zero.IsZero()) strokeColor := Style{StrokeColor: drawing.ColorWhite} - assert.False(strokeColor.IsZero()) + testutil.AssertFalse(t, strokeColor.IsZero()) fillColor := Style{FillColor: drawing.ColorWhite} - assert.False(fillColor.IsZero()) + testutil.AssertFalse(t, fillColor.IsZero()) strokeWidth := Style{StrokeWidth: 5.0} - assert.False(strokeWidth.IsZero()) + testutil.AssertFalse(t, strokeWidth.IsZero()) fontSize := Style{FontSize: 12.0} - assert.False(fontSize.IsZero()) + testutil.AssertFalse(t, fontSize.IsZero()) fontColor := Style{FontColor: drawing.ColorWhite} - assert.False(fontColor.IsZero()) + testutil.AssertFalse(t, fontColor.IsZero()) font := Style{Font: &truetype.Font{}} - assert.False(font.IsZero()) + testutil.AssertFalse(t, font.IsZero()) } func TestStyleGetStrokeColor(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper unset := Style{} - assert.Equal(drawing.ColorTransparent, unset.GetStrokeColor()) - assert.Equal(drawing.ColorWhite, unset.GetStrokeColor(drawing.ColorWhite)) + testutil.AssertEqual(t, drawing.ColorTransparent, unset.GetStrokeColor()) + testutil.AssertEqual(t, drawing.ColorWhite, unset.GetStrokeColor(drawing.ColorWhite)) set := Style{StrokeColor: drawing.ColorWhite} - assert.Equal(drawing.ColorWhite, set.GetStrokeColor()) - assert.Equal(drawing.ColorWhite, set.GetStrokeColor(drawing.ColorBlack)) + testutil.AssertEqual(t, drawing.ColorWhite, set.GetStrokeColor()) + testutil.AssertEqual(t, drawing.ColorWhite, set.GetStrokeColor(drawing.ColorBlack)) } func TestStyleGetFillColor(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper unset := Style{} - assert.Equal(drawing.ColorTransparent, unset.GetFillColor()) - assert.Equal(drawing.ColorWhite, unset.GetFillColor(drawing.ColorWhite)) + testutil.AssertEqual(t, drawing.ColorTransparent, unset.GetFillColor()) + testutil.AssertEqual(t, drawing.ColorWhite, unset.GetFillColor(drawing.ColorWhite)) set := Style{FillColor: drawing.ColorWhite} - assert.Equal(drawing.ColorWhite, set.GetFillColor()) - assert.Equal(drawing.ColorWhite, set.GetFillColor(drawing.ColorBlack)) + testutil.AssertEqual(t, drawing.ColorWhite, set.GetFillColor()) + testutil.AssertEqual(t, drawing.ColorWhite, set.GetFillColor(drawing.ColorBlack)) } func TestStyleGetStrokeWidth(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper unset := Style{} - assert.Equal(DefaultStrokeWidth, unset.GetStrokeWidth()) - assert.Equal(DefaultStrokeWidth+1, unset.GetStrokeWidth(DefaultStrokeWidth+1)) + testutil.AssertEqual(t, DefaultStrokeWidth, unset.GetStrokeWidth()) + testutil.AssertEqual(t, DefaultStrokeWidth+1, unset.GetStrokeWidth(DefaultStrokeWidth+1)) set := Style{StrokeWidth: DefaultStrokeWidth + 2} - assert.Equal(DefaultStrokeWidth+2, set.GetStrokeWidth()) - assert.Equal(DefaultStrokeWidth+2, set.GetStrokeWidth(DefaultStrokeWidth+1)) + testutil.AssertEqual(t, DefaultStrokeWidth+2, set.GetStrokeWidth()) + testutil.AssertEqual(t, DefaultStrokeWidth+2, set.GetStrokeWidth(DefaultStrokeWidth+1)) } func TestStyleGetFontSize(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper unset := Style{} - assert.Equal(DefaultFontSize, unset.GetFontSize()) - assert.Equal(DefaultFontSize+1, unset.GetFontSize(DefaultFontSize+1)) + testutil.AssertEqual(t, DefaultFontSize, unset.GetFontSize()) + testutil.AssertEqual(t, DefaultFontSize+1, unset.GetFontSize(DefaultFontSize+1)) set := Style{FontSize: DefaultFontSize + 2} - assert.Equal(DefaultFontSize+2, set.GetFontSize()) - assert.Equal(DefaultFontSize+2, set.GetFontSize(DefaultFontSize+1)) + testutil.AssertEqual(t, DefaultFontSize+2, set.GetFontSize()) + testutil.AssertEqual(t, DefaultFontSize+2, set.GetFontSize(DefaultFontSize+1)) } func TestStyleGetFontColor(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper unset := Style{} - assert.Equal(drawing.ColorTransparent, unset.GetFontColor()) - assert.Equal(drawing.ColorWhite, unset.GetFontColor(drawing.ColorWhite)) + testutil.AssertEqual(t, drawing.ColorTransparent, unset.GetFontColor()) + testutil.AssertEqual(t, drawing.ColorWhite, unset.GetFontColor(drawing.ColorWhite)) set := Style{FontColor: drawing.ColorWhite} - assert.Equal(drawing.ColorWhite, set.GetFontColor()) - assert.Equal(drawing.ColorWhite, set.GetFontColor(drawing.ColorBlack)) + testutil.AssertEqual(t, drawing.ColorWhite, set.GetFontColor()) + testutil.AssertEqual(t, drawing.ColorWhite, set.GetFontColor(drawing.ColorBlack)) } func TestStyleGetFont(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) unset := Style{} - assert.Nil(unset.GetFont()) - assert.Equal(f, unset.GetFont(f)) + testutil.AssertNil(t, unset.GetFont()) + testutil.AssertEqual(t, f, unset.GetFont(f)) set := Style{Font: f} - assert.NotNil(set.GetFont()) + testutil.AssertNotNil(t, set.GetFont()) } func TestStyleGetPadding(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper unset := Style{} - assert.True(unset.GetPadding().IsZero()) - assert.False(unset.GetPadding(DefaultBackgroundPadding).IsZero()) - assert.Equal(DefaultBackgroundPadding, unset.GetPadding(DefaultBackgroundPadding)) + testutil.AssertTrue(t, unset.GetPadding().IsZero()) + testutil.AssertFalse(t, unset.GetPadding(DefaultBackgroundPadding).IsZero()) + testutil.AssertEqual(t, DefaultBackgroundPadding, unset.GetPadding(DefaultBackgroundPadding)) set := Style{Padding: DefaultBackgroundPadding} - assert.False(set.GetPadding().IsZero()) - assert.Equal(DefaultBackgroundPadding, set.GetPadding()) - assert.Equal(DefaultBackgroundPadding, set.GetPadding(Box{ + testutil.AssertFalse(t, set.GetPadding().IsZero()) + testutil.AssertEqual(t, DefaultBackgroundPadding, set.GetPadding()) + testutil.AssertEqual(t, DefaultBackgroundPadding, set.GetPadding(Box{ Top: DefaultBackgroundPadding.Top + 1, Left: DefaultBackgroundPadding.Left + 1, Right: DefaultBackgroundPadding.Right + 1, @@ -126,10 +126,10 @@ func TestStyleGetPadding(t *testing.T) { } func TestStyleWithDefaultsFrom(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) unset := Style{} set := Style{ @@ -142,11 +142,11 @@ func TestStyleWithDefaultsFrom(t *testing.T) { } coalesced := unset.InheritFrom(set) - assert.Equal(set, coalesced) + testutil.AssertEqual(t, set, coalesced) } func TestStyleGetStrokeOptions(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper set := Style{ StrokeColor: drawing.ColorWhite, @@ -156,14 +156,14 @@ func TestStyleGetStrokeOptions(t *testing.T) { Padding: DefaultBackgroundPadding, } svgStroke := set.GetStrokeOptions() - assert.False(svgStroke.StrokeColor.IsZero()) - assert.NotZero(svgStroke.StrokeWidth) - assert.True(svgStroke.FillColor.IsZero()) - assert.True(svgStroke.FontColor.IsZero()) + testutil.AssertFalse(t, svgStroke.StrokeColor.IsZero()) + testutil.AssertNotZero(t, svgStroke.StrokeWidth) + testutil.AssertTrue(t, svgStroke.FillColor.IsZero()) + testutil.AssertTrue(t, svgStroke.FontColor.IsZero()) } func TestStyleGetFillOptions(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper set := Style{ StrokeColor: drawing.ColorWhite, @@ -173,14 +173,14 @@ func TestStyleGetFillOptions(t *testing.T) { Padding: DefaultBackgroundPadding, } svgFill := set.GetFillOptions() - assert.False(svgFill.FillColor.IsZero()) - assert.Zero(svgFill.StrokeWidth) - assert.True(svgFill.StrokeColor.IsZero()) - assert.True(svgFill.FontColor.IsZero()) + testutil.AssertFalse(t, svgFill.FillColor.IsZero()) + testutil.AssertZero(t, svgFill.StrokeWidth) + testutil.AssertTrue(t, svgFill.StrokeColor.IsZero()) + testutil.AssertTrue(t, svgFill.FontColor.IsZero()) } func TestStyleGetFillAndStrokeOptions(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper set := Style{ StrokeColor: drawing.ColorWhite, @@ -190,14 +190,14 @@ func TestStyleGetFillAndStrokeOptions(t *testing.T) { Padding: DefaultBackgroundPadding, } svgFillAndStroke := set.GetFillAndStrokeOptions() - assert.False(svgFillAndStroke.FillColor.IsZero()) - assert.NotZero(svgFillAndStroke.StrokeWidth) - assert.False(svgFillAndStroke.StrokeColor.IsZero()) - assert.True(svgFillAndStroke.FontColor.IsZero()) + testutil.AssertFalse(t, svgFillAndStroke.FillColor.IsZero()) + testutil.AssertNotZero(t, svgFillAndStroke.StrokeWidth) + testutil.AssertFalse(t, svgFillAndStroke.StrokeColor.IsZero()) + testutil.AssertTrue(t, svgFillAndStroke.FontColor.IsZero()) } func TestStyleGetTextOptions(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper set := Style{ StrokeColor: drawing.ColorWhite, @@ -207,8 +207,8 @@ func TestStyleGetTextOptions(t *testing.T) { Padding: DefaultBackgroundPadding, } svgStroke := set.GetTextOptions() - assert.True(svgStroke.StrokeColor.IsZero()) - assert.Zero(svgStroke.StrokeWidth) - assert.True(svgStroke.FillColor.IsZero()) - assert.False(svgStroke.FontColor.IsZero()) + testutil.AssertTrue(t, svgStroke.StrokeColor.IsZero()) + testutil.AssertZero(t, svgStroke.StrokeWidth) + testutil.AssertTrue(t, svgStroke.FillColor.IsZero()) + testutil.AssertFalse(t, svgStroke.FontColor.IsZero()) } diff --git a/testutil/helpers.go b/testutil/helpers.go new file mode 100644 index 0000000..a5774a6 --- /dev/null +++ b/testutil/helpers.go @@ -0,0 +1,202 @@ +package testutil + +import ( + "math" + "reflect" + "strings" + "testing" +) + +// AssertNil asserts an argument is nil. +func AssertNil(t *testing.T, actual interface{}) { + if !isNil(actual) { + t.Errorf("assertion failed; expected actual to be nil") + t.FailNow() + } +} + +// AssertNotNil asserts an argument is not nil. +func AssertNotNil(t *testing.T, actual interface{}, message ...interface{}) { + if isNil(actual) { + t.Error("assertion failed; expected actual to not be nil") + if len(message) > 0 { + t.Error(message...) + } + t.FailNow() + } +} + +// AssertEqual asserts two arguments are equal. +func AssertEqual(t *testing.T, expected, actual interface{}, message ...interface{}) { + if !equal(expected, actual) { + t.Errorf("assertion failed; expected %v to equal %v", actual, expected) + if len(message) > 0 { + t.Error(message...) + } + t.FailNow() + } +} + +// AssertNotEqual asserts two arguments are not equal. +func AssertNotEqual(t *testing.T, expected, actual interface{}, message ...interface{}) { + if equal(expected, actual) { + t.Errorf("assertion failed; expected %v to not equal %v", actual, expected) + if len(message) > 0 { + t.Error(message...) + } + t.FailNow() + } +} + +// AssertZero asserts an argument is zero. +func AssertZero(t *testing.T, actual interface{}, message ...interface{}) { + AssertEqual(t, 0, actual) +} + +// AssertNotZero asserts an argument is not zero. +func AssertNotZero(t *testing.T, actual interface{}, message ...interface{}) { + AssertNotEqual(t, 0, actual) +} + +// AssertTrue asserts an argument is true. +func AssertTrue(t *testing.T, arg bool, message ...interface{}) { + if !arg { + t.Errorf("assertion failed; expected actual to be true") + if len(message) > 0 { + t.Error(message...) + } + t.FailNow() + } +} + +// AssertFalse asserts an argument is false. +func AssertFalse(t *testing.T, arg bool, message ...interface{}) { + if arg { + t.Errorf("assertion failed; expected actual to be false") + if len(message) > 0 { + t.Error(message...) + } + t.FailNow() + } +} + +// AssertInDelta asserts a two arguments are within a delta of eachother. +// +// This delta will be determined absolute, and the delta should always be positive. +func AssertInDelta(t *testing.T, from, to, delta float64, message ...interface{}) { + if diff := math.Abs(from - to); diff > delta { + t.Errorf("assertion failed; expected absolute difference of %f and %f to be %f", from, to, delta) + if len(message) > 0 { + t.Error(message...) + } + t.FailNow() + } +} + +// AssertEmpty asserts an argument is empty. +func AssertEmpty(t *testing.T, arg interface{}, message ...interface{}) { + if getLength(arg) != 0 { + t.Errorf("assertion failed; expected actual to be empty") + if len(message) > 0 { + t.Error(message...) + } + t.FailNow() + } +} + +// AssertNotEmpty asserts an argument is not empty. +func AssertNotEmpty(t *testing.T, arg interface{}, message ...interface{}) { + if getLength(arg) == 0 { + t.Errorf("assertion failed; expected actual to not be empty") + if len(message) > 0 { + t.Error(message...) + } + t.FailNow() + } +} + +// AssertLen asserts an argument has a given length. +func AssertLen(t *testing.T, arg interface{}, length int, message ...interface{}) { + if getLength(arg) != length { + t.Errorf("assertion failed; expected actual to have length %d", length) + if len(message) > 0 { + t.Error(message...) + } + t.FailNow() + } +} + +// AssertContains asserts an argument contains a given substring. +func AssertContains(t *testing.T, s, substr string, message ...interface{}) { + if !strings.Contains(s, substr) { + t.Errorf("assertion failed; expected actual to contain %q", substr) + if len(message) > 0 { + t.Error(message...) + } + t.FailNow() + } +} + +// AssertNotContains asserts an argument does not contain a given substring. +func AssertNotContains(t *testing.T, s, substr string, message ...interface{}) { + if strings.Contains(s, substr) { + t.Errorf("assertion failed; expected actual to not contain %q", substr) + if len(message) > 0 { + t.Error(message...) + } + t.FailNow() + } +} + +func equal(expected, actual interface{}) bool { + if expected == nil && actual == nil { + return true + } + if (expected == nil && actual != nil) || (expected != nil && actual == nil) { + return false + } + + actualType := reflect.TypeOf(actual) + if actualType == nil { + return false + } + expectedValue := reflect.ValueOf(expected) + if expectedValue.IsValid() && expectedValue.Type().ConvertibleTo(actualType) { + return reflect.DeepEqual(expectedValue.Convert(actualType).Interface(), actual) + } + + return reflect.DeepEqual(expected, actual) +} + +func isNil(object interface{}) bool { + if object == nil { + return true + } + + value := reflect.ValueOf(object) + kind := value.Kind() + if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() { + return true + } + return false +} + +func getLength(object interface{}) int { + if object == nil { + return 0 + } else if object == "" { + return 0 + } + + objValue := reflect.ValueOf(object) + + switch objValue.Kind() { + case reflect.Map: + fallthrough + case reflect.Slice, reflect.Chan, reflect.String: + { + return objValue.Len() + } + } + return 0 +} diff --git a/text_test.go b/text_test.go index 41034c4..4f1e209 100644 --- a/text_test.go +++ b/text_test.go @@ -3,58 +3,58 @@ package chart import ( "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestTextWrapWord(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper r, err := PNG(1024, 1024) - assert.Nil(err) + testutil.AssertNil(t, err) f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) basicTextStyle := Style{Font: f, FontSize: 24} output := Text.WrapFitWord(r, "this is a test string", 100, basicTextStyle) - assert.NotEmpty(output) - assert.Len(output, 3) + testutil.AssertNotEmpty(t, output) + testutil.AssertLen(t, output, 3) for _, line := range output { basicTextStyle.WriteToRenderer(r) lineBox := r.MeasureText(line) - assert.True(lineBox.Width() < 100, line+": "+lineBox.String()) + testutil.AssertTrue(t, lineBox.Width() < 100, line+": "+lineBox.String()) } - assert.Equal("this is", output[0]) - assert.Equal("a test", output[1]) - assert.Equal("string", output[2]) + testutil.AssertEqual(t, "this is", output[0]) + testutil.AssertEqual(t, "a test", output[1]) + testutil.AssertEqual(t, "string", output[2]) output = Text.WrapFitWord(r, "foo", 100, basicTextStyle) - assert.Len(output, 1) - assert.Equal("foo", output[0]) + testutil.AssertLen(t, output, 1) + testutil.AssertEqual(t, "foo", output[0]) // test that it handles newlines. output = Text.WrapFitWord(r, "this\nis\na\ntest\nstring", 100, basicTextStyle) - assert.Len(output, 5) + testutil.AssertLen(t, output, 5) // test that it handles newlines and long lines. output = Text.WrapFitWord(r, "this\nis\na\ntest\nstring that is very long", 100, basicTextStyle) - assert.Len(output, 8) + testutil.AssertLen(t, output, 8) } func TestTextWrapRune(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper r, err := PNG(1024, 1024) - assert.Nil(err) + testutil.AssertNil(t, err) f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) basicTextStyle := Style{Font: f, FontSize: 24} output := Text.WrapFitRune(r, "this is a test string", 150, basicTextStyle) - assert.NotEmpty(output) - assert.Len(output, 2) - assert.Equal("this is a t", output[0]) - assert.Equal("est string", output[1]) + testutil.AssertNotEmpty(t, output) + testutil.AssertLen(t, output, 2) + testutil.AssertEqual(t, "this is a t", output[0]) + testutil.AssertEqual(t, "est string", output[1]) } diff --git a/tick_test.go b/tick_test.go index 9802150..9ea0ef2 100644 --- a/tick_test.go +++ b/tick_test.go @@ -3,17 +3,17 @@ package chart import ( "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestGenerateContinuousTicks(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) r, err := PNG(1024, 1024) - assert.Nil(err) + testutil.AssertNil(t, err) r.SetFont(f) ra := &ContinuousRange{ @@ -25,20 +25,20 @@ func TestGenerateContinuousTicks(t *testing.T) { vf := FloatValueFormatter ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf) - assert.NotEmpty(ticks) - assert.Len(ticks, 11) - assert.Equal(0.0, ticks[0].Value) - assert.Equal(10, ticks[len(ticks)-1].Value) + testutil.AssertNotEmpty(t, ticks) + testutil.AssertLen(t, ticks, 11) + testutil.AssertEqual(t, 0.0, ticks[0].Value) + testutil.AssertEqual(t, 10, ticks[len(ticks)-1].Value) } func TestGenerateContinuousTicksDescending(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) r, err := PNG(1024, 1024) - assert.Nil(err) + testutil.AssertNil(t, err) r.SetFont(f) ra := &ContinuousRange{ @@ -51,10 +51,10 @@ func TestGenerateContinuousTicksDescending(t *testing.T) { vf := FloatValueFormatter ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf) - assert.NotEmpty(ticks) - assert.Len(ticks, 11) - assert.Equal(10.0, ticks[0].Value) - assert.Equal(9.0, ticks[1].Value) - assert.Equal(1.0, ticks[len(ticks)-2].Value) - assert.Equal(0.0, ticks[len(ticks)-1].Value) + testutil.AssertNotEmpty(t, ticks) + testutil.AssertLen(t, ticks, 11) + testutil.AssertEqual(t, 10.0, ticks[0].Value) + testutil.AssertEqual(t, 9.0, ticks[1].Value) + testutil.AssertEqual(t, 1.0, ticks[len(ticks)-2].Value) + testutil.AssertEqual(t, 0.0, ticks[len(ticks)-1].Value) } diff --git a/time_series_test.go b/time_series_test.go index 55cec72..3f65eaf 100644 --- a/time_series_test.go +++ b/time_series_test.go @@ -4,11 +4,11 @@ import ( "testing" "time" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestTimeSeriesGetValue(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper ts := TimeSeries{ Name: "Test", @@ -25,12 +25,12 @@ func TestTimeSeriesGetValue(t *testing.T) { } x0, y0 := ts.GetValues(0) - assert.NotZero(x0) - assert.Equal(1.0, y0) + testutil.AssertNotZero(t, x0) + testutil.AssertEqual(t, 1.0, y0) } func TestTimeSeriesValidate(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper cs := TimeSeries{ Name: "Test Series", @@ -45,7 +45,7 @@ func TestTimeSeriesValidate(t *testing.T) { 1.0, 2.0, 3.0, 4.0, 5.0, }, } - assert.Nil(cs.Validate()) + testutil.AssertNil(t, cs.Validate()) cs = TimeSeries{ Name: "Test Series", @@ -57,7 +57,7 @@ func TestTimeSeriesValidate(t *testing.T) { time.Now().AddDate(0, 0, -1), }, } - assert.NotNil(cs.Validate()) + testutil.AssertNotNil(t, cs.Validate()) cs = TimeSeries{ Name: "Test Series", @@ -65,5 +65,5 @@ func TestTimeSeriesValidate(t *testing.T) { 1.0, 2.0, 3.0, 4.0, 5.0, }, } - assert.NotNil(cs.Validate()) + testutil.AssertNotNil(t, cs.Validate()) } diff --git a/value_buffer_test.go b/value_buffer_test.go index e701eb4..e8aa9a0 100644 --- a/value_buffer_test.go +++ b/value_buffer_test.go @@ -3,105 +3,105 @@ package chart import ( "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestBuffer(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper buffer := NewValueBuffer() buffer.Enqueue(1) - assert.Equal(1, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(1, buffer.PeekBack()) + testutil.AssertEqual(t, 1, buffer.Len()) + testutil.AssertEqual(t, 1, buffer.Peek()) + testutil.AssertEqual(t, 1, buffer.PeekBack()) buffer.Enqueue(2) - assert.Equal(2, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(2, buffer.PeekBack()) + testutil.AssertEqual(t, 2, buffer.Len()) + testutil.AssertEqual(t, 1, buffer.Peek()) + testutil.AssertEqual(t, 2, buffer.PeekBack()) buffer.Enqueue(3) - assert.Equal(3, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(3, buffer.PeekBack()) + testutil.AssertEqual(t, 3, buffer.Len()) + testutil.AssertEqual(t, 1, buffer.Peek()) + testutil.AssertEqual(t, 3, buffer.PeekBack()) buffer.Enqueue(4) - assert.Equal(4, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(4, buffer.PeekBack()) + testutil.AssertEqual(t, 4, buffer.Len()) + testutil.AssertEqual(t, 1, buffer.Peek()) + testutil.AssertEqual(t, 4, buffer.PeekBack()) buffer.Enqueue(5) - assert.Equal(5, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(5, buffer.PeekBack()) + testutil.AssertEqual(t, 5, buffer.Len()) + testutil.AssertEqual(t, 1, buffer.Peek()) + testutil.AssertEqual(t, 5, buffer.PeekBack()) buffer.Enqueue(6) - assert.Equal(6, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(6, buffer.PeekBack()) + testutil.AssertEqual(t, 6, buffer.Len()) + testutil.AssertEqual(t, 1, buffer.Peek()) + testutil.AssertEqual(t, 6, buffer.PeekBack()) buffer.Enqueue(7) - assert.Equal(7, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(7, buffer.PeekBack()) + testutil.AssertEqual(t, 7, buffer.Len()) + testutil.AssertEqual(t, 1, buffer.Peek()) + testutil.AssertEqual(t, 7, buffer.PeekBack()) buffer.Enqueue(8) - assert.Equal(8, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) + testutil.AssertEqual(t, 8, buffer.Len()) + testutil.AssertEqual(t, 1, buffer.Peek()) + testutil.AssertEqual(t, 8, buffer.PeekBack()) value := buffer.Dequeue() - assert.Equal(1, value) - assert.Equal(7, buffer.Len()) - assert.Equal(2, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) + testutil.AssertEqual(t, 1, value) + testutil.AssertEqual(t, 7, buffer.Len()) + testutil.AssertEqual(t, 2, buffer.Peek()) + testutil.AssertEqual(t, 8, buffer.PeekBack()) value = buffer.Dequeue() - assert.Equal(2, value) - assert.Equal(6, buffer.Len()) - assert.Equal(3, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) + testutil.AssertEqual(t, 2, value) + testutil.AssertEqual(t, 6, buffer.Len()) + testutil.AssertEqual(t, 3, buffer.Peek()) + testutil.AssertEqual(t, 8, buffer.PeekBack()) value = buffer.Dequeue() - assert.Equal(3, value) - assert.Equal(5, buffer.Len()) - assert.Equal(4, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) + testutil.AssertEqual(t, 3, value) + testutil.AssertEqual(t, 5, buffer.Len()) + testutil.AssertEqual(t, 4, buffer.Peek()) + testutil.AssertEqual(t, 8, buffer.PeekBack()) value = buffer.Dequeue() - assert.Equal(4, value) - assert.Equal(4, buffer.Len()) - assert.Equal(5, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) + testutil.AssertEqual(t, 4, value) + testutil.AssertEqual(t, 4, buffer.Len()) + testutil.AssertEqual(t, 5, buffer.Peek()) + testutil.AssertEqual(t, 8, buffer.PeekBack()) value = buffer.Dequeue() - assert.Equal(5, value) - assert.Equal(3, buffer.Len()) - assert.Equal(6, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) + testutil.AssertEqual(t, 5, value) + testutil.AssertEqual(t, 3, buffer.Len()) + testutil.AssertEqual(t, 6, buffer.Peek()) + testutil.AssertEqual(t, 8, buffer.PeekBack()) value = buffer.Dequeue() - assert.Equal(6, value) - assert.Equal(2, buffer.Len()) - assert.Equal(7, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) + testutil.AssertEqual(t, 6, value) + testutil.AssertEqual(t, 2, buffer.Len()) + testutil.AssertEqual(t, 7, buffer.Peek()) + testutil.AssertEqual(t, 8, buffer.PeekBack()) value = buffer.Dequeue() - assert.Equal(7, value) - assert.Equal(1, buffer.Len()) - assert.Equal(8, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) + testutil.AssertEqual(t, 7, value) + testutil.AssertEqual(t, 1, buffer.Len()) + testutil.AssertEqual(t, 8, buffer.Peek()) + testutil.AssertEqual(t, 8, buffer.PeekBack()) value = buffer.Dequeue() - assert.Equal(8, value) - assert.Equal(0, buffer.Len()) - assert.Zero(buffer.Peek()) - assert.Zero(buffer.PeekBack()) + testutil.AssertEqual(t, 8, value) + testutil.AssertEqual(t, 0, buffer.Len()) + testutil.AssertZero(t, buffer.Peek()) + testutil.AssertZero(t, buffer.PeekBack()) } func TestBufferClear(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper buffer := NewValueBuffer() buffer.Enqueue(1) @@ -113,16 +113,16 @@ func TestBufferClear(t *testing.T) { buffer.Enqueue(1) buffer.Enqueue(1) - assert.Equal(8, buffer.Len()) + testutil.AssertEqual(t, 8, buffer.Len()) buffer.Clear() - assert.Equal(0, buffer.Len()) - assert.Zero(buffer.Peek()) - assert.Zero(buffer.PeekBack()) + testutil.AssertEqual(t, 0, buffer.Len()) + testutil.AssertZero(t, buffer.Peek()) + testutil.AssertZero(t, buffer.PeekBack()) } func TestBufferArray(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper buffer := NewValueBuffer() buffer.Enqueue(1) @@ -132,16 +132,16 @@ func TestBufferArray(t *testing.T) { buffer.Enqueue(5) contents := buffer.Array() - assert.Len(contents, 5) - assert.Equal(1, contents[0]) - assert.Equal(2, contents[1]) - assert.Equal(3, contents[2]) - assert.Equal(4, contents[3]) - assert.Equal(5, contents[4]) + testutil.AssertLen(t, contents, 5) + testutil.AssertEqual(t, 1, contents[0]) + testutil.AssertEqual(t, 2, contents[1]) + testutil.AssertEqual(t, 3, contents[2]) + testutil.AssertEqual(t, 4, contents[3]) + testutil.AssertEqual(t, 5, contents[4]) } func TestBufferEach(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper buffer := NewValueBuffer() @@ -156,37 +156,37 @@ func TestBufferEach(t *testing.T) { } }) - assert.Equal(16, called) + testutil.AssertEqual(t, 16, called) } func TestNewBuffer(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper empty := NewValueBuffer() - assert.NotNil(empty) - assert.Zero(empty.Len()) - assert.Equal(bufferDefaultCapacity, empty.Capacity()) - assert.Zero(empty.Peek()) - assert.Zero(empty.PeekBack()) + testutil.AssertNotNil(t, empty) + testutil.AssertZero(t, empty.Len()) + testutil.AssertEqual(t, bufferDefaultCapacity, empty.Capacity()) + testutil.AssertZero(t, empty.Peek()) + testutil.AssertZero(t, empty.PeekBack()) } func TestNewBufferWithValues(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := NewValueBuffer(1, 2, 3, 4, 5) - assert.NotNil(values) - assert.Equal(5, values.Len()) - assert.Equal(1, values.Peek()) - assert.Equal(5, values.PeekBack()) + testutil.AssertNotNil(t, values) + testutil.AssertEqual(t, 5, values.Len()) + testutil.AssertEqual(t, 1, values.Peek()) + testutil.AssertEqual(t, 5, values.PeekBack()) } func TestBufferGrowth(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper values := NewValueBuffer(1, 2, 3, 4, 5) for i := 0; i < 1<<10; i++ { values.Enqueue(float64(i)) } - assert.Equal(1<<10-1, values.PeekBack()) + testutil.AssertEqual(t, 1<<10-1, values.PeekBack()) } diff --git a/value_formatter_test.go b/value_formatter_test.go index 623a399..d9ffaef 100644 --- a/value_formatter_test.go +++ b/value_formatter_test.go @@ -4,11 +4,11 @@ import ( "testing" "time" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestTimeValueFormatterWithFormat(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper d := time.Now() di := TimeToFloat64(d) @@ -17,42 +17,42 @@ func TestTimeValueFormatterWithFormat(t *testing.T) { s := formatTime(d, DefaultDateFormat) si := formatTime(di, DefaultDateFormat) sf := formatTime(df, DefaultDateFormat) - assert.Equal(s, si) - assert.Equal(s, sf) + testutil.AssertEqual(t, s, si) + testutil.AssertEqual(t, s, sf) sd := TimeValueFormatter(d) sdi := TimeValueFormatter(di) sdf := TimeValueFormatter(df) - assert.Equal(s, sd) - assert.Equal(s, sdi) - assert.Equal(s, sdf) + testutil.AssertEqual(t, s, sd) + testutil.AssertEqual(t, s, sdi) + testutil.AssertEqual(t, s, sdf) } func TestFloatValueFormatter(t *testing.T) { - assert := assert.New(t) - assert.Equal("1234.00", FloatValueFormatter(1234.00)) + // replaced new assertions helper + testutil.AssertEqual(t, "1234.00", FloatValueFormatter(1234.00)) } func TestFloatValueFormatterWithFloat32Input(t *testing.T) { - assert := assert.New(t) - assert.Equal("1234.00", FloatValueFormatter(float32(1234.00))) + // replaced new assertions helper + testutil.AssertEqual(t, "1234.00", FloatValueFormatter(float32(1234.00))) } func TestFloatValueFormatterWithIntegerInput(t *testing.T) { - assert := assert.New(t) - assert.Equal("1234.00", FloatValueFormatter(1234)) + // replaced new assertions helper + testutil.AssertEqual(t, "1234.00", FloatValueFormatter(1234)) } func TestFloatValueFormatterWithInt64Input(t *testing.T) { - assert := assert.New(t) - assert.Equal("1234.00", FloatValueFormatter(int64(1234))) + // replaced new assertions helper + testutil.AssertEqual(t, "1234.00", FloatValueFormatter(int64(1234))) } func TestFloatValueFormatterWithFormat(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper v := 123.456 sv := FloatValueFormatterWithFormat(v, "%.3f") - assert.Equal("123.456", sv) - assert.Equal("123.000", FloatValueFormatterWithFormat(123, "%.3f")) + testutil.AssertEqual(t, "123.456", sv) + testutil.AssertEqual(t, "123.000", FloatValueFormatterWithFormat(123, "%.3f")) } diff --git a/value_provider.go b/value_provider.go index e3a1a02..be985eb 100644 --- a/value_provider.go +++ b/value_provider.go @@ -1,6 +1,6 @@ package chart -import "github.com/wcharczuk/go-chart/drawing" +import "github.com/wcharczuk/go-chart/v2/drawing" // ValuesProvider is a type that produces values. type ValuesProvider interface { diff --git a/value_test.go b/value_test.go index ed7a96f..1c12ce7 100644 --- a/value_test.go +++ b/value_test.go @@ -3,11 +3,11 @@ package chart import ( "testing" - assert "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestValuesValues(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper vs := []Value{ {Value: 10, Label: "Blue"}, @@ -20,18 +20,18 @@ func TestValuesValues(t *testing.T) { } values := Values(vs).Values() - assert.Len(values, 7) - assert.Equal(10, values[0]) - assert.Equal(9, values[1]) - assert.Equal(8, values[2]) - assert.Equal(7, values[3]) - assert.Equal(6, values[4]) - assert.Equal(5, values[5]) - assert.Equal(2, values[6]) + testutil.AssertLen(t, values, 7) + testutil.AssertEqual(t, 10, values[0]) + testutil.AssertEqual(t, 9, values[1]) + testutil.AssertEqual(t, 8, values[2]) + testutil.AssertEqual(t, 7, values[3]) + testutil.AssertEqual(t, 6, values[4]) + testutil.AssertEqual(t, 5, values[5]) + testutil.AssertEqual(t, 2, values[6]) } func TestValuesValuesNormalized(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper vs := []Value{ {Value: 10, Label: "Blue"}, @@ -44,13 +44,13 @@ func TestValuesValuesNormalized(t *testing.T) { } values := Values(vs).ValuesNormalized() - assert.Len(values, 7) - assert.Equal(0.2127, values[0]) - assert.Equal(0.0425, values[6]) + testutil.AssertLen(t, values, 7) + testutil.AssertEqual(t, 0.2127, values[0]) + testutil.AssertEqual(t, 0.0425, values[6]) } func TestValuesNormalize(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper vs := []Value{ {Value: 10, Label: "Blue"}, @@ -63,7 +63,7 @@ func TestValuesNormalize(t *testing.T) { } values := Values(vs).Normalize() - assert.Len(values, 7) - assert.Equal(0.2127, values[0].Value) - assert.Equal(0.0425, values[6].Value) + testutil.AssertLen(t, values, 7) + testutil.AssertEqual(t, 0.2127, values[0].Value) + testutil.AssertEqual(t, 0.0425, values[6].Value) } diff --git a/vector_renderer.go b/vector_renderer.go index c9ba458..eb2fc83 100644 --- a/vector_renderer.go +++ b/vector_renderer.go @@ -10,7 +10,7 @@ import ( "golang.org/x/image/font" "github.com/golang/freetype/truetype" - "github.com/wcharczuk/go-chart/drawing" + "github.com/wcharczuk/go-chart/v2/drawing" ) // SVG returns a new png/raster renderer. diff --git a/vector_renderer_test.go b/vector_renderer_test.go index d937d2d..019c6b9 100644 --- a/vector_renderer_test.go +++ b/vector_renderer_test.go @@ -6,18 +6,18 @@ import ( "strings" "testing" - "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 TestVectorRendererPath(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper vr, err := SVG(100, 100) - assert.Nil(err) + testutil.AssertNil(t, err) typed, isTyped := vr.(*vectorRenderer) - assert.True(isTyped) + testutil.AssertTrue(t, isTyped) typed.MoveTo(0, 0) typed.LineTo(100, 100) @@ -27,37 +27,37 @@ func TestVectorRendererPath(t *testing.T) { buffer := bytes.NewBuffer([]byte{}) err = typed.Save(buffer) - assert.Nil(err) + testutil.AssertNil(t, err) raw := string(buffer.Bytes()) - assert.True(strings.HasPrefix(raw, "")) + testutil.AssertTrue(t, strings.HasPrefix(raw, "")) } func TestVectorRendererMeasureText(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) vr, err := SVG(100, 100) - assert.Nil(err) + testutil.AssertNil(t, err) vr.SetDPI(DefaultDPI) vr.SetFont(f) vr.SetFontSize(12.0) tb := vr.MeasureText("Ljp") - assert.Equal(21, tb.Width()) - assert.Equal(15, tb.Height()) + testutil.AssertEqual(t, 21, tb.Width()) + testutil.AssertEqual(t, 15, tb.Height()) } func TestCanvasStyleSVG(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) set := Style{ StrokeColor: drawing.ColorWhite, @@ -71,37 +71,35 @@ func TestCanvasStyleSVG(t *testing.T) { canvas := &canvas{dpi: DefaultDPI} svgString := canvas.styleAsSVG(set) - assert.NotEmpty(svgString) - assert.True(strings.HasPrefix(svgString, "style=\"")) - assert.True(strings.Contains(svgString, "stroke:rgba(255,255,255,1.0)")) - assert.True(strings.Contains(svgString, "stroke-width:5")) - assert.True(strings.Contains(svgString, "fill:rgba(255,255,255,1.0)")) - assert.True(strings.HasSuffix(svgString, "\"")) + testutil.AssertNotEmpty(t, svgString) + testutil.AssertTrue(t, strings.HasPrefix(svgString, "style=\"")) + testutil.AssertTrue(t, strings.Contains(svgString, "stroke:rgba(255,255,255,1.0)")) + testutil.AssertTrue(t, strings.Contains(svgString, "stroke-width:5")) + testutil.AssertTrue(t, strings.Contains(svgString, "fill:rgba(255,255,255,1.0)")) + testutil.AssertTrue(t, strings.HasSuffix(svgString, "\"")) } func TestCanvasClassSVG(t *testing.T) { - as := assert.New(t) - set := Style{ ClassName: "test-class", } canvas := &canvas{dpi: DefaultDPI} - as.Equal("class=\"test-class\"", canvas.styleAsSVG(set)) + testutil.AssertEqual(t, "class=\"test-class\"", canvas.styleAsSVG(set)) } func TestCanvasCustomInlineStylesheet(t *testing.T) { b := strings.Builder{} canvas := &canvas{ - w: &b, - css: ".background { fill: red }", + w: &b, + css: ".background { fill: red }", } canvas.Start(200, 200) - assert.New(t).Contains(b.String(), fmt.Sprintf(``, canvas.css)) + testutil.AssertContains(t, b.String(), fmt.Sprintf(``, canvas.css)) } func TestCanvasCustomInlineStylesheetWithNonce(t *testing.T) { @@ -115,5 +113,5 @@ func TestCanvasCustomInlineStylesheetWithNonce(t *testing.T) { canvas.Start(200, 200) - assert.New(t).Contains(b.String(), fmt.Sprintf(``, canvas.nonce, canvas.css)) -} \ No newline at end of file + testutil.AssertContains(t, b.String(), fmt.Sprintf(``, canvas.nonce, canvas.css)) +} diff --git a/viridis.go b/viridis.go index e801537..4234319 100644 --- a/viridis.go +++ b/viridis.go @@ -1,6 +1,6 @@ package chart -import "github.com/wcharczuk/go-chart/drawing" +import "github.com/wcharczuk/go-chart/v2/drawing" var viridisColors = [256]drawing.Color{ drawing.Color{R: 0x44, G: 0x1, B: 0x54, A: 0xff}, diff --git a/xaxis_test.go b/xaxis_test.go index 516be73..6d05d53 100644 --- a/xaxis_test.go +++ b/xaxis_test.go @@ -3,17 +3,17 @@ package chart import ( "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestXAxisGetTicks(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper r, err := PNG(1024, 1024) - assert.Nil(err) + testutil.AssertNil(t, err) f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) xa := XAxis{} xr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024} @@ -23,17 +23,17 @@ func TestXAxisGetTicks(t *testing.T) { } vf := FloatValueFormatter ticks := xa.GetTicks(r, xr, styleDefaults, vf) - assert.Len(ticks, 16) + testutil.AssertLen(t, ticks, 16) } func TestXAxisGetTicksWithUserDefaults(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper r, err := PNG(1024, 1024) - assert.Nil(err) + testutil.AssertNil(t, err) f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) xa := XAxis{ Ticks: []Tick{{Value: 1.0, Label: "1.0"}}, @@ -45,23 +45,23 @@ func TestXAxisGetTicksWithUserDefaults(t *testing.T) { } vf := FloatValueFormatter ticks := xa.GetTicks(r, xr, styleDefaults, vf) - assert.Len(ticks, 1) + testutil.AssertLen(t, ticks, 1) } func TestXAxisMeasure(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) style := Style{ Font: f, FontSize: 10.0, } r, err := PNG(100, 100) - assert.Nil(err) + testutil.AssertNil(t, err) ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}} xa := XAxis{} xab := xa.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks) - assert.Equal(122, xab.Width()) - assert.Equal(21, xab.Height()) + testutil.AssertEqual(t, 122, xab.Width()) + testutil.AssertEqual(t, 21, xab.Height()) } diff --git a/yaxis_test.go b/yaxis_test.go index 9b903ba..754f4e0 100644 --- a/yaxis_test.go +++ b/yaxis_test.go @@ -3,17 +3,17 @@ package chart import ( "testing" - "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestYAxisGetTicks(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper r, err := PNG(1024, 1024) - assert.Nil(err) + testutil.AssertNil(t, err) f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) ya := YAxis{} yr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024} @@ -23,17 +23,17 @@ func TestYAxisGetTicks(t *testing.T) { } vf := FloatValueFormatter ticks := ya.GetTicks(r, yr, styleDefaults, vf) - assert.Len(ticks, 32) + testutil.AssertLen(t, ticks, 32) } func TestYAxisGetTicksWithUserDefaults(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper r, err := PNG(1024, 1024) - assert.Nil(err) + testutil.AssertNil(t, err) f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) ya := YAxis{ Ticks: []Tick{{Value: 1.0, Label: "1.0"}}, @@ -45,41 +45,41 @@ func TestYAxisGetTicksWithUserDefaults(t *testing.T) { } vf := FloatValueFormatter ticks := ya.GetTicks(r, yr, styleDefaults, vf) - assert.Len(ticks, 1) + testutil.AssertLen(t, ticks, 1) } func TestYAxisMeasure(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) style := Style{ Font: f, FontSize: 10.0, } r, err := PNG(100, 100) - assert.Nil(err) + testutil.AssertNil(t, err) ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}} ya := YAxis{} yab := ya.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks) - assert.Equal(32, yab.Width()) - assert.Equal(110, yab.Height()) + testutil.AssertEqual(t, 32, yab.Width()) + testutil.AssertEqual(t, 110, yab.Height()) } func TestYAxisSecondaryMeasure(t *testing.T) { - assert := assert.New(t) + // replaced new assertions helper f, err := GetDefaultFont() - assert.Nil(err) + testutil.AssertNil(t, err) style := Style{ Font: f, FontSize: 10.0, } r, err := PNG(100, 100) - assert.Nil(err) + testutil.AssertNil(t, err) ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}} ya := YAxis{AxisType: YAxisSecondary} yab := ya.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks) - assert.Equal(32, yab.Width()) - assert.Equal(110, yab.Height()) + testutil.AssertEqual(t, 32, yab.Width()) + testutil.AssertEqual(t, 110, yab.Height()) }