Adds support for go mod
(finally) (#164)
This commit is contained in:
parent
962b9abdec
commit
c1468e8ae4
89 changed files with 1162 additions and 965 deletions
|
@ -3,15 +3,12 @@ jobs:
|
||||||
build:
|
build:
|
||||||
working_directory: /go/src/github.com/wcharczuk/go-chart
|
working_directory: /go/src/github.com/wcharczuk/go-chart
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/golang:1.11
|
- image: circleci/golang:1.15
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- run:
|
- run:
|
||||||
name: new-install
|
name: new-install
|
||||||
command: make new-install
|
command: make new-install
|
||||||
- run:
|
- run:
|
||||||
name: ci
|
name: Continuous Integration
|
||||||
command: make ci
|
command: make
|
||||||
- store_artifacts:
|
|
||||||
path: coverage.html
|
|
||||||
destination: coverage.html
|
|
13
Makefile
13
Makefile
|
@ -1,21 +1,10 @@
|
||||||
all: test
|
all: new-install test
|
||||||
|
|
||||||
ci: profanity coverage
|
|
||||||
|
|
||||||
new-install:
|
new-install:
|
||||||
@go get -v -u ./...
|
@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:
|
generate:
|
||||||
@go generate ./...
|
@go generate ./...
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@go test ./...
|
@go test ./...
|
||||||
|
|
||||||
.PHONY: profanity
|
|
||||||
profanity:
|
|
||||||
@profanity
|
|
||||||
|
|
||||||
coverage:
|
|
||||||
@coverage
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -3,8 +3,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -4,13 +4,12 @@ import (
|
||||||
"image/color"
|
"image/color"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAnnotationSeriesMeasure(t *testing.T) {
|
func TestAnnotationSeriesMeasure(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
as := AnnotationSeries{
|
as := AnnotationSeries{
|
||||||
Annotations: []Value2{
|
Annotations: []Value2{
|
||||||
|
@ -22,10 +21,10 @@ func TestAnnotationSeriesMeasure(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := PNG(110, 110)
|
r, err := PNG(110, 110)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
xrange := &ContinuousRange{
|
xrange := &ContinuousRange{
|
||||||
Min: 1.0,
|
Min: 1.0,
|
||||||
|
@ -50,15 +49,15 @@ func TestAnnotationSeriesMeasure(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
box := as.Measure(r, cb, xrange, yrange, sd)
|
box := as.Measure(r, cb, xrange, yrange, sd)
|
||||||
assert.False(box.IsZero())
|
testutil.AssertFalse(t, box.IsZero())
|
||||||
assert.Equal(-5.0, box.Top)
|
testutil.AssertEqual(t, -5.0, box.Top)
|
||||||
assert.Equal(5.0, box.Left)
|
testutil.AssertEqual(t, 5.0, box.Left)
|
||||||
assert.Equal(146.0, box.Right) //the top,left annotation sticks up 5px and out ~44px.
|
testutil.AssertEqual(t, 146.0, box.Right) //the top,left annotation sticks up 5px and out ~44px.
|
||||||
assert.Equal(115.0, box.Bottom)
|
testutil.AssertEqual(t, 115.0, box.Bottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAnnotationSeriesRender(t *testing.T) {
|
func TestAnnotationSeriesRender(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
as := AnnotationSeries{
|
as := AnnotationSeries{
|
||||||
Style: Style{
|
Style: Style{
|
||||||
|
@ -74,10 +73,10 @@ func TestAnnotationSeriesRender(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := PNG(110, 110)
|
r, err := PNG(110, 110)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
xrange := &ContinuousRange{
|
xrange := &ContinuousRange{
|
||||||
Min: 1.0,
|
Min: 1.0,
|
||||||
|
@ -104,13 +103,13 @@ func TestAnnotationSeriesRender(t *testing.T) {
|
||||||
as.Render(r, cb, xrange, yrange, sd)
|
as.Render(r, cb, xrange, yrange, sd)
|
||||||
|
|
||||||
rr, isRaster := r.(*rasterRenderer)
|
rr, isRaster := r.(*rasterRenderer)
|
||||||
assert.True(isRaster)
|
testutil.AssertTrue(t, isRaster)
|
||||||
assert.NotNil(rr)
|
testutil.AssertNotNil(t, rr)
|
||||||
|
|
||||||
c := rr.i.At(38, 70)
|
c := rr.i.At(38, 70)
|
||||||
converted, isRGBA := color.RGBAModel.Convert(c).(color.RGBA)
|
converted, isRGBA := color.RGBAModel.Convert(c).(color.RGBA)
|
||||||
assert.True(isRGBA)
|
testutil.AssertTrue(t, isRGBA)
|
||||||
assert.Equal(0, converted.R)
|
testutil.AssertEqual(t, 0, converted.R)
|
||||||
assert.Equal(0, converted.G)
|
testutil.AssertEqual(t, 0, converted.G)
|
||||||
assert.Equal(0, converted.B)
|
testutil.AssertEqual(t, 0, converted.B)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBarChartRender(t *testing.T) {
|
func TestBarChartRender(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{
|
bc := BarChart{
|
||||||
Width: 1024,
|
Width: 1024,
|
||||||
|
@ -25,12 +25,12 @@ func TestBarChartRender(t *testing.T) {
|
||||||
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
err := bc.Render(PNG, buf)
|
err := bc.Render(PNG, buf)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
assert.NotZero(buf.Len())
|
testutil.AssertNotZero(t, buf.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartRenderZero(t *testing.T) {
|
func TestBarChartRenderZero(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{
|
bc := BarChart{
|
||||||
Width: 1024,
|
Width: 1024,
|
||||||
|
@ -43,64 +43,64 @@ func TestBarChartRenderZero(t *testing.T) {
|
||||||
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
err := bc.Render(PNG, buf)
|
err := bc.Render(PNG, buf)
|
||||||
assert.NotNil(err)
|
testutil.AssertNotNil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartProps(t *testing.T) {
|
func TestBarChartProps(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{}
|
bc := BarChart{}
|
||||||
|
|
||||||
assert.Equal(DefaultDPI, bc.GetDPI())
|
testutil.AssertEqual(t, DefaultDPI, bc.GetDPI())
|
||||||
bc.DPI = 100
|
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()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
bc.Font = f
|
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
|
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
|
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
|
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
|
bc.BarWidth = 75
|
||||||
assert.Equal(75, bc.GetBarWidth())
|
testutil.AssertEqual(t, 75, bc.GetBarWidth())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartRenderNoBars(t *testing.T) {
|
func TestBarChartRenderNoBars(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{}
|
bc := BarChart{}
|
||||||
err := bc.Render(PNG, bytes.NewBuffer([]byte{}))
|
err := bc.Render(PNG, bytes.NewBuffer([]byte{}))
|
||||||
assert.NotNil(err)
|
testutil.AssertNotNil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartGetRanges(t *testing.T) {
|
func TestBarChartGetRanges(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{}
|
bc := BarChart{}
|
||||||
|
|
||||||
yr := bc.getRanges()
|
yr := bc.getRanges()
|
||||||
assert.NotNil(yr)
|
testutil.AssertNotNil(t, yr)
|
||||||
assert.False(yr.IsZero())
|
testutil.AssertFalse(t, yr.IsZero())
|
||||||
|
|
||||||
assert.Equal(-math.MaxFloat64, yr.GetMax())
|
testutil.AssertEqual(t, -math.MaxFloat64, yr.GetMax())
|
||||||
assert.Equal(math.MaxFloat64, yr.GetMin())
|
testutil.AssertEqual(t, math.MaxFloat64, yr.GetMin())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartGetRangesBarsMinMax(t *testing.T) {
|
func TestBarChartGetRangesBarsMinMax(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{
|
bc := BarChart{
|
||||||
Bars: []Value{
|
Bars: []Value{
|
||||||
|
@ -110,15 +110,15 @@ func TestBarChartGetRangesBarsMinMax(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
yr := bc.getRanges()
|
yr := bc.getRanges()
|
||||||
assert.NotNil(yr)
|
testutil.AssertNotNil(t, yr)
|
||||||
assert.False(yr.IsZero())
|
testutil.AssertFalse(t, yr.IsZero())
|
||||||
|
|
||||||
assert.Equal(10, yr.GetMax())
|
testutil.AssertEqual(t, 10, yr.GetMax())
|
||||||
assert.Equal(1, yr.GetMin())
|
testutil.AssertEqual(t, 1, yr.GetMin())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartGetRangesMinMax(t *testing.T) {
|
func TestBarChartGetRangesMinMax(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{
|
bc := BarChart{
|
||||||
YAxis: YAxis{
|
YAxis: YAxis{
|
||||||
|
@ -138,15 +138,15 @@ func TestBarChartGetRangesMinMax(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
yr := bc.getRanges()
|
yr := bc.getRanges()
|
||||||
assert.NotNil(yr)
|
testutil.AssertNotNil(t, yr)
|
||||||
assert.False(yr.IsZero())
|
testutil.AssertFalse(t, yr.IsZero())
|
||||||
|
|
||||||
assert.Equal(15, yr.GetMax())
|
testutil.AssertEqual(t, 15, yr.GetMax())
|
||||||
assert.Equal(5, yr.GetMin())
|
testutil.AssertEqual(t, 5, yr.GetMin())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartGetRangesTicksMinMax(t *testing.T) {
|
func TestBarChartGetRangesTicksMinMax(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{
|
bc := BarChart{
|
||||||
YAxis: YAxis{
|
YAxis: YAxis{
|
||||||
|
@ -162,56 +162,56 @@ func TestBarChartGetRangesTicksMinMax(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
yr := bc.getRanges()
|
yr := bc.getRanges()
|
||||||
assert.NotNil(yr)
|
testutil.AssertNotNil(t, yr)
|
||||||
assert.False(yr.IsZero())
|
testutil.AssertFalse(t, yr.IsZero())
|
||||||
|
|
||||||
assert.Equal(11, yr.GetMax())
|
testutil.AssertEqual(t, 11, yr.GetMax())
|
||||||
assert.Equal(7, yr.GetMin())
|
testutil.AssertEqual(t, 7, yr.GetMin())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartHasAxes(t *testing.T) {
|
func TestBarChartHasAxes(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{}
|
bc := BarChart{}
|
||||||
assert.True(bc.hasAxes())
|
testutil.AssertTrue(t, bc.hasAxes())
|
||||||
bc.YAxis = YAxis{
|
bc.YAxis = YAxis{
|
||||||
Style: Hidden(),
|
Style: Hidden(),
|
||||||
}
|
}
|
||||||
assert.False(bc.hasAxes())
|
testutil.AssertFalse(t, bc.hasAxes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartGetDefaultCanvasBox(t *testing.T) {
|
func TestBarChartGetDefaultCanvasBox(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{}
|
bc := BarChart{}
|
||||||
b := bc.getDefaultCanvasBox()
|
b := bc.getDefaultCanvasBox()
|
||||||
assert.False(b.IsZero())
|
testutil.AssertFalse(t, b.IsZero())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartSetRangeDomains(t *testing.T) {
|
func TestBarChartSetRangeDomains(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{}
|
bc := BarChart{}
|
||||||
cb := bc.box()
|
cb := bc.box()
|
||||||
yr := bc.getRanges()
|
yr := bc.getRanges()
|
||||||
yr2 := bc.setRangeDomains(cb, yr)
|
yr2 := bc.setRangeDomains(cb, yr)
|
||||||
assert.NotZero(yr2.GetDomain())
|
testutil.AssertNotZero(t, yr2.GetDomain())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartGetValueFormatters(t *testing.T) {
|
func TestBarChartGetValueFormatters(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{}
|
bc := BarChart{}
|
||||||
vf := bc.getValueFormatters()
|
vf := bc.getValueFormatters()
|
||||||
assert.NotNil(vf)
|
testutil.AssertNotNil(t, vf)
|
||||||
assert.Equal("1234.00", vf(1234.0))
|
testutil.AssertEqual(t, "1234.00", vf(1234.0))
|
||||||
|
|
||||||
bc.YAxis.ValueFormatter = func(_ interface{}) string { return "test" }
|
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) {
|
func TestBarChartGetAxesTicks(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{
|
bc := BarChart{
|
||||||
Bars: []Value{
|
Bars: []Value{
|
||||||
|
@ -222,21 +222,21 @@ func TestBarChartGetAxesTicks(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := PNG(128, 128)
|
r, err := PNG(128, 128)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
yr := bc.getRanges()
|
yr := bc.getRanges()
|
||||||
yf := bc.getValueFormatters()
|
yf := bc.getValueFormatters()
|
||||||
|
|
||||||
bc.YAxis.Style.Hidden = true
|
bc.YAxis.Style.Hidden = true
|
||||||
ticks := bc.getAxesTicks(r, yr, yf)
|
ticks := bc.getAxesTicks(r, yr, yf)
|
||||||
assert.Empty(ticks)
|
testutil.AssertEmpty(t, ticks)
|
||||||
|
|
||||||
bc.YAxis.Style.Hidden = false
|
bc.YAxis.Style.Hidden = false
|
||||||
ticks = bc.getAxesTicks(r, yr, yf)
|
ticks = bc.getAxesTicks(r, yr, yf)
|
||||||
assert.Len(ticks, 2)
|
testutil.AssertLen(t, ticks, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartCalculateEffectiveBarSpacing(t *testing.T) {
|
func TestBarChartCalculateEffectiveBarSpacing(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{
|
bc := BarChart{
|
||||||
Width: 1024,
|
Width: 1024,
|
||||||
|
@ -251,15 +251,15 @@ func TestBarChartCalculateEffectiveBarSpacing(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
spacing := bc.calculateEffectiveBarSpacing(bc.box())
|
spacing := bc.calculateEffectiveBarSpacing(bc.box())
|
||||||
assert.NotZero(spacing)
|
testutil.AssertNotZero(t, spacing)
|
||||||
|
|
||||||
bc.BarWidth = 250
|
bc.BarWidth = 250
|
||||||
spacing = bc.calculateEffectiveBarSpacing(bc.box())
|
spacing = bc.calculateEffectiveBarSpacing(bc.box())
|
||||||
assert.Zero(spacing)
|
testutil.AssertZero(t, spacing)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChartCalculateEffectiveBarWidth(t *testing.T) {
|
func TestBarChartCalculateEffectiveBarWidth(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BarChart{
|
bc := BarChart{
|
||||||
Width: 1024,
|
Width: 1024,
|
||||||
|
@ -276,35 +276,35 @@ func TestBarChartCalculateEffectiveBarWidth(t *testing.T) {
|
||||||
cb := bc.box()
|
cb := bc.box()
|
||||||
|
|
||||||
spacing := bc.calculateEffectiveBarSpacing(bc.box())
|
spacing := bc.calculateEffectiveBarSpacing(bc.box())
|
||||||
assert.NotZero(spacing)
|
testutil.AssertNotZero(t, spacing)
|
||||||
|
|
||||||
barWidth := bc.calculateEffectiveBarWidth(bc.box(), spacing)
|
barWidth := bc.calculateEffectiveBarWidth(bc.box(), spacing)
|
||||||
assert.Equal(10, barWidth)
|
testutil.AssertEqual(t, 10, barWidth)
|
||||||
|
|
||||||
bc.BarWidth = 250
|
bc.BarWidth = 250
|
||||||
spacing = bc.calculateEffectiveBarSpacing(bc.box())
|
spacing = bc.calculateEffectiveBarSpacing(bc.box())
|
||||||
assert.Zero(spacing)
|
testutil.AssertZero(t, spacing)
|
||||||
barWidth = bc.calculateEffectiveBarWidth(bc.box(), 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)
|
bw, bs, total := bc.calculateScaledTotalWidth(cb)
|
||||||
assert.Equal(spacing, bs)
|
testutil.AssertEqual(t, spacing, bs)
|
||||||
assert.Equal(barWidth, bw)
|
testutil.AssertEqual(t, barWidth, bw)
|
||||||
assert.Equal(cb.Width()+1, total)
|
testutil.AssertEqual(t, cb.Width()+1, total)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBarChatGetTitleFontSize(t *testing.T) {
|
func TestBarChatGetTitleFontSize(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
size := BarChart{Width: 2049, Height: 2049}.getTitleFontSize()
|
size := BarChart{Width: 2049, Height: 2049}.getTitleFontSize()
|
||||||
assert.Equal(48, size)
|
testutil.AssertEqual(t, 48, size)
|
||||||
size = BarChart{Width: 1025, Height: 1025}.getTitleFontSize()
|
size = BarChart{Width: 1025, Height: 1025}.getTitleFontSize()
|
||||||
assert.Equal(24, size)
|
testutil.AssertEqual(t, 24, size)
|
||||||
size = BarChart{Width: 513, Height: 513}.getTitleFontSize()
|
size = BarChart{Width: 513, Height: 513}.getTitleFontSize()
|
||||||
assert.Equal(18, size)
|
testutil.AssertEqual(t, 18, size)
|
||||||
size = BarChart{Width: 257, Height: 257}.getTitleFontSize()
|
size = BarChart{Width: 257, Height: 257}.getTitleFontSize()
|
||||||
assert.Equal(12, size)
|
testutil.AssertEqual(t, 12, size)
|
||||||
size = BarChart{Width: 128, Height: 128}.getTitleFontSize()
|
size = BarChart{Width: 128, Height: 128}.getTitleFontSize()
|
||||||
assert.Equal(10, size)
|
testutil.AssertEqual(t, 10, size)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBollingerBandSeries(t *testing.T) {
|
func TestBollingerBandSeries(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
s1 := mockValuesProvider{
|
s1 := mockValuesProvider{
|
||||||
X: LinearRange(1.0, 100.0),
|
X: LinearRange(1.0, 100.0),
|
||||||
|
@ -29,12 +29,12 @@ func TestBollingerBandSeries(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for x := bbs.GetPeriod(); x < 100; x++ {
|
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) {
|
func TestBollingerBandLastValue(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
s1 := mockValuesProvider{
|
s1 := mockValuesProvider{
|
||||||
X: LinearRange(1.0, 100.0),
|
X: LinearRange(1.0, 100.0),
|
||||||
|
@ -46,7 +46,7 @@ func TestBollingerBandLastValue(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
x, y1, y2 := bbs.GetBoundedLastValues()
|
x, y1, y2 := bbs.GetBoundedLastValues()
|
||||||
assert.Equal(100.0, x)
|
testutil.AssertEqual(t, 100.0, x)
|
||||||
assert.Equal(101, math.Floor(y1))
|
testutil.AssertEqual(t, 101, math.Floor(y1))
|
||||||
assert.Equal(83, math.Floor(y2))
|
testutil.AssertEqual(t, 83, math.Floor(y2))
|
||||||
}
|
}
|
||||||
|
|
134
box_test.go
134
box_test.go
|
@ -4,131 +4,131 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBoxClone(t *testing.T) {
|
func TestBoxClone(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
a := Box{Top: 5, Left: 5, Right: 15, Bottom: 15}
|
a := Box{Top: 5, Left: 5, Right: 15, Bottom: 15}
|
||||||
b := a.Clone()
|
b := a.Clone()
|
||||||
assert.True(a.Equals(b))
|
testutil.AssertTrue(t, a.Equals(b))
|
||||||
assert.True(b.Equals(a))
|
testutil.AssertTrue(t, b.Equals(a))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoxEquals(t *testing.T) {
|
func TestBoxEquals(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
a := Box{Top: 5, Left: 5, Right: 15, Bottom: 15}
|
a := Box{Top: 5, Left: 5, Right: 15, Bottom: 15}
|
||||||
b := Box{Top: 10, Left: 10, Right: 30, Bottom: 30}
|
b := Box{Top: 10, Left: 10, Right: 30, Bottom: 30}
|
||||||
c := Box{Top: 5, Left: 5, Right: 15, Bottom: 15}
|
c := Box{Top: 5, Left: 5, Right: 15, Bottom: 15}
|
||||||
assert.True(a.Equals(a))
|
testutil.AssertTrue(t, a.Equals(a))
|
||||||
assert.True(a.Equals(c))
|
testutil.AssertTrue(t, a.Equals(c))
|
||||||
assert.True(c.Equals(a))
|
testutil.AssertTrue(t, c.Equals(a))
|
||||||
assert.False(a.Equals(b))
|
testutil.AssertFalse(t, a.Equals(b))
|
||||||
assert.False(c.Equals(b))
|
testutil.AssertFalse(t, c.Equals(b))
|
||||||
assert.False(b.Equals(a))
|
testutil.AssertFalse(t, b.Equals(a))
|
||||||
assert.False(b.Equals(c))
|
testutil.AssertFalse(t, b.Equals(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoxIsBiggerThan(t *testing.T) {
|
func TestBoxIsBiggerThan(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
a := Box{Top: 5, Left: 5, Right: 25, Bottom: 25}
|
a := Box{Top: 5, Left: 5, Right: 25, Bottom: 25}
|
||||||
b := Box{Top: 10, Left: 10, Right: 20, Bottom: 20} // only half bigger
|
b := Box{Top: 10, Left: 10, Right: 20, Bottom: 20} // only half bigger
|
||||||
c := Box{Top: 1, Left: 1, Right: 30, Bottom: 30} //bigger
|
c := Box{Top: 1, Left: 1, Right: 30, Bottom: 30} //bigger
|
||||||
assert.True(a.IsBiggerThan(b))
|
testutil.AssertTrue(t, a.IsBiggerThan(b))
|
||||||
assert.False(a.IsBiggerThan(c))
|
testutil.AssertFalse(t, a.IsBiggerThan(c))
|
||||||
assert.True(c.IsBiggerThan(a))
|
testutil.AssertTrue(t, c.IsBiggerThan(a))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoxIsSmallerThan(t *testing.T) {
|
func TestBoxIsSmallerThan(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
a := Box{Top: 5, Left: 5, Right: 25, Bottom: 25}
|
a := Box{Top: 5, Left: 5, Right: 25, Bottom: 25}
|
||||||
b := Box{Top: 10, Left: 10, Right: 20, Bottom: 20} // only half bigger
|
b := Box{Top: 10, Left: 10, Right: 20, Bottom: 20} // only half bigger
|
||||||
c := Box{Top: 1, Left: 1, Right: 30, Bottom: 30} //bigger
|
c := Box{Top: 1, Left: 1, Right: 30, Bottom: 30} //bigger
|
||||||
assert.False(a.IsSmallerThan(b))
|
testutil.AssertFalse(t, a.IsSmallerThan(b))
|
||||||
assert.True(a.IsSmallerThan(c))
|
testutil.AssertTrue(t, a.IsSmallerThan(c))
|
||||||
assert.False(c.IsSmallerThan(a))
|
testutil.AssertFalse(t, c.IsSmallerThan(a))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoxGrow(t *testing.T) {
|
func TestBoxGrow(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
a := Box{Top: 1, Left: 2, Right: 15, Bottom: 15}
|
a := Box{Top: 1, Left: 2, Right: 15, Bottom: 15}
|
||||||
b := Box{Top: 4, Left: 5, Right: 30, Bottom: 35}
|
b := Box{Top: 4, Left: 5, Right: 30, Bottom: 35}
|
||||||
c := a.Grow(b)
|
c := a.Grow(b)
|
||||||
assert.False(c.Equals(b))
|
testutil.AssertFalse(t, c.Equals(b))
|
||||||
assert.False(c.Equals(a))
|
testutil.AssertFalse(t, c.Equals(a))
|
||||||
assert.Equal(1, c.Top)
|
testutil.AssertEqual(t, 1, c.Top)
|
||||||
assert.Equal(2, c.Left)
|
testutil.AssertEqual(t, 2, c.Left)
|
||||||
assert.Equal(30, c.Right)
|
testutil.AssertEqual(t, 30, c.Right)
|
||||||
assert.Equal(35, c.Bottom)
|
testutil.AssertEqual(t, 35, c.Bottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoxFit(t *testing.T) {
|
func TestBoxFit(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
a := Box{Top: 64, Left: 64, Right: 192, Bottom: 192}
|
a := Box{Top: 64, Left: 64, Right: 192, Bottom: 192}
|
||||||
b := Box{Top: 16, Left: 16, Right: 256, Bottom: 170}
|
b := Box{Top: 16, Left: 16, Right: 256, Bottom: 170}
|
||||||
c := Box{Top: 16, Left: 16, Right: 170, Bottom: 256}
|
c := Box{Top: 16, Left: 16, Right: 170, Bottom: 256}
|
||||||
|
|
||||||
fab := a.Fit(b)
|
fab := a.Fit(b)
|
||||||
assert.Equal(a.Left, fab.Left)
|
testutil.AssertEqual(t, a.Left, fab.Left)
|
||||||
assert.Equal(a.Right, fab.Right)
|
testutil.AssertEqual(t, a.Right, fab.Right)
|
||||||
assert.True(fab.Top < fab.Bottom)
|
testutil.AssertTrue(t, fab.Top < fab.Bottom)
|
||||||
assert.True(fab.Left < fab.Right)
|
testutil.AssertTrue(t, fab.Left < fab.Right)
|
||||||
assert.True(math.Abs(b.Aspect()-fab.Aspect()) < 0.02)
|
testutil.AssertTrue(t, math.Abs(b.Aspect()-fab.Aspect()) < 0.02)
|
||||||
|
|
||||||
fac := a.Fit(c)
|
fac := a.Fit(c)
|
||||||
assert.Equal(a.Top, fac.Top)
|
testutil.AssertEqual(t, a.Top, fac.Top)
|
||||||
assert.Equal(a.Bottom, fac.Bottom)
|
testutil.AssertEqual(t, a.Bottom, fac.Bottom)
|
||||||
assert.True(math.Abs(c.Aspect()-fac.Aspect()) < 0.02)
|
testutil.AssertTrue(t, math.Abs(c.Aspect()-fac.Aspect()) < 0.02)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoxConstrain(t *testing.T) {
|
func TestBoxConstrain(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
a := Box{Top: 64, Left: 64, Right: 192, Bottom: 192}
|
a := Box{Top: 64, Left: 64, Right: 192, Bottom: 192}
|
||||||
b := Box{Top: 16, Left: 16, Right: 256, Bottom: 170}
|
b := Box{Top: 16, Left: 16, Right: 256, Bottom: 170}
|
||||||
c := Box{Top: 16, Left: 16, Right: 170, Bottom: 256}
|
c := Box{Top: 16, Left: 16, Right: 170, Bottom: 256}
|
||||||
|
|
||||||
cab := a.Constrain(b)
|
cab := a.Constrain(b)
|
||||||
assert.Equal(64, cab.Top)
|
testutil.AssertEqual(t, 64, cab.Top)
|
||||||
assert.Equal(64, cab.Left)
|
testutil.AssertEqual(t, 64, cab.Left)
|
||||||
assert.Equal(192, cab.Right)
|
testutil.AssertEqual(t, 192, cab.Right)
|
||||||
assert.Equal(170, cab.Bottom)
|
testutil.AssertEqual(t, 170, cab.Bottom)
|
||||||
|
|
||||||
cac := a.Constrain(c)
|
cac := a.Constrain(c)
|
||||||
assert.Equal(64, cac.Top)
|
testutil.AssertEqual(t, 64, cac.Top)
|
||||||
assert.Equal(64, cac.Left)
|
testutil.AssertEqual(t, 64, cac.Left)
|
||||||
assert.Equal(170, cac.Right)
|
testutil.AssertEqual(t, 170, cac.Right)
|
||||||
assert.Equal(192, cac.Bottom)
|
testutil.AssertEqual(t, 192, cac.Bottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoxOuterConstrain(t *testing.T) {
|
func TestBoxOuterConstrain(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
box := NewBox(0, 0, 100, 100)
|
box := NewBox(0, 0, 100, 100)
|
||||||
canvas := NewBox(5, 5, 95, 95)
|
canvas := NewBox(5, 5, 95, 95)
|
||||||
taller := NewBox(-10, 5, 50, 50)
|
taller := NewBox(-10, 5, 50, 50)
|
||||||
|
|
||||||
c := canvas.OuterConstrain(box, taller)
|
c := canvas.OuterConstrain(box, taller)
|
||||||
assert.Equal(15, c.Top, c.String())
|
testutil.AssertEqual(t, 15, c.Top, c.String())
|
||||||
assert.Equal(5, c.Left, c.String())
|
testutil.AssertEqual(t, 5, c.Left, c.String())
|
||||||
assert.Equal(95, c.Right, c.String())
|
testutil.AssertEqual(t, 95, c.Right, c.String())
|
||||||
assert.Equal(95, c.Bottom, c.String())
|
testutil.AssertEqual(t, 95, c.Bottom, c.String())
|
||||||
|
|
||||||
wider := NewBox(5, 5, 110, 50)
|
wider := NewBox(5, 5, 110, 50)
|
||||||
d := canvas.OuterConstrain(box, wider)
|
d := canvas.OuterConstrain(box, wider)
|
||||||
assert.Equal(5, d.Top, d.String())
|
testutil.AssertEqual(t, 5, d.Top, d.String())
|
||||||
assert.Equal(5, d.Left, d.String())
|
testutil.AssertEqual(t, 5, d.Left, d.String())
|
||||||
assert.Equal(85, d.Right, d.String())
|
testutil.AssertEqual(t, 85, d.Right, d.String())
|
||||||
assert.Equal(95, d.Bottom, d.String())
|
testutil.AssertEqual(t, 95, d.Bottom, d.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoxShift(t *testing.T) {
|
func TestBoxShift(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
b := Box{
|
b := Box{
|
||||||
Top: 5,
|
Top: 5,
|
||||||
|
@ -138,14 +138,14 @@ func TestBoxShift(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
shifted := b.Shift(1, 2)
|
shifted := b.Shift(1, 2)
|
||||||
assert.Equal(7, shifted.Top)
|
testutil.AssertEqual(t, 7, shifted.Top)
|
||||||
assert.Equal(6, shifted.Left)
|
testutil.AssertEqual(t, 6, shifted.Left)
|
||||||
assert.Equal(11, shifted.Right)
|
testutil.AssertEqual(t, 11, shifted.Right)
|
||||||
assert.Equal(12, shifted.Bottom)
|
testutil.AssertEqual(t, 12, shifted.Bottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoxCenter(t *testing.T) {
|
func TestBoxCenter(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
b := Box{
|
b := Box{
|
||||||
Top: 10,
|
Top: 10,
|
||||||
|
@ -154,12 +154,12 @@ func TestBoxCenter(t *testing.T) {
|
||||||
Bottom: 30,
|
Bottom: 30,
|
||||||
}
|
}
|
||||||
cx, cy := b.Center()
|
cx, cy := b.Center()
|
||||||
assert.Equal(15, cx)
|
testutil.AssertEqual(t, 15, cx)
|
||||||
assert.Equal(20, cy)
|
testutil.AssertEqual(t, 20, cy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoxCornersCenter(t *testing.T) {
|
func TestBoxCornersCenter(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BoxCorners{
|
bc := BoxCorners{
|
||||||
TopLeft: Point{5, 5},
|
TopLeft: Point{5, 5},
|
||||||
|
@ -169,12 +169,12 @@ func TestBoxCornersCenter(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cx, cy := bc.Center()
|
cx, cy := bc.Center()
|
||||||
assert.Equal(10, cx)
|
testutil.AssertEqual(t, 10, cx)
|
||||||
assert.Equal(10, cy)
|
testutil.AssertEqual(t, 10, cy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoxCornersRotate(t *testing.T) {
|
func TestBoxCornersRotate(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
bc := BoxCorners{
|
bc := BoxCorners{
|
||||||
TopLeft: Point{5, 5},
|
TopLeft: Point{5, 5},
|
||||||
|
@ -184,5 +184,5 @@ func TestBoxCornersRotate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
rotated := bc.Rotate(45)
|
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())
|
||||||
}
|
}
|
||||||
|
|
205
chart_test.go
205
chart_test.go
|
@ -8,58 +8,57 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestChartGetDPI(t *testing.T) {
|
func TestChartGetDPI(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
unset := Chart{}
|
unset := Chart{}
|
||||||
assert.Equal(DefaultDPI, unset.GetDPI())
|
testutil.AssertEqual(t, DefaultDPI, unset.GetDPI())
|
||||||
assert.Equal(192, unset.GetDPI(192))
|
testutil.AssertEqual(t, 192, unset.GetDPI(192))
|
||||||
|
|
||||||
set := Chart{DPI: 128}
|
set := Chart{DPI: 128}
|
||||||
assert.Equal(128, set.GetDPI())
|
testutil.AssertEqual(t, 128, set.GetDPI())
|
||||||
assert.Equal(128, set.GetDPI(192))
|
testutil.AssertEqual(t, 128, set.GetDPI(192))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartGetFont(t *testing.T) {
|
func TestChartGetFont(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
unset := Chart{}
|
unset := Chart{}
|
||||||
assert.Nil(unset.GetFont())
|
testutil.AssertNil(t, unset.GetFont())
|
||||||
|
|
||||||
set := Chart{Font: f}
|
set := Chart{Font: f}
|
||||||
assert.NotNil(set.GetFont())
|
testutil.AssertNotNil(t, set.GetFont())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartGetWidth(t *testing.T) {
|
func TestChartGetWidth(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
unset := Chart{}
|
unset := Chart{}
|
||||||
assert.Equal(DefaultChartWidth, unset.GetWidth())
|
testutil.AssertEqual(t, DefaultChartWidth, unset.GetWidth())
|
||||||
|
|
||||||
set := Chart{Width: DefaultChartWidth + 10}
|
set := Chart{Width: DefaultChartWidth + 10}
|
||||||
assert.Equal(DefaultChartWidth+10, set.GetWidth())
|
testutil.AssertEqual(t, DefaultChartWidth+10, set.GetWidth())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartGetHeight(t *testing.T) {
|
func TestChartGetHeight(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
unset := Chart{}
|
unset := Chart{}
|
||||||
assert.Equal(DefaultChartHeight, unset.GetHeight())
|
testutil.AssertEqual(t, DefaultChartHeight, unset.GetHeight())
|
||||||
|
|
||||||
set := Chart{Height: DefaultChartHeight + 10}
|
set := Chart{Height: DefaultChartHeight + 10}
|
||||||
assert.Equal(DefaultChartHeight+10, set.GetHeight())
|
testutil.AssertEqual(t, DefaultChartHeight+10, set.GetHeight())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartGetRanges(t *testing.T) {
|
func TestChartGetRanges(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
c := Chart{
|
c := Chart{
|
||||||
Series: []Series{
|
Series: []Series{
|
||||||
|
@ -80,14 +79,14 @@ func TestChartGetRanges(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
xrange, yrange, yrangeAlt := c.getRanges()
|
xrange, yrange, yrangeAlt := c.getRanges()
|
||||||
assert.Equal(-2.0, xrange.GetMin())
|
testutil.AssertEqual(t, -2.0, xrange.GetMin())
|
||||||
assert.Equal(5.0, xrange.GetMax())
|
testutil.AssertEqual(t, 5.0, xrange.GetMax())
|
||||||
|
|
||||||
assert.Equal(-2.1, yrange.GetMin())
|
testutil.AssertEqual(t, -2.1, yrange.GetMin())
|
||||||
assert.Equal(4.5, yrange.GetMax())
|
testutil.AssertEqual(t, 4.5, yrange.GetMax())
|
||||||
|
|
||||||
assert.Equal(10.0, yrangeAlt.GetMin())
|
testutil.AssertEqual(t, 10.0, yrangeAlt.GetMin())
|
||||||
assert.Equal(14.0, yrangeAlt.GetMax())
|
testutil.AssertEqual(t, 14.0, yrangeAlt.GetMax())
|
||||||
|
|
||||||
cSet := Chart{
|
cSet := Chart{
|
||||||
XAxis: XAxis{
|
XAxis: XAxis{
|
||||||
|
@ -117,18 +116,18 @@ func TestChartGetRanges(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
xr2, yr2, yra2 := cSet.getRanges()
|
xr2, yr2, yra2 := cSet.getRanges()
|
||||||
assert.Equal(9.8, xr2.GetMin())
|
testutil.AssertEqual(t, 9.8, xr2.GetMin())
|
||||||
assert.Equal(19.8, xr2.GetMax())
|
testutil.AssertEqual(t, 19.8, xr2.GetMax())
|
||||||
|
|
||||||
assert.Equal(9.9, yr2.GetMin())
|
testutil.AssertEqual(t, 9.9, yr2.GetMin())
|
||||||
assert.Equal(19.9, yr2.GetMax())
|
testutil.AssertEqual(t, 19.9, yr2.GetMax())
|
||||||
|
|
||||||
assert.Equal(9.7, yra2.GetMin())
|
testutil.AssertEqual(t, 9.7, yra2.GetMin())
|
||||||
assert.Equal(19.7, yra2.GetMax())
|
testutil.AssertEqual(t, 19.7, yra2.GetMax())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartGetRangesUseTicks(t *testing.T) {
|
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.
|
// 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()
|
xr, yr, yar := c.getRanges()
|
||||||
assert.Equal(-2.0, xr.GetMin())
|
testutil.AssertEqual(t, -2.0, xr.GetMin())
|
||||||
assert.Equal(2.0, xr.GetMax())
|
testutil.AssertEqual(t, 2.0, xr.GetMax())
|
||||||
assert.Equal(0.0, yr.GetMin())
|
testutil.AssertEqual(t, 0.0, yr.GetMin())
|
||||||
assert.Equal(5.0, yr.GetMax())
|
testutil.AssertEqual(t, 5.0, yr.GetMax())
|
||||||
assert.True(yar.IsZero(), yar.String())
|
testutil.AssertTrue(t, yar.IsZero(), yar.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartGetRangesUseUserRanges(t *testing.T) {
|
func TestChartGetRangesUseUserRanges(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
c := Chart{
|
c := Chart{
|
||||||
YAxis: YAxis{
|
YAxis: YAxis{
|
||||||
|
@ -182,15 +181,15 @@ func TestChartGetRangesUseUserRanges(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
xr, yr, yar := c.getRanges()
|
xr, yr, yar := c.getRanges()
|
||||||
assert.Equal(-2.0, xr.GetMin())
|
testutil.AssertEqual(t, -2.0, xr.GetMin())
|
||||||
assert.Equal(2.0, xr.GetMax())
|
testutil.AssertEqual(t, 2.0, xr.GetMax())
|
||||||
assert.Equal(-5.0, yr.GetMin())
|
testutil.AssertEqual(t, -5.0, yr.GetMin())
|
||||||
assert.Equal(5.0, yr.GetMax())
|
testutil.AssertEqual(t, 5.0, yr.GetMax())
|
||||||
assert.True(yar.IsZero(), yar.String())
|
testutil.AssertTrue(t, yar.IsZero(), yar.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartGetBackgroundStyle(t *testing.T) {
|
func TestChartGetBackgroundStyle(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
c := Chart{
|
c := Chart{
|
||||||
Background: Style{
|
Background: Style{
|
||||||
|
@ -199,11 +198,11 @@ func TestChartGetBackgroundStyle(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bs := c.getBackgroundStyle()
|
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) {
|
func TestChartGetCanvasStyle(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
c := Chart{
|
c := Chart{
|
||||||
Canvas: Style{
|
Canvas: Style{
|
||||||
|
@ -212,19 +211,19 @@ func TestChartGetCanvasStyle(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bs := c.getCanvasStyle()
|
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) {
|
func TestChartGetDefaultCanvasBox(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
c := Chart{}
|
c := Chart{}
|
||||||
canvasBoxDefault := c.getDefaultCanvasBox()
|
canvasBoxDefault := c.getDefaultCanvasBox()
|
||||||
assert.False(canvasBoxDefault.IsZero())
|
testutil.AssertFalse(t, canvasBoxDefault.IsZero())
|
||||||
assert.Equal(DefaultBackgroundPadding.Top, canvasBoxDefault.Top)
|
testutil.AssertEqual(t, DefaultBackgroundPadding.Top, canvasBoxDefault.Top)
|
||||||
assert.Equal(DefaultBackgroundPadding.Left, canvasBoxDefault.Left)
|
testutil.AssertEqual(t, DefaultBackgroundPadding.Left, canvasBoxDefault.Left)
|
||||||
assert.Equal(c.GetWidth()-DefaultBackgroundPadding.Right, canvasBoxDefault.Right)
|
testutil.AssertEqual(t, c.GetWidth()-DefaultBackgroundPadding.Right, canvasBoxDefault.Right)
|
||||||
assert.Equal(c.GetHeight()-DefaultBackgroundPadding.Bottom, canvasBoxDefault.Bottom)
|
testutil.AssertEqual(t, c.GetHeight()-DefaultBackgroundPadding.Bottom, canvasBoxDefault.Bottom)
|
||||||
|
|
||||||
custom := Chart{
|
custom := Chart{
|
||||||
Background: Style{
|
Background: Style{
|
||||||
|
@ -237,15 +236,15 @@ func TestChartGetDefaultCanvasBox(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
canvasBoxCustom := custom.getDefaultCanvasBox()
|
canvasBoxCustom := custom.getDefaultCanvasBox()
|
||||||
assert.False(canvasBoxCustom.IsZero())
|
testutil.AssertFalse(t, canvasBoxCustom.IsZero())
|
||||||
assert.Equal(DefaultBackgroundPadding.Top+1, canvasBoxCustom.Top)
|
testutil.AssertEqual(t, DefaultBackgroundPadding.Top+1, canvasBoxCustom.Top)
|
||||||
assert.Equal(DefaultBackgroundPadding.Left+1, canvasBoxCustom.Left)
|
testutil.AssertEqual(t, DefaultBackgroundPadding.Left+1, canvasBoxCustom.Left)
|
||||||
assert.Equal(c.GetWidth()-(DefaultBackgroundPadding.Right+1), canvasBoxCustom.Right)
|
testutil.AssertEqual(t, c.GetWidth()-(DefaultBackgroundPadding.Right+1), canvasBoxCustom.Right)
|
||||||
assert.Equal(c.GetHeight()-(DefaultBackgroundPadding.Bottom+1), canvasBoxCustom.Bottom)
|
testutil.AssertEqual(t, c.GetHeight()-(DefaultBackgroundPadding.Bottom+1), canvasBoxCustom.Bottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartGetValueFormatters(t *testing.T) {
|
func TestChartGetValueFormatters(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
c := Chart{
|
c := Chart{
|
||||||
Series: []Series{
|
Series: []Series{
|
||||||
|
@ -266,16 +265,16 @@ func TestChartGetValueFormatters(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dxf, dyf, dyaf := c.getValueFormatters()
|
dxf, dyf, dyaf := c.getValueFormatters()
|
||||||
assert.NotNil(dxf)
|
testutil.AssertNotNil(t, dxf)
|
||||||
assert.NotNil(dyf)
|
testutil.AssertNotNil(t, dyf)
|
||||||
assert.NotNil(dyaf)
|
testutil.AssertNotNil(t, dyaf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartHasAxes(t *testing.T) {
|
func TestChartHasAxes(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
assert.True(Chart{}.hasAxes())
|
testutil.AssertTrue(t, Chart{}.hasAxes())
|
||||||
assert.False(Chart{XAxis: XAxis{Style: Hidden()}, YAxis: YAxis{Style: Hidden()}, YAxisSecondary: YAxis{Style: Hidden()}}.hasAxes())
|
testutil.AssertFalse(t, Chart{XAxis: XAxis{Style: Hidden()}, YAxis: YAxis{Style: Hidden()}, YAxisSecondary: YAxis{Style: Hidden()}}.hasAxes())
|
||||||
|
|
||||||
x := Chart{
|
x := Chart{
|
||||||
XAxis: XAxis{
|
XAxis: XAxis{
|
||||||
|
@ -288,7 +287,7 @@ func TestChartHasAxes(t *testing.T) {
|
||||||
Style: Hidden(),
|
Style: Hidden(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.True(x.hasAxes())
|
testutil.AssertTrue(t, x.hasAxes())
|
||||||
|
|
||||||
y := Chart{
|
y := Chart{
|
||||||
XAxis: XAxis{
|
XAxis: XAxis{
|
||||||
|
@ -301,7 +300,7 @@ func TestChartHasAxes(t *testing.T) {
|
||||||
Style: Hidden(),
|
Style: Hidden(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.True(y.hasAxes())
|
testutil.AssertTrue(t, y.hasAxes())
|
||||||
|
|
||||||
ya := Chart{
|
ya := Chart{
|
||||||
XAxis: XAxis{
|
XAxis: XAxis{
|
||||||
|
@ -314,14 +313,14 @@ func TestChartHasAxes(t *testing.T) {
|
||||||
Style: Shown(),
|
Style: Shown(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.True(ya.hasAxes())
|
testutil.AssertTrue(t, ya.hasAxes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartGetAxesTicks(t *testing.T) {
|
func TestChartGetAxesTicks(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
r, err := PNG(1024, 1024)
|
r, err := PNG(1024, 1024)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
c := Chart{
|
c := Chart{
|
||||||
XAxis: XAxis{
|
XAxis: XAxis{
|
||||||
|
@ -337,13 +336,13 @@ func TestChartGetAxesTicks(t *testing.T) {
|
||||||
xr, yr, yar := c.getRanges()
|
xr, yr, yar := c.getRanges()
|
||||||
|
|
||||||
xt, yt, yat := c.getAxesTicks(r, xr, yr, yar, FloatValueFormatter, FloatValueFormatter, FloatValueFormatter)
|
xt, yt, yat := c.getAxesTicks(r, xr, yr, yar, FloatValueFormatter, FloatValueFormatter, FloatValueFormatter)
|
||||||
assert.NotEmpty(xt)
|
testutil.AssertNotEmpty(t, xt)
|
||||||
assert.NotEmpty(yt)
|
testutil.AssertNotEmpty(t, yt)
|
||||||
assert.NotEmpty(yat)
|
testutil.AssertNotEmpty(t, yat)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartSingleSeries(t *testing.T) {
|
func TestChartSingleSeries(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
c := Chart{
|
c := Chart{
|
||||||
Title: "Hello!",
|
Title: "Hello!",
|
||||||
|
@ -366,11 +365,11 @@ func TestChartSingleSeries(t *testing.T) {
|
||||||
|
|
||||||
buffer := bytes.NewBuffer([]byte{})
|
buffer := bytes.NewBuffer([]byte{})
|
||||||
c.Render(PNG, buffer)
|
c.Render(PNG, buffer)
|
||||||
assert.NotEmpty(buffer.Bytes())
|
testutil.AssertNotEmpty(t, buffer.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartRegressionBadRanges(t *testing.T) {
|
func TestChartRegressionBadRanges(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
c := Chart{
|
c := Chart{
|
||||||
Series: []Series{
|
Series: []Series{
|
||||||
|
@ -382,11 +381,11 @@ func TestChartRegressionBadRanges(t *testing.T) {
|
||||||
}
|
}
|
||||||
buffer := bytes.NewBuffer([]byte{})
|
buffer := bytes.NewBuffer([]byte{})
|
||||||
c.Render(PNG, buffer)
|
c.Render(PNG, buffer)
|
||||||
assert.True(true, "Render needs to finish.")
|
testutil.AssertTrue(t, true, "Render needs to finish.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartRegressionBadRangesByUser(t *testing.T) {
|
func TestChartRegressionBadRangesByUser(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
c := Chart{
|
c := Chart{
|
||||||
YAxis: YAxis{
|
YAxis: YAxis{
|
||||||
|
@ -404,11 +403,11 @@ func TestChartRegressionBadRangesByUser(t *testing.T) {
|
||||||
}
|
}
|
||||||
buffer := bytes.NewBuffer([]byte{})
|
buffer := bytes.NewBuffer([]byte{})
|
||||||
c.Render(PNG, buffer)
|
c.Render(PNG, buffer)
|
||||||
assert.True(true, "Render needs to finish.")
|
testutil.AssertTrue(t, true, "Render needs to finish.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartValidatesSeries(t *testing.T) {
|
func TestChartValidatesSeries(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
c := Chart{
|
c := Chart{
|
||||||
Series: []Series{
|
Series: []Series{
|
||||||
|
@ -419,7 +418,7 @@ func TestChartValidatesSeries(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Nil(c.validateSeries())
|
testutil.AssertNil(t, c.validateSeries())
|
||||||
|
|
||||||
c = Chart{
|
c = Chart{
|
||||||
Series: []Series{
|
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) {
|
func TestChartCheckRanges(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
c := Chart{
|
c := Chart{
|
||||||
Series: []Series{
|
Series: []Series{
|
||||||
|
@ -445,11 +444,11 @@ func TestChartCheckRanges(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
xr, yr, yra := c.getRanges()
|
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) {
|
func TestChartCheckRangesWithRanges(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
c := Chart{
|
c := Chart{
|
||||||
XAxis: XAxis{
|
XAxis: XAxis{
|
||||||
|
@ -473,7 +472,7 @@ func TestChartCheckRangesWithRanges(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
xr, yr, yra := c.getRanges()
|
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 {
|
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) {
|
func TestChartE2ELine(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
c := Chart{
|
c := Chart{
|
||||||
Height: 50,
|
Height: 50,
|
||||||
|
@ -506,26 +505,26 @@ func TestChartE2ELine(t *testing.T) {
|
||||||
|
|
||||||
var buffer = &bytes.Buffer{}
|
var buffer = &bytes.Buffer{}
|
||||||
err := c.Render(PNG, buffer)
|
err := c.Render(PNG, buffer)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
// do color tests ...
|
// do color tests ...
|
||||||
|
|
||||||
i, err := png.Decode(buffer)
|
i, err := png.Decode(buffer)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
// test the bottom and top of the line
|
// test the bottom and top of the line
|
||||||
assert.Equal(drawing.ColorWhite, at(i, 0, 0))
|
testutil.AssertEqual(t, drawing.ColorWhite, at(i, 0, 0))
|
||||||
assert.Equal(drawing.ColorWhite, at(i, 49, 49))
|
testutil.AssertEqual(t, drawing.ColorWhite, at(i, 49, 49))
|
||||||
|
|
||||||
// test a line mid point
|
// test a line mid point
|
||||||
defaultSeriesColor := GetDefaultColor(0)
|
defaultSeriesColor := GetDefaultColor(0)
|
||||||
assert.Equal(defaultSeriesColor, at(i, 0, 49))
|
testutil.AssertEqual(t, defaultSeriesColor, at(i, 0, 49))
|
||||||
assert.Equal(defaultSeriesColor, at(i, 49, 0))
|
testutil.AssertEqual(t, defaultSeriesColor, at(i, 49, 0))
|
||||||
assert.Equal(drawing.ColorFromHex("bddbf6"), at(i, 24, 24))
|
testutil.AssertEqual(t, drawing.ColorFromHex("bddbf6"), at(i, 24, 24))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChartE2ELineWithFill(t *testing.T) {
|
func TestChartE2ELineWithFill(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
logBuffer := new(bytes.Buffer)
|
logBuffer := new(bytes.Buffer)
|
||||||
|
|
||||||
|
@ -555,22 +554,22 @@ func TestChartE2ELineWithFill(t *testing.T) {
|
||||||
Log: NewLogger(OptLoggerStdout(logBuffer), OptLoggerStderr(logBuffer)),
|
Log: NewLogger(OptLoggerStdout(logBuffer), OptLoggerStderr(logBuffer)),
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(5, len(c.Series[0].(ContinuousSeries).XValues))
|
testutil.AssertEqual(t, 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).YValues))
|
||||||
|
|
||||||
var buffer = &bytes.Buffer{}
|
var buffer = &bytes.Buffer{}
|
||||||
err := c.Render(PNG, buffer)
|
err := c.Render(PNG, buffer)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
i, err := png.Decode(buffer)
|
i, err := png.Decode(buffer)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
// test the bottom and top of the line
|
// test the bottom and top of the line
|
||||||
assert.Equal(drawing.ColorWhite, at(i, 0, 0))
|
testutil.AssertEqual(t, drawing.ColorWhite, at(i, 0, 0))
|
||||||
assert.Equal(drawing.ColorRed, at(i, 49, 49))
|
testutil.AssertEqual(t, drawing.ColorRed, at(i, 49, 49))
|
||||||
|
|
||||||
// test a line mid point
|
// test a line mid point
|
||||||
defaultSeriesColor := drawing.ColorBlue
|
defaultSeriesColor := drawing.ColorBlue
|
||||||
assert.Equal(defaultSeriesColor, at(i, 0, 49))
|
testutil.AssertEqual(t, defaultSeriesColor, at(i, 0, 49))
|
||||||
assert.Equal(defaultSeriesColor, at(i, 49, 0))
|
testutil.AssertEqual(t, defaultSeriesColor, at(i, 49, 0))
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package chart
|
package chart
|
||||||
|
|
||||||
import "github.com/wcharczuk/go-chart/drawing"
|
import "github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ColorWhite is white.
|
// ColorWhite is white.
|
||||||
|
|
|
@ -3,11 +3,11 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConcatSeries(t *testing.T) {
|
func TestConcatSeries(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
s1 := ContinuousSeries{
|
s1 := ContinuousSeries{
|
||||||
XValues: LinearRange(1.0, 10.0),
|
XValues: LinearRange(1.0, 10.0),
|
||||||
|
@ -25,17 +25,17 @@ func TestConcatSeries(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cs := ConcatSeries([]Series{s1, s2, s3})
|
cs := ConcatSeries([]Series{s1, s2, s3})
|
||||||
assert.Equal(30, cs.Len())
|
testutil.AssertEqual(t, 30, cs.Len())
|
||||||
|
|
||||||
x0, y0 := cs.GetValue(0)
|
x0, y0 := cs.GetValue(0)
|
||||||
assert.Equal(1.0, x0)
|
testutil.AssertEqual(t, 1.0, x0)
|
||||||
assert.Equal(1.0, y0)
|
testutil.AssertEqual(t, 1.0, y0)
|
||||||
|
|
||||||
xm, ym := cs.GetValue(19)
|
xm, ym := cs.GetValue(19)
|
||||||
assert.Equal(20.0, xm)
|
testutil.AssertEqual(t, 20.0, xm)
|
||||||
assert.Equal(1.0, ym)
|
testutil.AssertEqual(t, 1.0, ym)
|
||||||
|
|
||||||
xn, yn := cs.GetValue(29)
|
xn, yn := cs.GetValue(29)
|
||||||
assert.Equal(30.0, xn)
|
testutil.AssertEqual(t, 30.0, xn)
|
||||||
assert.Equal(10.0, yn)
|
testutil.AssertEqual(t, 10.0, yn)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,11 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRangeTranslate(t *testing.T) {
|
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}
|
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 := ContinuousRange{Domain: 1000}
|
||||||
r.Min, r.Max = MinMax(values...)
|
r.Min, r.Max = MinMax(values...)
|
||||||
|
@ -16,7 +16,7 @@ func TestRangeTranslate(t *testing.T) {
|
||||||
// value = ~5.0
|
// value = ~5.0
|
||||||
// domain = ~1000
|
// domain = ~1000
|
||||||
// 5/8 * 1000 ~=
|
// 5/8 * 1000 ~=
|
||||||
assert.Equal(0, r.Translate(1.0))
|
testutil.AssertEqual(t, 0, r.Translate(1.0))
|
||||||
assert.Equal(1000, r.Translate(8.0))
|
testutil.AssertEqual(t, 1000, r.Translate(8.0))
|
||||||
assert.Equal(572, r.Translate(5.0))
|
testutil.AssertEqual(t, 572, r.Translate(5.0))
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestContinuousSeries(t *testing.T) {
|
func TestContinuousSeries(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
cs := ContinuousSeries{
|
cs := ContinuousSeries{
|
||||||
Name: "Test Series",
|
Name: "Test Series",
|
||||||
|
@ -16,23 +16,23 @@ func TestContinuousSeries(t *testing.T) {
|
||||||
YValues: LinearRange(1.0, 10.0),
|
YValues: LinearRange(1.0, 10.0),
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal("Test Series", cs.GetName())
|
testutil.AssertEqual(t, "Test Series", cs.GetName())
|
||||||
assert.Equal(10, cs.Len())
|
testutil.AssertEqual(t, 10, cs.Len())
|
||||||
x0, y0 := cs.GetValues(0)
|
x0, y0 := cs.GetValues(0)
|
||||||
assert.Equal(1.0, x0)
|
testutil.AssertEqual(t, 1.0, x0)
|
||||||
assert.Equal(1.0, y0)
|
testutil.AssertEqual(t, 1.0, y0)
|
||||||
|
|
||||||
xn, yn := cs.GetValues(9)
|
xn, yn := cs.GetValues(9)
|
||||||
assert.Equal(10.0, xn)
|
testutil.AssertEqual(t, 10.0, xn)
|
||||||
assert.Equal(10.0, yn)
|
testutil.AssertEqual(t, 10.0, yn)
|
||||||
|
|
||||||
xn, yn = cs.GetLastValues()
|
xn, yn = cs.GetLastValues()
|
||||||
assert.Equal(10.0, xn)
|
testutil.AssertEqual(t, 10.0, xn)
|
||||||
assert.Equal(10.0, yn)
|
testutil.AssertEqual(t, 10.0, yn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContinuousSeriesValueFormatter(t *testing.T) {
|
func TestContinuousSeriesValueFormatter(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
cs := ContinuousSeries{
|
cs := ContinuousSeries{
|
||||||
XValueFormatter: func(v interface{}) string {
|
XValueFormatter: func(v interface{}) string {
|
||||||
|
@ -44,29 +44,29 @@ func TestContinuousSeriesValueFormatter(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
xf, yf := cs.GetValueFormatters()
|
xf, yf := cs.GetValueFormatters()
|
||||||
assert.Equal("0.100000 foo", xf(0.1))
|
testutil.AssertEqual(t, "0.100000 foo", xf(0.1))
|
||||||
assert.Equal("0.100000 bar", yf(0.1))
|
testutil.AssertEqual(t, "0.100000 bar", yf(0.1))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContinuousSeriesValidate(t *testing.T) {
|
func TestContinuousSeriesValidate(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
cs := ContinuousSeries{
|
cs := ContinuousSeries{
|
||||||
Name: "Test Series",
|
Name: "Test Series",
|
||||||
XValues: LinearRange(1.0, 10.0),
|
XValues: LinearRange(1.0, 10.0),
|
||||||
YValues: LinearRange(1.0, 10.0),
|
YValues: LinearRange(1.0, 10.0),
|
||||||
}
|
}
|
||||||
assert.Nil(cs.Validate())
|
testutil.AssertNil(t, cs.Validate())
|
||||||
|
|
||||||
cs = ContinuousSeries{
|
cs = ContinuousSeries{
|
||||||
Name: "Test Series",
|
Name: "Test Series",
|
||||||
XValues: LinearRange(1.0, 10.0),
|
XValues: LinearRange(1.0, 10.0),
|
||||||
}
|
}
|
||||||
assert.NotNil(cs.Validate())
|
testutil.AssertNotNil(t, cs.Validate())
|
||||||
|
|
||||||
cs = ContinuousSeries{
|
cs = ContinuousSeries{
|
||||||
Name: "Test Series",
|
Name: "Test Series",
|
||||||
YValues: LinearRange(1.0, 10.0),
|
YValues: LinearRange(1.0, 10.0),
|
||||||
}
|
}
|
||||||
assert.NotNil(cs.Validate())
|
testutil.AssertNotNil(t, cs.Validate())
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDonutChart(t *testing.T) {
|
func TestDonutChart(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
pie := DonutChart{
|
pie := DonutChart{
|
||||||
Canvas: Style{
|
Canvas: Style{
|
||||||
|
@ -27,11 +27,11 @@ func TestDonutChart(t *testing.T) {
|
||||||
|
|
||||||
b := bytes.NewBuffer([]byte{})
|
b := bytes.NewBuffer([]byte{})
|
||||||
pie.Render(PNG, b)
|
pie.Render(PNG, b)
|
||||||
assert.NotZero(b.Len())
|
testutil.AssertNotZero(t, b.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDonutChartDropsZeroValues(t *testing.T) {
|
func TestDonutChartDropsZeroValues(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
pie := DonutChart{
|
pie := DonutChart{
|
||||||
Canvas: Style{
|
Canvas: Style{
|
||||||
|
@ -46,11 +46,11 @@ func TestDonutChartDropsZeroValues(t *testing.T) {
|
||||||
|
|
||||||
b := bytes.NewBuffer([]byte{})
|
b := bytes.NewBuffer([]byte{})
|
||||||
err := pie.Render(PNG, b)
|
err := pie.Render(PNG, b)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDonutChartAllZeroValues(t *testing.T) {
|
func TestDonutChartAllZeroValues(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
pie := DonutChart{
|
pie := DonutChart{
|
||||||
Canvas: Style{
|
Canvas: Style{
|
||||||
|
@ -65,5 +65,5 @@ func TestDonutChartAllZeroValues(t *testing.T) {
|
||||||
|
|
||||||
b := bytes.NewBuffer([]byte{})
|
b := bytes.NewBuffer([]byte{})
|
||||||
err := pie.Render(PNG, b)
|
err := pie.Render(PNG, b)
|
||||||
assert.NotNil(err)
|
testutil.AssertNotNil(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,49 +5,49 @@ import (
|
||||||
|
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestColorFromHex(t *testing.T) {
|
func TestColorFromHex(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
white := ColorFromHex("FFFFFF")
|
white := ColorFromHex("FFFFFF")
|
||||||
assert.Equal(ColorWhite, white)
|
testutil.AssertEqual(t, ColorWhite, white)
|
||||||
|
|
||||||
shortWhite := ColorFromHex("FFF")
|
shortWhite := ColorFromHex("FFF")
|
||||||
assert.Equal(ColorWhite, shortWhite)
|
testutil.AssertEqual(t, ColorWhite, shortWhite)
|
||||||
|
|
||||||
black := ColorFromHex("000000")
|
black := ColorFromHex("000000")
|
||||||
assert.Equal(ColorBlack, black)
|
testutil.AssertEqual(t, ColorBlack, black)
|
||||||
|
|
||||||
shortBlack := ColorFromHex("000")
|
shortBlack := ColorFromHex("000")
|
||||||
assert.Equal(ColorBlack, shortBlack)
|
testutil.AssertEqual(t, ColorBlack, shortBlack)
|
||||||
|
|
||||||
red := ColorFromHex("FF0000")
|
red := ColorFromHex("FF0000")
|
||||||
assert.Equal(ColorRed, red)
|
testutil.AssertEqual(t, ColorRed, red)
|
||||||
|
|
||||||
shortRed := ColorFromHex("F00")
|
shortRed := ColorFromHex("F00")
|
||||||
assert.Equal(ColorRed, shortRed)
|
testutil.AssertEqual(t, ColorRed, shortRed)
|
||||||
|
|
||||||
green := ColorFromHex("00FF00")
|
green := ColorFromHex("00FF00")
|
||||||
assert.Equal(ColorGreen, green)
|
testutil.AssertEqual(t, ColorGreen, green)
|
||||||
|
|
||||||
shortGreen := ColorFromHex("0F0")
|
shortGreen := ColorFromHex("0F0")
|
||||||
assert.Equal(ColorGreen, shortGreen)
|
testutil.AssertEqual(t, ColorGreen, shortGreen)
|
||||||
|
|
||||||
blue := ColorFromHex("0000FF")
|
blue := ColorFromHex("0000FF")
|
||||||
assert.Equal(ColorBlue, blue)
|
testutil.AssertEqual(t, ColorBlue, blue)
|
||||||
|
|
||||||
shortBlue := ColorFromHex("00F")
|
shortBlue := ColorFromHex("00F")
|
||||||
assert.Equal(ColorBlue, shortBlue)
|
testutil.AssertEqual(t, ColorBlue, shortBlue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestColorFromAlphaMixedRGBA(t *testing.T) {
|
func TestColorFromAlphaMixedRGBA(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
black := ColorFromAlphaMixedRGBA(color.Black.RGBA())
|
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())
|
white := ColorFromAlphaMixedRGBA(color.White.RGBA())
|
||||||
assert.True(white.Equals(ColorWhite), white.String())
|
testutil.AssertTrue(t, white.Equals(ColorWhite), white.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package drawing
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type point struct {
|
type point struct {
|
||||||
|
@ -23,7 +23,7 @@ func (ml mockLine) Len() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTraceQuad(t *testing.T) {
|
func TestTraceQuad(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
// Quad
|
// Quad
|
||||||
// x1, y1, cpx1, cpy2, x2, y2 float64
|
// x1, y1, cpx1, cpy2, x2, y2 float64
|
||||||
|
@ -31,5 +31,5 @@ func TestTraceQuad(t *testing.T) {
|
||||||
quad := []float64{10, 20, 20, 20, 20, 10}
|
quad := []float64{10, 20, 20, 20, 20, 10}
|
||||||
liner := &mockLine{}
|
liner := &mockLine{}
|
||||||
TraceQuad(liner, quad, 0.5)
|
TraceQuad(liner, quad, 0.5)
|
||||||
assert.NotZero(liner.Len())
|
testutil.AssertNotZero(t, liner.Len())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -73,13 +73,13 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEMASeries(t *testing.T) {
|
func TestEMASeries(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
mockSeries := mockValuesProvider{
|
mockSeries := mockValuesProvider{
|
||||||
emaXValues,
|
emaXValues,
|
||||||
emaYValues,
|
emaYValues,
|
||||||
}
|
}
|
||||||
assert.Equal(50, mockSeries.Len())
|
testutil.AssertEqual(t, 50, mockSeries.Len())
|
||||||
|
|
||||||
ema := &EMASeries{
|
ema := &EMASeries{
|
||||||
InnerSeries: mockSeries,
|
InnerSeries: mockSeries,
|
||||||
|
@ -87,7 +87,7 @@ func TestEMASeries(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sig := ema.GetSigma()
|
sig := ema.GetSigma()
|
||||||
assert.Equal(2.0/(26.0+1), sig)
|
testutil.AssertEqual(t, 2.0/(26.0+1), sig)
|
||||||
|
|
||||||
var yvalues []float64
|
var yvalues []float64
|
||||||
for x := 0; x < ema.Len(); x++ {
|
for x := 0; x < ema.Len(); x++ {
|
||||||
|
@ -96,10 +96,10 @@ func TestEMASeries(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for index, yv := range yvalues {
|
for index, yv := range yvalues {
|
||||||
assert.InDelta(yv, emaExpected[index], emaDelta)
|
testutil.AssertInDelta(t, yv, emaExpected[index], emaDelta)
|
||||||
}
|
}
|
||||||
|
|
||||||
lvx, lvy := ema.GetLastValues()
|
lvx, lvy := ema.GetLastValues()
|
||||||
assert.Equal(50.0, lvx)
|
testutil.AssertEqual(t, 50.0, lvx)
|
||||||
assert.InDelta(lvy, emaExpected[49], emaDelta)
|
testutil.AssertInDelta(t, lvy, emaExpected[49], emaDelta)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
chart "github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
chart "github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,8 +5,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func random(min, max float64) float64 {
|
func random(min, max float64) float64 {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"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
|
// Note: Additional examples on how to add Stylesheets are in the custom_stylesheets example
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,8 +5,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,8 +5,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const style = "svg .background { fill: white; }" +
|
const style = "svg .background { fill: white; }" +
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
chart "github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
chart "github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
chart "github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var lock sync.Mutex
|
var lock sync.Mutex
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
|
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -5,8 +5,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
chart "github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -3,11 +3,11 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFirstValueAnnotation(t *testing.T) {
|
func TestFirstValueAnnotation(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
series := ContinuousSeries{
|
series := ContinuousSeries{
|
||||||
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
|
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
|
||||||
|
@ -15,8 +15,8 @@ func TestFirstValueAnnotation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fva := FirstValueAnnotation(series)
|
fva := FirstValueAnnotation(series)
|
||||||
assert.NotEmpty(fva.Annotations)
|
testutil.AssertNotEmpty(t, fva.Annotations)
|
||||||
fvaa := fva.Annotations[0]
|
fvaa := fva.Annotations[0]
|
||||||
assert.Equal(1, fvaa.XValue)
|
testutil.AssertEqual(t, 1, fvaa.XValue)
|
||||||
assert.Equal(5, fvaa.YValue)
|
testutil.AssertEqual(t, 5, fvaa.YValue)
|
||||||
}
|
}
|
||||||
|
|
2
font.go
2
font.go
|
@ -4,7 +4,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"github.com/wcharczuk/go-chart/roboto"
|
"github.com/wcharczuk/go-chart/v2/roboto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
8
go.mod
Normal file
8
go.mod
Normal file
|
@ -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
|
||||||
|
)
|
5
go.sum
Normal file
5
go.sum
Normal file
|
@ -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=
|
|
@ -3,11 +3,11 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenerateGridLines(t *testing.T) {
|
func TestGenerateGridLines(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
ticks := []Tick{
|
ticks := []Tick{
|
||||||
{Value: 1.0, Label: "1.0"},
|
{Value: 1.0, Label: "1.0"},
|
||||||
|
@ -17,8 +17,8 @@ func TestGenerateGridLines(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
gl := GenerateGridLines(ticks, Style{}, Style{})
|
gl := GenerateGridLines(ticks, Style{}, Style{})
|
||||||
assert.Len(gl, 2)
|
testutil.AssertLen(t, gl, 2)
|
||||||
|
|
||||||
assert.Equal(2.0, gl[0].Value)
|
testutil.AssertEqual(t, 2.0, gl[0].Value)
|
||||||
assert.Equal(3.0, gl[1].Value)
|
testutil.AssertEqual(t, 3.0, gl[1].Value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,11 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHistogramSeries(t *testing.T) {
|
func TestHistogramSeries(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
cs := ContinuousSeries{
|
cs := ContinuousSeries{
|
||||||
Name: "Test Series",
|
Name: "Test Series",
|
||||||
|
@ -22,10 +22,10 @@ func TestHistogramSeries(t *testing.T) {
|
||||||
for x := 0; x < hs.Len(); x++ {
|
for x := 0; x < hs.Len(); x++ {
|
||||||
csx, csy := cs.GetValues(0)
|
csx, csy := cs.GetValues(0)
|
||||||
hsx, hsy1, hsy2 := hs.GetBoundedValues(0)
|
hsx, hsy1, hsy2 := hs.GetBoundedValues(0)
|
||||||
assert.Equal(csx, hsx)
|
testutil.AssertEqual(t, csx, hsx)
|
||||||
assert.True(hsy1 > 0)
|
testutil.AssertTrue(t, hsy1 > 0)
|
||||||
assert.True(hsy2 <= 0)
|
testutil.AssertTrue(t, hsy2 <= 0)
|
||||||
assert.True(csy < 0 || (csy > 0 && csy == hsy1))
|
testutil.AssertTrue(t, csy < 0 || (csy > 0 && csy == hsy1))
|
||||||
assert.True(csy > 0 || (csy < 0 && csy == hsy2))
|
testutil.AssertTrue(t, csy > 0 || (csy < 0 && csy == hsy2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
jet.go
2
jet.go
|
@ -1,6 +1,6 @@
|
||||||
package chart
|
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.
|
// Jet is a color map provider based on matlab's jet color map.
|
||||||
func Jet(v, vmin, vmax float64) drawing.Color {
|
func Jet(v, vmin, vmax float64) drawing.Color {
|
||||||
|
|
|
@ -3,11 +3,11 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLastValueAnnotationSeries(t *testing.T) {
|
func TestLastValueAnnotationSeries(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
series := ContinuousSeries{
|
series := ContinuousSeries{
|
||||||
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
|
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
|
||||||
|
@ -15,8 +15,8 @@ func TestLastValueAnnotationSeries(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
lva := LastValueAnnotationSeries(series)
|
lva := LastValueAnnotationSeries(series)
|
||||||
assert.NotEmpty(lva.Annotations)
|
testutil.AssertNotEmpty(t, lva.Annotations)
|
||||||
lvaa := lva.Annotations[0]
|
lvaa := lva.Annotations[0]
|
||||||
assert.Equal(5, lvaa.XValue)
|
testutil.AssertEqual(t, 5, lvaa.XValue)
|
||||||
assert.Equal(1, lvaa.YValue)
|
testutil.AssertEqual(t, 1, lvaa.YValue)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package chart
|
package chart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Legend returns a legend renderable function.
|
// Legend returns a legend renderable function.
|
||||||
|
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLegend(t *testing.T) {
|
func TestLegend(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
graph := Chart{
|
graph := Chart{
|
||||||
Series: []Series{
|
Series: []Series{
|
||||||
|
@ -26,6 +26,6 @@ func TestLegend(t *testing.T) {
|
||||||
}
|
}
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
err := graph.Render(PNG, buf)
|
err := graph.Render(PNG, buf)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
assert.NotZero(buf.Len())
|
testutil.AssertNotZero(t, buf.Len())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,11 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLinearRegressionSeries(t *testing.T) {
|
func TestLinearRegressionSeries(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
mainSeries := ContinuousSeries{
|
mainSeries := ContinuousSeries{
|
||||||
Name: "A test series",
|
Name: "A test series",
|
||||||
|
@ -20,16 +20,16 @@ func TestLinearRegressionSeries(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
lrx0, lry0 := linRegSeries.GetValues(0)
|
lrx0, lry0 := linRegSeries.GetValues(0)
|
||||||
assert.InDelta(1.0, lrx0, 0.0000001)
|
testutil.AssertInDelta(t, 1.0, lrx0, 0.0000001)
|
||||||
assert.InDelta(1.0, lry0, 0.0000001)
|
testutil.AssertInDelta(t, 1.0, lry0, 0.0000001)
|
||||||
|
|
||||||
lrxn, lryn := linRegSeries.GetLastValues()
|
lrxn, lryn := linRegSeries.GetLastValues()
|
||||||
assert.InDelta(100.0, lrxn, 0.0000001)
|
testutil.AssertInDelta(t, 100.0, lrxn, 0.0000001)
|
||||||
assert.InDelta(100.0, lryn, 0.0000001)
|
testutil.AssertInDelta(t, 100.0, lryn, 0.0000001)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLinearRegressionSeriesDesc(t *testing.T) {
|
func TestLinearRegressionSeriesDesc(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
mainSeries := ContinuousSeries{
|
mainSeries := ContinuousSeries{
|
||||||
Name: "A test series",
|
Name: "A test series",
|
||||||
|
@ -42,16 +42,16 @@ func TestLinearRegressionSeriesDesc(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
lrx0, lry0 := linRegSeries.GetValues(0)
|
lrx0, lry0 := linRegSeries.GetValues(0)
|
||||||
assert.InDelta(100.0, lrx0, 0.0000001)
|
testutil.AssertInDelta(t, 100.0, lrx0, 0.0000001)
|
||||||
assert.InDelta(100.0, lry0, 0.0000001)
|
testutil.AssertInDelta(t, 100.0, lry0, 0.0000001)
|
||||||
|
|
||||||
lrxn, lryn := linRegSeries.GetLastValues()
|
lrxn, lryn := linRegSeries.GetLastValues()
|
||||||
assert.InDelta(1.0, lrxn, 0.0000001)
|
testutil.AssertInDelta(t, 1.0, lrxn, 0.0000001)
|
||||||
assert.InDelta(1.0, lryn, 0.0000001)
|
testutil.AssertInDelta(t, 1.0, lryn, 0.0000001)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLinearRegressionSeriesWindowAndOffset(t *testing.T) {
|
func TestLinearRegressionSeriesWindowAndOffset(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
mainSeries := ContinuousSeries{
|
mainSeries := ContinuousSeries{
|
||||||
Name: "A test series",
|
Name: "A test series",
|
||||||
|
@ -65,13 +65,13 @@ func TestLinearRegressionSeriesWindowAndOffset(t *testing.T) {
|
||||||
Limit: 10,
|
Limit: 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(10, linRegSeries.Len())
|
testutil.AssertEqual(t, 10, linRegSeries.Len())
|
||||||
|
|
||||||
lrx0, lry0 := linRegSeries.GetValues(0)
|
lrx0, lry0 := linRegSeries.GetValues(0)
|
||||||
assert.InDelta(90.0, lrx0, 0.0000001)
|
testutil.AssertInDelta(t, 90.0, lrx0, 0.0000001)
|
||||||
assert.InDelta(90.0, lry0, 0.0000001)
|
testutil.AssertInDelta(t, 90.0, lry0, 0.0000001)
|
||||||
|
|
||||||
lrxn, lryn := linRegSeries.GetLastValues()
|
lrxn, lryn := linRegSeries.GetLastValues()
|
||||||
assert.InDelta(80.0, lrxn, 0.0000001)
|
testutil.AssertInDelta(t, 80.0, lrxn, 0.0000001)
|
||||||
assert.InDelta(80.0, lryn, 0.0000001)
|
testutil.AssertInDelta(t, 80.0, lryn, 0.0000001)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -63,13 +63,13 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMACDSeries(t *testing.T) {
|
func TestMACDSeries(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
mockSeries := mockValuesProvider{
|
mockSeries := mockValuesProvider{
|
||||||
emaXValues,
|
emaXValues,
|
||||||
emaYValues,
|
emaYValues,
|
||||||
}
|
}
|
||||||
assert.Equal(50, mockSeries.Len())
|
testutil.AssertEqual(t, 50, mockSeries.Len())
|
||||||
|
|
||||||
mas := &MACDSeries{
|
mas := &MACDSeries{
|
||||||
InnerSeries: mockSeries,
|
InnerSeries: mockSeries,
|
||||||
|
@ -81,8 +81,8 @@ func TestMACDSeries(t *testing.T) {
|
||||||
yvalues = append(yvalues, y)
|
yvalues = append(yvalues, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NotEmpty(yvalues)
|
testutil.AssertNotEmpty(t, yvalues)
|
||||||
for index, vy := range 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]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,139 +3,139 @@ package matrix
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNew(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := New(10, 5)
|
m := New(10, 5)
|
||||||
rows, cols := m.Size()
|
rows, cols := m.Size()
|
||||||
assert.Equal(10, rows)
|
testutil.AssertEqual(t, 10, rows)
|
||||||
assert.Equal(5, cols)
|
testutil.AssertEqual(t, 5, cols)
|
||||||
assert.Zero(m.Get(0, 0))
|
testutil.AssertZero(t, m.Get(0, 0))
|
||||||
assert.Zero(m.Get(9, 4))
|
testutil.AssertZero(t, m.Get(9, 4))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewWithValues(t *testing.T) {
|
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)
|
m := New(5, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
||||||
rows, cols := m.Size()
|
rows, cols := m.Size()
|
||||||
assert.Equal(5, rows)
|
testutil.AssertEqual(t, 5, rows)
|
||||||
assert.Equal(2, cols)
|
testutil.AssertEqual(t, 2, cols)
|
||||||
assert.Equal(1, m.Get(0, 0))
|
testutil.AssertEqual(t, 1, m.Get(0, 0))
|
||||||
assert.Equal(10, m.Get(4, 1))
|
testutil.AssertEqual(t, 10, m.Get(4, 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIdentitiy(t *testing.T) {
|
func TestIdentitiy(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
id := Identity(5)
|
id := Identity(5)
|
||||||
rows, cols := id.Size()
|
rows, cols := id.Size()
|
||||||
assert.Equal(5, rows)
|
testutil.AssertEqual(t, 5, rows)
|
||||||
assert.Equal(5, cols)
|
testutil.AssertEqual(t, 5, cols)
|
||||||
assert.Equal(1, id.Get(0, 0))
|
testutil.AssertEqual(t, 1, id.Get(0, 0))
|
||||||
assert.Equal(1, id.Get(1, 1))
|
testutil.AssertEqual(t, 1, id.Get(1, 1))
|
||||||
assert.Equal(1, id.Get(2, 2))
|
testutil.AssertEqual(t, 1, id.Get(2, 2))
|
||||||
assert.Equal(1, id.Get(3, 3))
|
testutil.AssertEqual(t, 1, id.Get(3, 3))
|
||||||
assert.Equal(1, id.Get(4, 4))
|
testutil.AssertEqual(t, 1, id.Get(4, 4))
|
||||||
assert.Equal(0, id.Get(0, 1))
|
testutil.AssertEqual(t, 0, id.Get(0, 1))
|
||||||
assert.Equal(0, id.Get(1, 0))
|
testutil.AssertEqual(t, 0, id.Get(1, 0))
|
||||||
assert.Equal(0, id.Get(4, 0))
|
testutil.AssertEqual(t, 0, id.Get(4, 0))
|
||||||
assert.Equal(0, id.Get(0, 4))
|
testutil.AssertEqual(t, 0, id.Get(0, 4))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewFromArrays(t *testing.T) {
|
func TestNewFromArrays(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 2, 3, 4},
|
{1, 2, 3, 4},
|
||||||
{5, 6, 7, 8},
|
{5, 6, 7, 8},
|
||||||
})
|
})
|
||||||
assert.NotNil(m)
|
testutil.AssertNotNil(t, m)
|
||||||
|
|
||||||
rows, cols := m.Size()
|
rows, cols := m.Size()
|
||||||
assert.Equal(2, rows)
|
testutil.AssertEqual(t, 2, rows)
|
||||||
assert.Equal(4, cols)
|
testutil.AssertEqual(t, 4, cols)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOnes(t *testing.T) {
|
func TestOnes(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
ones := Ones(5, 10)
|
ones := Ones(5, 10)
|
||||||
rows, cols := ones.Size()
|
rows, cols := ones.Size()
|
||||||
assert.Equal(5, rows)
|
testutil.AssertEqual(t, 5, rows)
|
||||||
assert.Equal(10, cols)
|
testutil.AssertEqual(t, 10, cols)
|
||||||
|
|
||||||
for row := 0; row < rows; row++ {
|
for row := 0; row < rows; row++ {
|
||||||
for col := 0; col < cols; col++ {
|
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) {
|
func TestMatrixEpsilon(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
ones := Ones(2, 2)
|
ones := Ones(2, 2)
|
||||||
ones = ones.WithEpsilon(0.001)
|
ones = ones.WithEpsilon(0.001)
|
||||||
assert.Equal(0.001, ones.Epsilon())
|
testutil.AssertEqual(t, 0.001, ones.Epsilon())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixArrays(t *testing.T) {
|
func TestMatrixArrays(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
{4, 5, 6},
|
{4, 5, 6},
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NotNil(m)
|
testutil.AssertNotNil(t, m)
|
||||||
|
|
||||||
arrays := m.Arrays()
|
arrays := m.Arrays()
|
||||||
|
|
||||||
assert.Equal(arrays, [][]float64{
|
testutil.AssertEqual(t, arrays, [][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
{4, 5, 6},
|
{4, 5, 6},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixIsSquare(t *testing.T) {
|
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},
|
{1, 2, 3},
|
||||||
{4, 5, 6},
|
{4, 5, 6},
|
||||||
}).IsSquare())
|
}).IsSquare())
|
||||||
|
|
||||||
assert.False(NewFromArrays([][]float64{
|
testutil.AssertFalse(t, NewFromArrays([][]float64{
|
||||||
{1, 2},
|
{1, 2},
|
||||||
{3, 4},
|
{3, 4},
|
||||||
{5, 6},
|
{5, 6},
|
||||||
}).IsSquare())
|
}).IsSquare())
|
||||||
|
|
||||||
assert.True(NewFromArrays([][]float64{
|
testutil.AssertTrue(t, NewFromArrays([][]float64{
|
||||||
{1, 2},
|
{1, 2},
|
||||||
{3, 4},
|
{3, 4},
|
||||||
}).IsSquare())
|
}).IsSquare())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixIsSymmetric(t *testing.T) {
|
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},
|
{1, 2, 3},
|
||||||
{2, 1, 2},
|
{2, 1, 2},
|
||||||
}).IsSymmetric())
|
}).IsSymmetric())
|
||||||
|
|
||||||
assert.False(NewFromArrays([][]float64{
|
testutil.AssertFalse(t, NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
{4, 5, 6},
|
{4, 5, 6},
|
||||||
{7, 8, 9},
|
{7, 8, 9},
|
||||||
}).IsSymmetric())
|
}).IsSymmetric())
|
||||||
|
|
||||||
assert.True(NewFromArrays([][]float64{
|
testutil.AssertTrue(t, NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
{2, 1, 2},
|
{2, 1, 2},
|
||||||
{3, 2, 1},
|
{3, 2, 1},
|
||||||
|
@ -144,7 +144,7 @@ func TestMatrixIsSymmetric(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixGet(t *testing.T) {
|
func TestMatrixGet(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
|
@ -152,19 +152,19 @@ func TestMatrixGet(t *testing.T) {
|
||||||
{7, 8, 9},
|
{7, 8, 9},
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.Equal(1, m.Get(0, 0))
|
testutil.AssertEqual(t, 1, m.Get(0, 0))
|
||||||
assert.Equal(2, m.Get(0, 1))
|
testutil.AssertEqual(t, 2, m.Get(0, 1))
|
||||||
assert.Equal(3, m.Get(0, 2))
|
testutil.AssertEqual(t, 3, m.Get(0, 2))
|
||||||
assert.Equal(4, m.Get(1, 0))
|
testutil.AssertEqual(t, 4, m.Get(1, 0))
|
||||||
assert.Equal(5, m.Get(1, 1))
|
testutil.AssertEqual(t, 5, m.Get(1, 1))
|
||||||
assert.Equal(6, m.Get(1, 2))
|
testutil.AssertEqual(t, 6, m.Get(1, 2))
|
||||||
assert.Equal(7, m.Get(2, 0))
|
testutil.AssertEqual(t, 7, m.Get(2, 0))
|
||||||
assert.Equal(8, m.Get(2, 1))
|
testutil.AssertEqual(t, 8, m.Get(2, 1))
|
||||||
assert.Equal(9, m.Get(2, 2))
|
testutil.AssertEqual(t, 9, m.Get(2, 2))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixSet(t *testing.T) {
|
func TestMatrixSet(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
|
@ -173,11 +173,11 @@ func TestMatrixSet(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Set(1, 1, 99)
|
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) {
|
func TestMatrixCol(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
|
@ -185,13 +185,13 @@ func TestMatrixCol(t *testing.T) {
|
||||||
{7, 8, 9},
|
{7, 8, 9},
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.Equal([]float64{1, 4, 7}, m.Col(0))
|
testutil.AssertEqual(t, []float64{1, 4, 7}, m.Col(0))
|
||||||
assert.Equal([]float64{2, 5, 8}, m.Col(1))
|
testutil.AssertEqual(t, []float64{2, 5, 8}, m.Col(1))
|
||||||
assert.Equal([]float64{3, 6, 9}, m.Col(2))
|
testutil.AssertEqual(t, []float64{3, 6, 9}, m.Col(2))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixRow(t *testing.T) {
|
func TestMatrixRow(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
|
@ -199,13 +199,13 @@ func TestMatrixRow(t *testing.T) {
|
||||||
{7, 8, 9},
|
{7, 8, 9},
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.Equal([]float64{1, 2, 3}, m.Row(0))
|
testutil.AssertEqual(t, []float64{1, 2, 3}, m.Row(0))
|
||||||
assert.Equal([]float64{4, 5, 6}, m.Row(1))
|
testutil.AssertEqual(t, []float64{4, 5, 6}, m.Row(1))
|
||||||
assert.Equal([]float64{7, 8, 9}, m.Row(2))
|
testutil.AssertEqual(t, []float64{7, 8, 9}, m.Row(2))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixSwapRows(t *testing.T) {
|
func TestMatrixSwapRows(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
|
@ -215,13 +215,13 @@ func TestMatrixSwapRows(t *testing.T) {
|
||||||
|
|
||||||
m.SwapRows(0, 1)
|
m.SwapRows(0, 1)
|
||||||
|
|
||||||
assert.Equal([]float64{4, 5, 6}, m.Row(0))
|
testutil.AssertEqual(t, []float64{4, 5, 6}, m.Row(0))
|
||||||
assert.Equal([]float64{1, 2, 3}, m.Row(1))
|
testutil.AssertEqual(t, []float64{1, 2, 3}, m.Row(1))
|
||||||
assert.Equal([]float64{7, 8, 9}, m.Row(2))
|
testutil.AssertEqual(t, []float64{7, 8, 9}, m.Row(2))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixCopy(t *testing.T) {
|
func TestMatrixCopy(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
|
@ -230,12 +230,12 @@ func TestMatrixCopy(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
m2 := m.Copy()
|
m2 := m.Copy()
|
||||||
assert.False(m == m2)
|
testutil.AssertFalse(t, m == m2)
|
||||||
assert.True(m.Equals(m2))
|
testutil.AssertTrue(t, m.Equals(m2))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixDiagonalVector(t *testing.T) {
|
func TestMatrixDiagonalVector(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 4, 7},
|
{1, 4, 7},
|
||||||
|
@ -244,11 +244,11 @@ func TestMatrixDiagonalVector(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
diag := m.DiagonalVector()
|
diag := m.DiagonalVector()
|
||||||
assert.Equal([]float64{1, 2, 3}, diag)
|
testutil.AssertEqual(t, []float64{1, 2, 3}, diag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixDiagonalVectorLandscape(t *testing.T) {
|
func TestMatrixDiagonalVectorLandscape(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 4, 7, 99},
|
{1, 4, 7, 99},
|
||||||
|
@ -256,11 +256,11 @@ func TestMatrixDiagonalVectorLandscape(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
diag := m.DiagonalVector()
|
diag := m.DiagonalVector()
|
||||||
assert.Equal([]float64{1, 2}, diag)
|
testutil.AssertEqual(t, []float64{1, 2}, diag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixDiagonalVectorPortrait(t *testing.T) {
|
func TestMatrixDiagonalVectorPortrait(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 4},
|
{1, 4},
|
||||||
|
@ -269,11 +269,11 @@ func TestMatrixDiagonalVectorPortrait(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
diag := m.DiagonalVector()
|
diag := m.DiagonalVector()
|
||||||
assert.Equal([]float64{1, 2}, diag)
|
testutil.AssertEqual(t, []float64{1, 2}, diag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixDiagonal(t *testing.T) {
|
func TestMatrixDiagonal(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 4, 7},
|
{1, 4, 7},
|
||||||
|
@ -287,11 +287,11 @@ func TestMatrixDiagonal(t *testing.T) {
|
||||||
{0, 0, 3},
|
{0, 0, 3},
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.True(m.Diagonal().Equals(m2))
|
testutil.AssertTrue(t, m.Diagonal().Equals(m2))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixEquals(t *testing.T) {
|
func TestMatrixEquals(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 4, 7},
|
{1, 4, 7},
|
||||||
|
@ -299,16 +299,16 @@ func TestMatrixEquals(t *testing.T) {
|
||||||
{7, 8, 3},
|
{7, 8, 3},
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.False(m.Equals(nil))
|
testutil.AssertFalse(t, m.Equals(nil))
|
||||||
var nilMatrix *Matrix
|
var nilMatrix *Matrix
|
||||||
assert.True(nilMatrix.Equals(nil))
|
testutil.AssertTrue(t, nilMatrix.Equals(nil))
|
||||||
assert.False(m.Equals(New(1, 1)))
|
testutil.AssertFalse(t, m.Equals(New(1, 1)))
|
||||||
assert.False(m.Equals(New(3, 3)))
|
testutil.AssertFalse(t, m.Equals(New(3, 3)))
|
||||||
assert.True(m.Equals(New(3, 3, 1, 4, 7, 4, 2, 8, 7, 8, 3)))
|
testutil.AssertTrue(t, m.Equals(New(3, 3, 1, 4, 7, 4, 2, 8, 7, 8, 3)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixL(t *testing.T) {
|
func TestMatrixL(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
|
@ -317,11 +317,11 @@ func TestMatrixL(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
l := m.L()
|
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) {
|
func TestMatrixU(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
|
@ -330,11 +330,11 @@ func TestMatrixU(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
u := m.U()
|
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) {
|
func TestMatrixString(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
|
@ -342,11 +342,11 @@ func TestMatrixString(t *testing.T) {
|
||||||
{7, 8, 9},
|
{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) {
|
func TestMatrixLU(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 3, 5},
|
{1, 3, 5},
|
||||||
|
@ -355,13 +355,13 @@ func TestMatrixLU(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
l, u, p := m.LU()
|
l, u, p := m.LU()
|
||||||
assert.NotNil(l)
|
testutil.AssertNotNil(t, l)
|
||||||
assert.NotNil(u)
|
testutil.AssertNotNil(t, u)
|
||||||
assert.NotNil(p)
|
testutil.AssertNotNil(t, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixQR(t *testing.T) {
|
func TestMatrixQR(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{12, -51, 4},
|
{12, -51, 4},
|
||||||
|
@ -370,12 +370,12 @@ func TestMatrixQR(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
q, r := m.QR()
|
q, r := m.QR()
|
||||||
assert.NotNil(q)
|
testutil.AssertNotNil(t, q)
|
||||||
assert.NotNil(r)
|
testutil.AssertNotNil(t, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatrixTranspose(t *testing.T) {
|
func TestMatrixTranspose(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
m := NewFromArrays([][]float64{
|
m := NewFromArrays([][]float64{
|
||||||
{1, 2, 3},
|
{1, 2, 3},
|
||||||
|
@ -387,10 +387,10 @@ func TestMatrixTranspose(t *testing.T) {
|
||||||
m2 := m.Transpose()
|
m2 := m.Transpose()
|
||||||
|
|
||||||
rows, cols := m2.Size()
|
rows, cols := m2.Size()
|
||||||
assert.Equal(3, rows)
|
testutil.AssertEqual(t, 3, rows)
|
||||||
assert.Equal(4, cols)
|
testutil.AssertEqual(t, 4, cols)
|
||||||
|
|
||||||
assert.Equal(1, m2.Get(0, 0))
|
testutil.AssertEqual(t, 1, m2.Get(0, 0))
|
||||||
assert.Equal(10, m2.Get(0, 3))
|
testutil.AssertEqual(t, 10, m2.Get(0, 3))
|
||||||
assert.Equal(3, m2.Get(2, 0))
|
testutil.AssertEqual(t, 3, m2.Get(2, 0))
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,20 +3,20 @@ package matrix
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPoly(t *testing.T) {
|
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 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 yGiven = []float64{1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321}
|
||||||
var degree = 2
|
var degree = 2
|
||||||
|
|
||||||
c, err := Poly(xGiven, yGiven, degree)
|
c, err := Poly(xGiven, yGiven, degree)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
assert.Len(c, 3)
|
testutil.AssertLen(t, c, 3)
|
||||||
|
|
||||||
assert.InDelta(c[0], 0.999999999, DefaultEpsilon)
|
testutil.AssertInDelta(t, c[0], 0.999999999, DefaultEpsilon)
|
||||||
assert.InDelta(c[1], 2, DefaultEpsilon)
|
testutil.AssertInDelta(t, c[1], 2, DefaultEpsilon)
|
||||||
assert.InDelta(c[2], 3, DefaultEpsilon)
|
testutil.AssertInDelta(t, c[2], 3, DefaultEpsilon)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,11 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPercentageDifferenceSeries(t *testing.T) {
|
func TestPercentageDifferenceSeries(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
cs := ContinuousSeries{
|
cs := ContinuousSeries{
|
||||||
XValues: LinearRange(1.0, 10.0),
|
XValues: LinearRange(1.0, 10.0),
|
||||||
|
@ -19,17 +19,17 @@ func TestPercentageDifferenceSeries(t *testing.T) {
|
||||||
InnerSeries: cs,
|
InnerSeries: cs,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal("Test Series", pcs.GetName())
|
testutil.AssertEqual(t, "Test Series", pcs.GetName())
|
||||||
assert.Equal(10, pcs.Len())
|
testutil.AssertEqual(t, 10, pcs.Len())
|
||||||
x0, y0 := pcs.GetValues(0)
|
x0, y0 := pcs.GetValues(0)
|
||||||
assert.Equal(1.0, x0)
|
testutil.AssertEqual(t, 1.0, x0)
|
||||||
assert.Equal(0, y0)
|
testutil.AssertEqual(t, 0, y0)
|
||||||
|
|
||||||
xn, yn := pcs.GetValues(9)
|
xn, yn := pcs.GetValues(9)
|
||||||
assert.Equal(10.0, xn)
|
testutil.AssertEqual(t, 10.0, xn)
|
||||||
assert.Equal(9.0, yn)
|
testutil.AssertEqual(t, 9.0, yn)
|
||||||
|
|
||||||
xn, yn = pcs.GetLastValues()
|
xn, yn = pcs.GetLastValues()
|
||||||
assert.Equal(10.0, xn)
|
testutil.AssertEqual(t, 10.0, xn)
|
||||||
assert.Equal(9.0, yn)
|
testutil.AssertEqual(t, 9.0, yn)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPieChart(t *testing.T) {
|
func TestPieChart(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
pie := PieChart{
|
pie := PieChart{
|
||||||
Canvas: Style{
|
Canvas: Style{
|
||||||
|
@ -27,11 +27,11 @@ func TestPieChart(t *testing.T) {
|
||||||
|
|
||||||
b := bytes.NewBuffer([]byte{})
|
b := bytes.NewBuffer([]byte{})
|
||||||
pie.Render(PNG, b)
|
pie.Render(PNG, b)
|
||||||
assert.NotZero(b.Len())
|
testutil.AssertNotZero(t, b.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPieChartDropsZeroValues(t *testing.T) {
|
func TestPieChartDropsZeroValues(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
pie := PieChart{
|
pie := PieChart{
|
||||||
Canvas: Style{
|
Canvas: Style{
|
||||||
|
@ -46,11 +46,11 @@ func TestPieChartDropsZeroValues(t *testing.T) {
|
||||||
|
|
||||||
b := bytes.NewBuffer([]byte{})
|
b := bytes.NewBuffer([]byte{})
|
||||||
err := pie.Render(PNG, b)
|
err := pie.Render(PNG, b)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPieChartAllZeroValues(t *testing.T) {
|
func TestPieChartAllZeroValues(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
pie := PieChart{
|
pie := PieChart{
|
||||||
Canvas: Style{
|
Canvas: Style{
|
||||||
|
@ -65,5 +65,5 @@ func TestPieChartAllZeroValues(t *testing.T) {
|
||||||
|
|
||||||
b := bytes.NewBuffer([]byte{})
|
b := bytes.NewBuffer([]byte{})
|
||||||
err := pie.Render(PNG, b)
|
err := pie.Render(PNG, b)
|
||||||
assert.NotNil(err)
|
testutil.AssertNotNil(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart/matrix"
|
"github.com/wcharczuk/go-chart/v2/matrix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Interface Assertions.
|
// Interface Assertions.
|
||||||
|
|
|
@ -3,12 +3,12 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/matrix"
|
||||||
"github.com/wcharczuk/go-chart/matrix"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPolynomialRegression(t *testing.T) {
|
func TestPolynomialRegression(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
var xv []float64
|
var xv []float64
|
||||||
var yv []float64
|
var yv []float64
|
||||||
|
@ -30,6 +30,6 @@ func TestPolynomialRegression(t *testing.T) {
|
||||||
|
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
_, y := poly.GetValues(i)
|
_, y := poly.GetValues(i)
|
||||||
assert.InDelta(float64(i*i), y, matrix.DefaultEpsilon)
|
testutil.AssertInDelta(t, float64(i*i), y, matrix.DefaultEpsilon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"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.
|
// PNG returns a new png/raster renderer.
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"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.
|
// Renderer represents the basic methods required to draw a chart.
|
||||||
|
|
86
seq_test.go
86
seq_test.go
|
@ -3,134 +3,134 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSeqEach(t *testing.T) {
|
func TestSeqEach(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
values := Seq{NewArray(1, 2, 3, 4)}
|
values := Seq{NewArray(1, 2, 3, 4)}
|
||||||
values.Each(func(i int, v float64) {
|
values.Each(func(i int, v float64) {
|
||||||
assert.Equal(i, v-1)
|
testutil.AssertEqual(t, i, v-1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSeqMap(t *testing.T) {
|
func TestSeqMap(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
values := Seq{NewArray(1, 2, 3, 4)}
|
values := Seq{NewArray(1, 2, 3, 4)}
|
||||||
mapped := values.Map(func(i int, v float64) float64 {
|
mapped := values.Map(func(i int, v float64) float64 {
|
||||||
assert.Equal(i, v-1)
|
testutil.AssertEqual(t, i, v-1)
|
||||||
return v * 2
|
return v * 2
|
||||||
})
|
})
|
||||||
assert.Equal(4, mapped.Len())
|
testutil.AssertEqual(t, 4, mapped.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSeqFoldLeft(t *testing.T) {
|
func TestSeqFoldLeft(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
values := Seq{NewArray(1, 2, 3, 4)}
|
values := Seq{NewArray(1, 2, 3, 4)}
|
||||||
ten := values.FoldLeft(func(_ int, vp, v float64) float64 {
|
ten := values.FoldLeft(func(_ int, vp, v float64) float64 {
|
||||||
return vp + v
|
return vp + v
|
||||||
})
|
})
|
||||||
assert.Equal(10, ten)
|
testutil.AssertEqual(t, 10, ten)
|
||||||
|
|
||||||
orderTest := Seq{NewArray(10, 3, 2, 1)}
|
orderTest := Seq{NewArray(10, 3, 2, 1)}
|
||||||
four := orderTest.FoldLeft(func(_ int, vp, v float64) float64 {
|
four := orderTest.FoldLeft(func(_ int, vp, v float64) float64 {
|
||||||
return vp - v
|
return vp - v
|
||||||
})
|
})
|
||||||
assert.Equal(4, four)
|
testutil.AssertEqual(t, 4, four)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSeqFoldRight(t *testing.T) {
|
func TestSeqFoldRight(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
values := Seq{NewArray(1, 2, 3, 4)}
|
values := Seq{NewArray(1, 2, 3, 4)}
|
||||||
ten := values.FoldRight(func(_ int, vp, v float64) float64 {
|
ten := values.FoldRight(func(_ int, vp, v float64) float64 {
|
||||||
return vp + v
|
return vp + v
|
||||||
})
|
})
|
||||||
assert.Equal(10, ten)
|
testutil.AssertEqual(t, 10, ten)
|
||||||
|
|
||||||
orderTest := Seq{NewArray(10, 3, 2, 1)}
|
orderTest := Seq{NewArray(10, 3, 2, 1)}
|
||||||
notFour := orderTest.FoldRight(func(_ int, vp, v float64) float64 {
|
notFour := orderTest.FoldRight(func(_ int, vp, v float64) float64 {
|
||||||
return vp - v
|
return vp - v
|
||||||
})
|
})
|
||||||
assert.Equal(-14, notFour)
|
testutil.AssertEqual(t, -14, notFour)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSeqSum(t *testing.T) {
|
func TestSeqSum(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
values := Seq{NewArray(1, 2, 3, 4)}
|
values := Seq{NewArray(1, 2, 3, 4)}
|
||||||
assert.Equal(10, values.Sum())
|
testutil.AssertEqual(t, 10, values.Sum())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSeqAverage(t *testing.T) {
|
func TestSeqAverage(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
values := Seq{NewArray(1, 2, 3, 4)}
|
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)}
|
valuesOdd := Seq{NewArray(1, 2, 3, 4, 5)}
|
||||||
assert.Equal(3, valuesOdd.Average())
|
testutil.AssertEqual(t, 3, valuesOdd.Average())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSequenceVariance(t *testing.T) {
|
func TestSequenceVariance(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
values := Seq{NewArray(1, 2, 3, 4, 5)}
|
values := Seq{NewArray(1, 2, 3, 4, 5)}
|
||||||
assert.Equal(2, values.Variance())
|
testutil.AssertEqual(t, 2, values.Variance())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSequenceNormalize(t *testing.T) {
|
func TestSequenceNormalize(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
normalized := ValueSequence(1, 2, 3, 4, 5).Normalize().Values()
|
normalized := ValueSequence(1, 2, 3, 4, 5).Normalize().Values()
|
||||||
|
|
||||||
assert.NotEmpty(normalized)
|
testutil.AssertNotEmpty(t, normalized)
|
||||||
assert.Len(normalized, 5)
|
testutil.AssertLen(t, normalized, 5)
|
||||||
assert.Equal(0, normalized[0])
|
testutil.AssertEqual(t, 0, normalized[0])
|
||||||
assert.Equal(0.25, normalized[1])
|
testutil.AssertEqual(t, 0.25, normalized[1])
|
||||||
assert.Equal(1, normalized[4])
|
testutil.AssertEqual(t, 1, normalized[4])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLinearRange(t *testing.T) {
|
func TestLinearRange(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
values := LinearRange(1, 100)
|
values := LinearRange(1, 100)
|
||||||
assert.Len(values, 100)
|
testutil.AssertLen(t, values, 100)
|
||||||
assert.Equal(1, values[0])
|
testutil.AssertEqual(t, 1, values[0])
|
||||||
assert.Equal(100, values[99])
|
testutil.AssertEqual(t, 100, values[99])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLinearRangeWithStep(t *testing.T) {
|
func TestLinearRangeWithStep(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
values := LinearRangeWithStep(0, 100, 5)
|
values := LinearRangeWithStep(0, 100, 5)
|
||||||
assert.Equal(100, values[20])
|
testutil.AssertEqual(t, 100, values[20])
|
||||||
assert.Len(values, 21)
|
testutil.AssertLen(t, values, 21)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLinearRangeReversed(t *testing.T) {
|
func TestLinearRangeReversed(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
values := LinearRange(10.0, 1.0)
|
values := LinearRange(10.0, 1.0)
|
||||||
assert.Equal(10, len(values))
|
testutil.AssertEqual(t, 10, len(values))
|
||||||
assert.Equal(10.0, values[0])
|
testutil.AssertEqual(t, 10.0, values[0])
|
||||||
assert.Equal(1.0, values[9])
|
testutil.AssertEqual(t, 1.0, values[9])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLinearSequenceRegression(t *testing.T) {
|
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.
|
// note; this assumes a 1.0 step is implicitly set in the constructor.
|
||||||
linearProvider := NewLinearSequence().WithStart(1.0).WithEnd(100.0)
|
linearProvider := NewLinearSequence().WithStart(1.0).WithEnd(100.0)
|
||||||
assert.Equal(1, linearProvider.Start())
|
testutil.AssertEqual(t, 1, linearProvider.Start())
|
||||||
assert.Equal(100, linearProvider.End())
|
testutil.AssertEqual(t, 100, linearProvider.End())
|
||||||
assert.Equal(100, linearProvider.Len())
|
testutil.AssertEqual(t, 100, linearProvider.Len())
|
||||||
|
|
||||||
values := Seq{linearProvider}.Values()
|
values := Seq{linearProvider}.Values()
|
||||||
assert.Len(values, 100)
|
testutil.AssertLen(t, values, 100)
|
||||||
assert.Equal(1.0, values[0])
|
testutil.AssertEqual(t, 1.0, values[0])
|
||||||
assert.Equal(100, values[99])
|
testutil.AssertEqual(t, 100, values[99])
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mockValuesProvider struct {
|
type mockValuesProvider struct {
|
||||||
|
@ -28,13 +28,13 @@ func (m mockValuesProvider) GetValues(index int) (x, y float64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSMASeriesGetValue(t *testing.T) {
|
func TestSMASeriesGetValue(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
mockSeries := mockValuesProvider{
|
mockSeries := mockValuesProvider{
|
||||||
LinearRange(1.0, 10.0),
|
LinearRange(1.0, 10.0),
|
||||||
LinearRange(10, 1.0),
|
LinearRange(10, 1.0),
|
||||||
}
|
}
|
||||||
assert.Equal(10, mockSeries.Len())
|
testutil.AssertEqual(t, 10, mockSeries.Len())
|
||||||
|
|
||||||
mas := &SMASeries{
|
mas := &SMASeries{
|
||||||
InnerSeries: mockSeries,
|
InnerSeries: mockSeries,
|
||||||
|
@ -47,25 +47,25 @@ func TestSMASeriesGetValue(t *testing.T) {
|
||||||
yvalues = append(yvalues, y)
|
yvalues = append(yvalues, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(10.0, yvalues[0])
|
testutil.AssertEqual(t, 10.0, yvalues[0])
|
||||||
assert.Equal(9.5, yvalues[1])
|
testutil.AssertEqual(t, 9.5, yvalues[1])
|
||||||
assert.Equal(9.0, yvalues[2])
|
testutil.AssertEqual(t, 9.0, yvalues[2])
|
||||||
assert.Equal(8.5, yvalues[3])
|
testutil.AssertEqual(t, 8.5, yvalues[3])
|
||||||
assert.Equal(8.0, yvalues[4])
|
testutil.AssertEqual(t, 8.0, yvalues[4])
|
||||||
assert.Equal(7.5, yvalues[5])
|
testutil.AssertEqual(t, 7.5, yvalues[5])
|
||||||
assert.Equal(7.0, yvalues[6])
|
testutil.AssertEqual(t, 7.0, yvalues[6])
|
||||||
assert.Equal(6.5, yvalues[7])
|
testutil.AssertEqual(t, 6.5, yvalues[7])
|
||||||
assert.Equal(6.0, yvalues[8])
|
testutil.AssertEqual(t, 6.0, yvalues[8])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSMASeriesGetLastValueWindowOverlap(t *testing.T) {
|
func TestSMASeriesGetLastValueWindowOverlap(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
mockSeries := mockValuesProvider{
|
mockSeries := mockValuesProvider{
|
||||||
LinearRange(1.0, 10.0),
|
LinearRange(1.0, 10.0),
|
||||||
LinearRange(10, 1.0),
|
LinearRange(10, 1.0),
|
||||||
}
|
}
|
||||||
assert.Equal(10, mockSeries.Len())
|
testutil.AssertEqual(t, 10, mockSeries.Len())
|
||||||
|
|
||||||
mas := &SMASeries{
|
mas := &SMASeries{
|
||||||
InnerSeries: mockSeries,
|
InnerSeries: mockSeries,
|
||||||
|
@ -79,19 +79,19 @@ func TestSMASeriesGetLastValueWindowOverlap(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
lx, ly := mas.GetLastValues()
|
lx, ly := mas.GetLastValues()
|
||||||
assert.Equal(10.0, lx)
|
testutil.AssertEqual(t, 10.0, lx)
|
||||||
assert.Equal(5.5, ly)
|
testutil.AssertEqual(t, 5.5, ly)
|
||||||
assert.Equal(yvalues[len(yvalues)-1], ly)
|
testutil.AssertEqual(t, yvalues[len(yvalues)-1], ly)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSMASeriesGetLastValue(t *testing.T) {
|
func TestSMASeriesGetLastValue(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
mockSeries := mockValuesProvider{
|
mockSeries := mockValuesProvider{
|
||||||
LinearRange(1.0, 100.0),
|
LinearRange(1.0, 100.0),
|
||||||
LinearRange(100, 1.0),
|
LinearRange(100, 1.0),
|
||||||
}
|
}
|
||||||
assert.Equal(100, mockSeries.Len())
|
testutil.AssertEqual(t, 100, mockSeries.Len())
|
||||||
|
|
||||||
mas := &SMASeries{
|
mas := &SMASeries{
|
||||||
InnerSeries: mockSeries,
|
InnerSeries: mockSeries,
|
||||||
|
@ -105,7 +105,7 @@ func TestSMASeriesGetLastValue(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
lx, ly := mas.GetLastValues()
|
lx, ly := mas.GetLastValues()
|
||||||
assert.Equal(100.0, lx)
|
testutil.AssertEqual(t, 100.0, lx)
|
||||||
assert.Equal(6, ly)
|
testutil.AssertEqual(t, 6, ly)
|
||||||
assert.Equal(yvalues[len(yvalues)-1], ly)
|
testutil.AssertEqual(t, yvalues[len(yvalues)-1], ly)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,20 +3,20 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSplitCSV(t *testing.T) {
|
func TestSplitCSV(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
assert.Empty(SplitCSV(""))
|
testutil.AssertEmpty(t, SplitCSV(""))
|
||||||
assert.Equal([]string{"foo"}, SplitCSV("foo"))
|
testutil.AssertEqual(t, []string{"foo"}, SplitCSV("foo"))
|
||||||
assert.Equal([]string{"foo", "bar"}, SplitCSV("foo,bar"))
|
testutil.AssertEqual(t, []string{"foo", "bar"}, SplitCSV("foo,bar"))
|
||||||
assert.Equal([]string{"foo", "bar"}, SplitCSV("foo, bar"))
|
testutil.AssertEqual(t, []string{"foo", "bar"}, SplitCSV("foo, bar"))
|
||||||
assert.Equal([]string{"foo", "bar"}, SplitCSV(" foo , bar "))
|
testutil.AssertEqual(t, []string{"foo", "bar"}, SplitCSV(" foo , bar "))
|
||||||
assert.Equal([]string{"foo", "bar", "baz"}, SplitCSV("foo,bar,baz"))
|
testutil.AssertEqual(t, []string{"foo", "bar", "baz"}, SplitCSV("foo,bar,baz"))
|
||||||
assert.Equal([]string{"foo", "bar", "baz,buzz"}, SplitCSV("foo,bar,\"baz,buzz\""))
|
testutil.AssertEqual(t, []string{"foo", "bar", "baz,buzz"}, SplitCSV("foo,bar,\"baz,buzz\""))
|
||||||
assert.Equal([]string{"foo", "bar", "baz,'buzz'"}, SplitCSV("foo,bar,\"baz,'buzz'\""))
|
testutil.AssertEqual(t, []string{"foo", "bar", "baz,'buzz'"}, SplitCSV("foo,bar,\"baz,'buzz'\""))
|
||||||
assert.Equal([]string{"foo", "bar", "baz,'buzz"}, SplitCSV("foo,bar,\"baz,'buzz\""))
|
testutil.AssertEqual(t, []string{"foo", "bar", "baz,'buzz"}, SplitCSV("foo,bar,\"baz,'buzz\""))
|
||||||
assert.Equal([]string{"foo", "bar", "baz,\"buzz\""}, SplitCSV("foo,bar,'baz,\"buzz\"'"))
|
testutil.AssertEqual(t, []string{"foo", "bar", "baz,\"buzz\""}, SplitCSV("foo,bar,'baz,\"buzz\"'"))
|
||||||
}
|
}
|
||||||
|
|
2
style.go
2
style.go
|
@ -5,7 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
140
style_test.go
140
style_test.go
|
@ -3,121 +3,121 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
|
||||||
"github.com/golang/freetype/truetype"
|
"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) {
|
func TestStyleIsZero(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
zero := Style{}
|
zero := Style{}
|
||||||
assert.True(zero.IsZero())
|
testutil.AssertTrue(t, zero.IsZero())
|
||||||
|
|
||||||
strokeColor := Style{StrokeColor: drawing.ColorWhite}
|
strokeColor := Style{StrokeColor: drawing.ColorWhite}
|
||||||
assert.False(strokeColor.IsZero())
|
testutil.AssertFalse(t, strokeColor.IsZero())
|
||||||
|
|
||||||
fillColor := Style{FillColor: drawing.ColorWhite}
|
fillColor := Style{FillColor: drawing.ColorWhite}
|
||||||
assert.False(fillColor.IsZero())
|
testutil.AssertFalse(t, fillColor.IsZero())
|
||||||
|
|
||||||
strokeWidth := Style{StrokeWidth: 5.0}
|
strokeWidth := Style{StrokeWidth: 5.0}
|
||||||
assert.False(strokeWidth.IsZero())
|
testutil.AssertFalse(t, strokeWidth.IsZero())
|
||||||
|
|
||||||
fontSize := Style{FontSize: 12.0}
|
fontSize := Style{FontSize: 12.0}
|
||||||
assert.False(fontSize.IsZero())
|
testutil.AssertFalse(t, fontSize.IsZero())
|
||||||
|
|
||||||
fontColor := Style{FontColor: drawing.ColorWhite}
|
fontColor := Style{FontColor: drawing.ColorWhite}
|
||||||
assert.False(fontColor.IsZero())
|
testutil.AssertFalse(t, fontColor.IsZero())
|
||||||
|
|
||||||
font := Style{Font: &truetype.Font{}}
|
font := Style{Font: &truetype.Font{}}
|
||||||
assert.False(font.IsZero())
|
testutil.AssertFalse(t, font.IsZero())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStyleGetStrokeColor(t *testing.T) {
|
func TestStyleGetStrokeColor(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
unset := Style{}
|
unset := Style{}
|
||||||
assert.Equal(drawing.ColorTransparent, unset.GetStrokeColor())
|
testutil.AssertEqual(t, drawing.ColorTransparent, unset.GetStrokeColor())
|
||||||
assert.Equal(drawing.ColorWhite, unset.GetStrokeColor(drawing.ColorWhite))
|
testutil.AssertEqual(t, drawing.ColorWhite, unset.GetStrokeColor(drawing.ColorWhite))
|
||||||
|
|
||||||
set := Style{StrokeColor: drawing.ColorWhite}
|
set := Style{StrokeColor: drawing.ColorWhite}
|
||||||
assert.Equal(drawing.ColorWhite, set.GetStrokeColor())
|
testutil.AssertEqual(t, drawing.ColorWhite, set.GetStrokeColor())
|
||||||
assert.Equal(drawing.ColorWhite, set.GetStrokeColor(drawing.ColorBlack))
|
testutil.AssertEqual(t, drawing.ColorWhite, set.GetStrokeColor(drawing.ColorBlack))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStyleGetFillColor(t *testing.T) {
|
func TestStyleGetFillColor(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
unset := Style{}
|
unset := Style{}
|
||||||
assert.Equal(drawing.ColorTransparent, unset.GetFillColor())
|
testutil.AssertEqual(t, drawing.ColorTransparent, unset.GetFillColor())
|
||||||
assert.Equal(drawing.ColorWhite, unset.GetFillColor(drawing.ColorWhite))
|
testutil.AssertEqual(t, drawing.ColorWhite, unset.GetFillColor(drawing.ColorWhite))
|
||||||
|
|
||||||
set := Style{FillColor: drawing.ColorWhite}
|
set := Style{FillColor: drawing.ColorWhite}
|
||||||
assert.Equal(drawing.ColorWhite, set.GetFillColor())
|
testutil.AssertEqual(t, drawing.ColorWhite, set.GetFillColor())
|
||||||
assert.Equal(drawing.ColorWhite, set.GetFillColor(drawing.ColorBlack))
|
testutil.AssertEqual(t, drawing.ColorWhite, set.GetFillColor(drawing.ColorBlack))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStyleGetStrokeWidth(t *testing.T) {
|
func TestStyleGetStrokeWidth(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
unset := Style{}
|
unset := Style{}
|
||||||
assert.Equal(DefaultStrokeWidth, unset.GetStrokeWidth())
|
testutil.AssertEqual(t, DefaultStrokeWidth, unset.GetStrokeWidth())
|
||||||
assert.Equal(DefaultStrokeWidth+1, unset.GetStrokeWidth(DefaultStrokeWidth+1))
|
testutil.AssertEqual(t, DefaultStrokeWidth+1, unset.GetStrokeWidth(DefaultStrokeWidth+1))
|
||||||
|
|
||||||
set := Style{StrokeWidth: DefaultStrokeWidth + 2}
|
set := Style{StrokeWidth: DefaultStrokeWidth + 2}
|
||||||
assert.Equal(DefaultStrokeWidth+2, set.GetStrokeWidth())
|
testutil.AssertEqual(t, DefaultStrokeWidth+2, set.GetStrokeWidth())
|
||||||
assert.Equal(DefaultStrokeWidth+2, set.GetStrokeWidth(DefaultStrokeWidth+1))
|
testutil.AssertEqual(t, DefaultStrokeWidth+2, set.GetStrokeWidth(DefaultStrokeWidth+1))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStyleGetFontSize(t *testing.T) {
|
func TestStyleGetFontSize(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
unset := Style{}
|
unset := Style{}
|
||||||
assert.Equal(DefaultFontSize, unset.GetFontSize())
|
testutil.AssertEqual(t, DefaultFontSize, unset.GetFontSize())
|
||||||
assert.Equal(DefaultFontSize+1, unset.GetFontSize(DefaultFontSize+1))
|
testutil.AssertEqual(t, DefaultFontSize+1, unset.GetFontSize(DefaultFontSize+1))
|
||||||
|
|
||||||
set := Style{FontSize: DefaultFontSize + 2}
|
set := Style{FontSize: DefaultFontSize + 2}
|
||||||
assert.Equal(DefaultFontSize+2, set.GetFontSize())
|
testutil.AssertEqual(t, DefaultFontSize+2, set.GetFontSize())
|
||||||
assert.Equal(DefaultFontSize+2, set.GetFontSize(DefaultFontSize+1))
|
testutil.AssertEqual(t, DefaultFontSize+2, set.GetFontSize(DefaultFontSize+1))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStyleGetFontColor(t *testing.T) {
|
func TestStyleGetFontColor(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
unset := Style{}
|
unset := Style{}
|
||||||
assert.Equal(drawing.ColorTransparent, unset.GetFontColor())
|
testutil.AssertEqual(t, drawing.ColorTransparent, unset.GetFontColor())
|
||||||
assert.Equal(drawing.ColorWhite, unset.GetFontColor(drawing.ColorWhite))
|
testutil.AssertEqual(t, drawing.ColorWhite, unset.GetFontColor(drawing.ColorWhite))
|
||||||
|
|
||||||
set := Style{FontColor: drawing.ColorWhite}
|
set := Style{FontColor: drawing.ColorWhite}
|
||||||
assert.Equal(drawing.ColorWhite, set.GetFontColor())
|
testutil.AssertEqual(t, drawing.ColorWhite, set.GetFontColor())
|
||||||
assert.Equal(drawing.ColorWhite, set.GetFontColor(drawing.ColorBlack))
|
testutil.AssertEqual(t, drawing.ColorWhite, set.GetFontColor(drawing.ColorBlack))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStyleGetFont(t *testing.T) {
|
func TestStyleGetFont(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
unset := Style{}
|
unset := Style{}
|
||||||
assert.Nil(unset.GetFont())
|
testutil.AssertNil(t, unset.GetFont())
|
||||||
assert.Equal(f, unset.GetFont(f))
|
testutil.AssertEqual(t, f, unset.GetFont(f))
|
||||||
|
|
||||||
set := Style{Font: f}
|
set := Style{Font: f}
|
||||||
assert.NotNil(set.GetFont())
|
testutil.AssertNotNil(t, set.GetFont())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStyleGetPadding(t *testing.T) {
|
func TestStyleGetPadding(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
unset := Style{}
|
unset := Style{}
|
||||||
assert.True(unset.GetPadding().IsZero())
|
testutil.AssertTrue(t, unset.GetPadding().IsZero())
|
||||||
assert.False(unset.GetPadding(DefaultBackgroundPadding).IsZero())
|
testutil.AssertFalse(t, unset.GetPadding(DefaultBackgroundPadding).IsZero())
|
||||||
assert.Equal(DefaultBackgroundPadding, unset.GetPadding(DefaultBackgroundPadding))
|
testutil.AssertEqual(t, DefaultBackgroundPadding, unset.GetPadding(DefaultBackgroundPadding))
|
||||||
|
|
||||||
set := Style{Padding: DefaultBackgroundPadding}
|
set := Style{Padding: DefaultBackgroundPadding}
|
||||||
assert.False(set.GetPadding().IsZero())
|
testutil.AssertFalse(t, set.GetPadding().IsZero())
|
||||||
assert.Equal(DefaultBackgroundPadding, set.GetPadding())
|
testutil.AssertEqual(t, DefaultBackgroundPadding, set.GetPadding())
|
||||||
assert.Equal(DefaultBackgroundPadding, set.GetPadding(Box{
|
testutil.AssertEqual(t, DefaultBackgroundPadding, set.GetPadding(Box{
|
||||||
Top: DefaultBackgroundPadding.Top + 1,
|
Top: DefaultBackgroundPadding.Top + 1,
|
||||||
Left: DefaultBackgroundPadding.Left + 1,
|
Left: DefaultBackgroundPadding.Left + 1,
|
||||||
Right: DefaultBackgroundPadding.Right + 1,
|
Right: DefaultBackgroundPadding.Right + 1,
|
||||||
|
@ -126,10 +126,10 @@ func TestStyleGetPadding(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStyleWithDefaultsFrom(t *testing.T) {
|
func TestStyleWithDefaultsFrom(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
unset := Style{}
|
unset := Style{}
|
||||||
set := Style{
|
set := Style{
|
||||||
|
@ -142,11 +142,11 @@ func TestStyleWithDefaultsFrom(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
coalesced := unset.InheritFrom(set)
|
coalesced := unset.InheritFrom(set)
|
||||||
assert.Equal(set, coalesced)
|
testutil.AssertEqual(t, set, coalesced)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStyleGetStrokeOptions(t *testing.T) {
|
func TestStyleGetStrokeOptions(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
set := Style{
|
set := Style{
|
||||||
StrokeColor: drawing.ColorWhite,
|
StrokeColor: drawing.ColorWhite,
|
||||||
|
@ -156,14 +156,14 @@ func TestStyleGetStrokeOptions(t *testing.T) {
|
||||||
Padding: DefaultBackgroundPadding,
|
Padding: DefaultBackgroundPadding,
|
||||||
}
|
}
|
||||||
svgStroke := set.GetStrokeOptions()
|
svgStroke := set.GetStrokeOptions()
|
||||||
assert.False(svgStroke.StrokeColor.IsZero())
|
testutil.AssertFalse(t, svgStroke.StrokeColor.IsZero())
|
||||||
assert.NotZero(svgStroke.StrokeWidth)
|
testutil.AssertNotZero(t, svgStroke.StrokeWidth)
|
||||||
assert.True(svgStroke.FillColor.IsZero())
|
testutil.AssertTrue(t, svgStroke.FillColor.IsZero())
|
||||||
assert.True(svgStroke.FontColor.IsZero())
|
testutil.AssertTrue(t, svgStroke.FontColor.IsZero())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStyleGetFillOptions(t *testing.T) {
|
func TestStyleGetFillOptions(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
set := Style{
|
set := Style{
|
||||||
StrokeColor: drawing.ColorWhite,
|
StrokeColor: drawing.ColorWhite,
|
||||||
|
@ -173,14 +173,14 @@ func TestStyleGetFillOptions(t *testing.T) {
|
||||||
Padding: DefaultBackgroundPadding,
|
Padding: DefaultBackgroundPadding,
|
||||||
}
|
}
|
||||||
svgFill := set.GetFillOptions()
|
svgFill := set.GetFillOptions()
|
||||||
assert.False(svgFill.FillColor.IsZero())
|
testutil.AssertFalse(t, svgFill.FillColor.IsZero())
|
||||||
assert.Zero(svgFill.StrokeWidth)
|
testutil.AssertZero(t, svgFill.StrokeWidth)
|
||||||
assert.True(svgFill.StrokeColor.IsZero())
|
testutil.AssertTrue(t, svgFill.StrokeColor.IsZero())
|
||||||
assert.True(svgFill.FontColor.IsZero())
|
testutil.AssertTrue(t, svgFill.FontColor.IsZero())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStyleGetFillAndStrokeOptions(t *testing.T) {
|
func TestStyleGetFillAndStrokeOptions(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
set := Style{
|
set := Style{
|
||||||
StrokeColor: drawing.ColorWhite,
|
StrokeColor: drawing.ColorWhite,
|
||||||
|
@ -190,14 +190,14 @@ func TestStyleGetFillAndStrokeOptions(t *testing.T) {
|
||||||
Padding: DefaultBackgroundPadding,
|
Padding: DefaultBackgroundPadding,
|
||||||
}
|
}
|
||||||
svgFillAndStroke := set.GetFillAndStrokeOptions()
|
svgFillAndStroke := set.GetFillAndStrokeOptions()
|
||||||
assert.False(svgFillAndStroke.FillColor.IsZero())
|
testutil.AssertFalse(t, svgFillAndStroke.FillColor.IsZero())
|
||||||
assert.NotZero(svgFillAndStroke.StrokeWidth)
|
testutil.AssertNotZero(t, svgFillAndStroke.StrokeWidth)
|
||||||
assert.False(svgFillAndStroke.StrokeColor.IsZero())
|
testutil.AssertFalse(t, svgFillAndStroke.StrokeColor.IsZero())
|
||||||
assert.True(svgFillAndStroke.FontColor.IsZero())
|
testutil.AssertTrue(t, svgFillAndStroke.FontColor.IsZero())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStyleGetTextOptions(t *testing.T) {
|
func TestStyleGetTextOptions(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
set := Style{
|
set := Style{
|
||||||
StrokeColor: drawing.ColorWhite,
|
StrokeColor: drawing.ColorWhite,
|
||||||
|
@ -207,8 +207,8 @@ func TestStyleGetTextOptions(t *testing.T) {
|
||||||
Padding: DefaultBackgroundPadding,
|
Padding: DefaultBackgroundPadding,
|
||||||
}
|
}
|
||||||
svgStroke := set.GetTextOptions()
|
svgStroke := set.GetTextOptions()
|
||||||
assert.True(svgStroke.StrokeColor.IsZero())
|
testutil.AssertTrue(t, svgStroke.StrokeColor.IsZero())
|
||||||
assert.Zero(svgStroke.StrokeWidth)
|
testutil.AssertZero(t, svgStroke.StrokeWidth)
|
||||||
assert.True(svgStroke.FillColor.IsZero())
|
testutil.AssertTrue(t, svgStroke.FillColor.IsZero())
|
||||||
assert.False(svgStroke.FontColor.IsZero())
|
testutil.AssertFalse(t, svgStroke.FontColor.IsZero())
|
||||||
}
|
}
|
||||||
|
|
202
testutil/helpers.go
Normal file
202
testutil/helpers.go
Normal file
|
@ -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
|
||||||
|
}
|
42
text_test.go
42
text_test.go
|
@ -3,58 +3,58 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTextWrapWord(t *testing.T) {
|
func TestTextWrapWord(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
r, err := PNG(1024, 1024)
|
r, err := PNG(1024, 1024)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
basicTextStyle := Style{Font: f, FontSize: 24}
|
basicTextStyle := Style{Font: f, FontSize: 24}
|
||||||
|
|
||||||
output := Text.WrapFitWord(r, "this is a test string", 100, basicTextStyle)
|
output := Text.WrapFitWord(r, "this is a test string", 100, basicTextStyle)
|
||||||
assert.NotEmpty(output)
|
testutil.AssertNotEmpty(t, output)
|
||||||
assert.Len(output, 3)
|
testutil.AssertLen(t, output, 3)
|
||||||
|
|
||||||
for _, line := range output {
|
for _, line := range output {
|
||||||
basicTextStyle.WriteToRenderer(r)
|
basicTextStyle.WriteToRenderer(r)
|
||||||
lineBox := r.MeasureText(line)
|
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])
|
testutil.AssertEqual(t, "this is", output[0])
|
||||||
assert.Equal("a test", output[1])
|
testutil.AssertEqual(t, "a test", output[1])
|
||||||
assert.Equal("string", output[2])
|
testutil.AssertEqual(t, "string", output[2])
|
||||||
|
|
||||||
output = Text.WrapFitWord(r, "foo", 100, basicTextStyle)
|
output = Text.WrapFitWord(r, "foo", 100, basicTextStyle)
|
||||||
assert.Len(output, 1)
|
testutil.AssertLen(t, output, 1)
|
||||||
assert.Equal("foo", output[0])
|
testutil.AssertEqual(t, "foo", output[0])
|
||||||
|
|
||||||
// test that it handles newlines.
|
// test that it handles newlines.
|
||||||
output = Text.WrapFitWord(r, "this\nis\na\ntest\nstring", 100, basicTextStyle)
|
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.
|
// test that it handles newlines and long lines.
|
||||||
output = Text.WrapFitWord(r, "this\nis\na\ntest\nstring that is very long", 100, basicTextStyle)
|
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) {
|
func TestTextWrapRune(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
r, err := PNG(1024, 1024)
|
r, err := PNG(1024, 1024)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
basicTextStyle := Style{Font: f, FontSize: 24}
|
basicTextStyle := Style{Font: f, FontSize: 24}
|
||||||
|
|
||||||
output := Text.WrapFitRune(r, "this is a test string", 150, basicTextStyle)
|
output := Text.WrapFitRune(r, "this is a test string", 150, basicTextStyle)
|
||||||
assert.NotEmpty(output)
|
testutil.AssertNotEmpty(t, output)
|
||||||
assert.Len(output, 2)
|
testutil.AssertLen(t, output, 2)
|
||||||
assert.Equal("this is a t", output[0])
|
testutil.AssertEqual(t, "this is a t", output[0])
|
||||||
assert.Equal("est string", output[1])
|
testutil.AssertEqual(t, "est string", output[1])
|
||||||
}
|
}
|
||||||
|
|
34
tick_test.go
34
tick_test.go
|
@ -3,17 +3,17 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenerateContinuousTicks(t *testing.T) {
|
func TestGenerateContinuousTicks(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
r, err := PNG(1024, 1024)
|
r, err := PNG(1024, 1024)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
r.SetFont(f)
|
r.SetFont(f)
|
||||||
|
|
||||||
ra := &ContinuousRange{
|
ra := &ContinuousRange{
|
||||||
|
@ -25,20 +25,20 @@ func TestGenerateContinuousTicks(t *testing.T) {
|
||||||
vf := FloatValueFormatter
|
vf := FloatValueFormatter
|
||||||
|
|
||||||
ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf)
|
ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf)
|
||||||
assert.NotEmpty(ticks)
|
testutil.AssertNotEmpty(t, ticks)
|
||||||
assert.Len(ticks, 11)
|
testutil.AssertLen(t, ticks, 11)
|
||||||
assert.Equal(0.0, ticks[0].Value)
|
testutil.AssertEqual(t, 0.0, ticks[0].Value)
|
||||||
assert.Equal(10, ticks[len(ticks)-1].Value)
|
testutil.AssertEqual(t, 10, ticks[len(ticks)-1].Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateContinuousTicksDescending(t *testing.T) {
|
func TestGenerateContinuousTicksDescending(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
r, err := PNG(1024, 1024)
|
r, err := PNG(1024, 1024)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
r.SetFont(f)
|
r.SetFont(f)
|
||||||
|
|
||||||
ra := &ContinuousRange{
|
ra := &ContinuousRange{
|
||||||
|
@ -51,10 +51,10 @@ func TestGenerateContinuousTicksDescending(t *testing.T) {
|
||||||
vf := FloatValueFormatter
|
vf := FloatValueFormatter
|
||||||
|
|
||||||
ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf)
|
ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf)
|
||||||
assert.NotEmpty(ticks)
|
testutil.AssertNotEmpty(t, ticks)
|
||||||
assert.Len(ticks, 11)
|
testutil.AssertLen(t, ticks, 11)
|
||||||
assert.Equal(10.0, ticks[0].Value)
|
testutil.AssertEqual(t, 10.0, ticks[0].Value)
|
||||||
assert.Equal(9.0, ticks[1].Value)
|
testutil.AssertEqual(t, 9.0, ticks[1].Value)
|
||||||
assert.Equal(1.0, ticks[len(ticks)-2].Value)
|
testutil.AssertEqual(t, 1.0, ticks[len(ticks)-2].Value)
|
||||||
assert.Equal(0.0, ticks[len(ticks)-1].Value)
|
testutil.AssertEqual(t, 0.0, ticks[len(ticks)-1].Value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTimeSeriesGetValue(t *testing.T) {
|
func TestTimeSeriesGetValue(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
ts := TimeSeries{
|
ts := TimeSeries{
|
||||||
Name: "Test",
|
Name: "Test",
|
||||||
|
@ -25,12 +25,12 @@ func TestTimeSeriesGetValue(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
x0, y0 := ts.GetValues(0)
|
x0, y0 := ts.GetValues(0)
|
||||||
assert.NotZero(x0)
|
testutil.AssertNotZero(t, x0)
|
||||||
assert.Equal(1.0, y0)
|
testutil.AssertEqual(t, 1.0, y0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTimeSeriesValidate(t *testing.T) {
|
func TestTimeSeriesValidate(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
cs := TimeSeries{
|
cs := TimeSeries{
|
||||||
Name: "Test Series",
|
Name: "Test Series",
|
||||||
|
@ -45,7 +45,7 @@ func TestTimeSeriesValidate(t *testing.T) {
|
||||||
1.0, 2.0, 3.0, 4.0, 5.0,
|
1.0, 2.0, 3.0, 4.0, 5.0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.Nil(cs.Validate())
|
testutil.AssertNil(t, cs.Validate())
|
||||||
|
|
||||||
cs = TimeSeries{
|
cs = TimeSeries{
|
||||||
Name: "Test Series",
|
Name: "Test Series",
|
||||||
|
@ -57,7 +57,7 @@ func TestTimeSeriesValidate(t *testing.T) {
|
||||||
time.Now().AddDate(0, 0, -1),
|
time.Now().AddDate(0, 0, -1),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NotNil(cs.Validate())
|
testutil.AssertNotNil(t, cs.Validate())
|
||||||
|
|
||||||
cs = TimeSeries{
|
cs = TimeSeries{
|
||||||
Name: "Test Series",
|
Name: "Test Series",
|
||||||
|
@ -65,5 +65,5 @@ func TestTimeSeriesValidate(t *testing.T) {
|
||||||
1.0, 2.0, 3.0, 4.0, 5.0,
|
1.0, 2.0, 3.0, 4.0, 5.0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NotNil(cs.Validate())
|
testutil.AssertNotNil(t, cs.Validate())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,105 +3,105 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuffer(t *testing.T) {
|
func TestBuffer(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
buffer := NewValueBuffer()
|
buffer := NewValueBuffer()
|
||||||
|
|
||||||
buffer.Enqueue(1)
|
buffer.Enqueue(1)
|
||||||
assert.Equal(1, buffer.Len())
|
testutil.AssertEqual(t, 1, buffer.Len())
|
||||||
assert.Equal(1, buffer.Peek())
|
testutil.AssertEqual(t, 1, buffer.Peek())
|
||||||
assert.Equal(1, buffer.PeekBack())
|
testutil.AssertEqual(t, 1, buffer.PeekBack())
|
||||||
|
|
||||||
buffer.Enqueue(2)
|
buffer.Enqueue(2)
|
||||||
assert.Equal(2, buffer.Len())
|
testutil.AssertEqual(t, 2, buffer.Len())
|
||||||
assert.Equal(1, buffer.Peek())
|
testutil.AssertEqual(t, 1, buffer.Peek())
|
||||||
assert.Equal(2, buffer.PeekBack())
|
testutil.AssertEqual(t, 2, buffer.PeekBack())
|
||||||
|
|
||||||
buffer.Enqueue(3)
|
buffer.Enqueue(3)
|
||||||
assert.Equal(3, buffer.Len())
|
testutil.AssertEqual(t, 3, buffer.Len())
|
||||||
assert.Equal(1, buffer.Peek())
|
testutil.AssertEqual(t, 1, buffer.Peek())
|
||||||
assert.Equal(3, buffer.PeekBack())
|
testutil.AssertEqual(t, 3, buffer.PeekBack())
|
||||||
|
|
||||||
buffer.Enqueue(4)
|
buffer.Enqueue(4)
|
||||||
assert.Equal(4, buffer.Len())
|
testutil.AssertEqual(t, 4, buffer.Len())
|
||||||
assert.Equal(1, buffer.Peek())
|
testutil.AssertEqual(t, 1, buffer.Peek())
|
||||||
assert.Equal(4, buffer.PeekBack())
|
testutil.AssertEqual(t, 4, buffer.PeekBack())
|
||||||
|
|
||||||
buffer.Enqueue(5)
|
buffer.Enqueue(5)
|
||||||
assert.Equal(5, buffer.Len())
|
testutil.AssertEqual(t, 5, buffer.Len())
|
||||||
assert.Equal(1, buffer.Peek())
|
testutil.AssertEqual(t, 1, buffer.Peek())
|
||||||
assert.Equal(5, buffer.PeekBack())
|
testutil.AssertEqual(t, 5, buffer.PeekBack())
|
||||||
|
|
||||||
buffer.Enqueue(6)
|
buffer.Enqueue(6)
|
||||||
assert.Equal(6, buffer.Len())
|
testutil.AssertEqual(t, 6, buffer.Len())
|
||||||
assert.Equal(1, buffer.Peek())
|
testutil.AssertEqual(t, 1, buffer.Peek())
|
||||||
assert.Equal(6, buffer.PeekBack())
|
testutil.AssertEqual(t, 6, buffer.PeekBack())
|
||||||
|
|
||||||
buffer.Enqueue(7)
|
buffer.Enqueue(7)
|
||||||
assert.Equal(7, buffer.Len())
|
testutil.AssertEqual(t, 7, buffer.Len())
|
||||||
assert.Equal(1, buffer.Peek())
|
testutil.AssertEqual(t, 1, buffer.Peek())
|
||||||
assert.Equal(7, buffer.PeekBack())
|
testutil.AssertEqual(t, 7, buffer.PeekBack())
|
||||||
|
|
||||||
buffer.Enqueue(8)
|
buffer.Enqueue(8)
|
||||||
assert.Equal(8, buffer.Len())
|
testutil.AssertEqual(t, 8, buffer.Len())
|
||||||
assert.Equal(1, buffer.Peek())
|
testutil.AssertEqual(t, 1, buffer.Peek())
|
||||||
assert.Equal(8, buffer.PeekBack())
|
testutil.AssertEqual(t, 8, buffer.PeekBack())
|
||||||
|
|
||||||
value := buffer.Dequeue()
|
value := buffer.Dequeue()
|
||||||
assert.Equal(1, value)
|
testutil.AssertEqual(t, 1, value)
|
||||||
assert.Equal(7, buffer.Len())
|
testutil.AssertEqual(t, 7, buffer.Len())
|
||||||
assert.Equal(2, buffer.Peek())
|
testutil.AssertEqual(t, 2, buffer.Peek())
|
||||||
assert.Equal(8, buffer.PeekBack())
|
testutil.AssertEqual(t, 8, buffer.PeekBack())
|
||||||
|
|
||||||
value = buffer.Dequeue()
|
value = buffer.Dequeue()
|
||||||
assert.Equal(2, value)
|
testutil.AssertEqual(t, 2, value)
|
||||||
assert.Equal(6, buffer.Len())
|
testutil.AssertEqual(t, 6, buffer.Len())
|
||||||
assert.Equal(3, buffer.Peek())
|
testutil.AssertEqual(t, 3, buffer.Peek())
|
||||||
assert.Equal(8, buffer.PeekBack())
|
testutil.AssertEqual(t, 8, buffer.PeekBack())
|
||||||
|
|
||||||
value = buffer.Dequeue()
|
value = buffer.Dequeue()
|
||||||
assert.Equal(3, value)
|
testutil.AssertEqual(t, 3, value)
|
||||||
assert.Equal(5, buffer.Len())
|
testutil.AssertEqual(t, 5, buffer.Len())
|
||||||
assert.Equal(4, buffer.Peek())
|
testutil.AssertEqual(t, 4, buffer.Peek())
|
||||||
assert.Equal(8, buffer.PeekBack())
|
testutil.AssertEqual(t, 8, buffer.PeekBack())
|
||||||
|
|
||||||
value = buffer.Dequeue()
|
value = buffer.Dequeue()
|
||||||
assert.Equal(4, value)
|
testutil.AssertEqual(t, 4, value)
|
||||||
assert.Equal(4, buffer.Len())
|
testutil.AssertEqual(t, 4, buffer.Len())
|
||||||
assert.Equal(5, buffer.Peek())
|
testutil.AssertEqual(t, 5, buffer.Peek())
|
||||||
assert.Equal(8, buffer.PeekBack())
|
testutil.AssertEqual(t, 8, buffer.PeekBack())
|
||||||
|
|
||||||
value = buffer.Dequeue()
|
value = buffer.Dequeue()
|
||||||
assert.Equal(5, value)
|
testutil.AssertEqual(t, 5, value)
|
||||||
assert.Equal(3, buffer.Len())
|
testutil.AssertEqual(t, 3, buffer.Len())
|
||||||
assert.Equal(6, buffer.Peek())
|
testutil.AssertEqual(t, 6, buffer.Peek())
|
||||||
assert.Equal(8, buffer.PeekBack())
|
testutil.AssertEqual(t, 8, buffer.PeekBack())
|
||||||
|
|
||||||
value = buffer.Dequeue()
|
value = buffer.Dequeue()
|
||||||
assert.Equal(6, value)
|
testutil.AssertEqual(t, 6, value)
|
||||||
assert.Equal(2, buffer.Len())
|
testutil.AssertEqual(t, 2, buffer.Len())
|
||||||
assert.Equal(7, buffer.Peek())
|
testutil.AssertEqual(t, 7, buffer.Peek())
|
||||||
assert.Equal(8, buffer.PeekBack())
|
testutil.AssertEqual(t, 8, buffer.PeekBack())
|
||||||
|
|
||||||
value = buffer.Dequeue()
|
value = buffer.Dequeue()
|
||||||
assert.Equal(7, value)
|
testutil.AssertEqual(t, 7, value)
|
||||||
assert.Equal(1, buffer.Len())
|
testutil.AssertEqual(t, 1, buffer.Len())
|
||||||
assert.Equal(8, buffer.Peek())
|
testutil.AssertEqual(t, 8, buffer.Peek())
|
||||||
assert.Equal(8, buffer.PeekBack())
|
testutil.AssertEqual(t, 8, buffer.PeekBack())
|
||||||
|
|
||||||
value = buffer.Dequeue()
|
value = buffer.Dequeue()
|
||||||
assert.Equal(8, value)
|
testutil.AssertEqual(t, 8, value)
|
||||||
assert.Equal(0, buffer.Len())
|
testutil.AssertEqual(t, 0, buffer.Len())
|
||||||
assert.Zero(buffer.Peek())
|
testutil.AssertZero(t, buffer.Peek())
|
||||||
assert.Zero(buffer.PeekBack())
|
testutil.AssertZero(t, buffer.PeekBack())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBufferClear(t *testing.T) {
|
func TestBufferClear(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
buffer := NewValueBuffer()
|
buffer := NewValueBuffer()
|
||||||
buffer.Enqueue(1)
|
buffer.Enqueue(1)
|
||||||
|
@ -113,16 +113,16 @@ func TestBufferClear(t *testing.T) {
|
||||||
buffer.Enqueue(1)
|
buffer.Enqueue(1)
|
||||||
buffer.Enqueue(1)
|
buffer.Enqueue(1)
|
||||||
|
|
||||||
assert.Equal(8, buffer.Len())
|
testutil.AssertEqual(t, 8, buffer.Len())
|
||||||
|
|
||||||
buffer.Clear()
|
buffer.Clear()
|
||||||
assert.Equal(0, buffer.Len())
|
testutil.AssertEqual(t, 0, buffer.Len())
|
||||||
assert.Zero(buffer.Peek())
|
testutil.AssertZero(t, buffer.Peek())
|
||||||
assert.Zero(buffer.PeekBack())
|
testutil.AssertZero(t, buffer.PeekBack())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBufferArray(t *testing.T) {
|
func TestBufferArray(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
buffer := NewValueBuffer()
|
buffer := NewValueBuffer()
|
||||||
buffer.Enqueue(1)
|
buffer.Enqueue(1)
|
||||||
|
@ -132,16 +132,16 @@ func TestBufferArray(t *testing.T) {
|
||||||
buffer.Enqueue(5)
|
buffer.Enqueue(5)
|
||||||
|
|
||||||
contents := buffer.Array()
|
contents := buffer.Array()
|
||||||
assert.Len(contents, 5)
|
testutil.AssertLen(t, contents, 5)
|
||||||
assert.Equal(1, contents[0])
|
testutil.AssertEqual(t, 1, contents[0])
|
||||||
assert.Equal(2, contents[1])
|
testutil.AssertEqual(t, 2, contents[1])
|
||||||
assert.Equal(3, contents[2])
|
testutil.AssertEqual(t, 3, contents[2])
|
||||||
assert.Equal(4, contents[3])
|
testutil.AssertEqual(t, 4, contents[3])
|
||||||
assert.Equal(5, contents[4])
|
testutil.AssertEqual(t, 5, contents[4])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBufferEach(t *testing.T) {
|
func TestBufferEach(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
buffer := NewValueBuffer()
|
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) {
|
func TestNewBuffer(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
empty := NewValueBuffer()
|
empty := NewValueBuffer()
|
||||||
assert.NotNil(empty)
|
testutil.AssertNotNil(t, empty)
|
||||||
assert.Zero(empty.Len())
|
testutil.AssertZero(t, empty.Len())
|
||||||
assert.Equal(bufferDefaultCapacity, empty.Capacity())
|
testutil.AssertEqual(t, bufferDefaultCapacity, empty.Capacity())
|
||||||
assert.Zero(empty.Peek())
|
testutil.AssertZero(t, empty.Peek())
|
||||||
assert.Zero(empty.PeekBack())
|
testutil.AssertZero(t, empty.PeekBack())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewBufferWithValues(t *testing.T) {
|
func TestNewBufferWithValues(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
values := NewValueBuffer(1, 2, 3, 4, 5)
|
values := NewValueBuffer(1, 2, 3, 4, 5)
|
||||||
assert.NotNil(values)
|
testutil.AssertNotNil(t, values)
|
||||||
assert.Equal(5, values.Len())
|
testutil.AssertEqual(t, 5, values.Len())
|
||||||
assert.Equal(1, values.Peek())
|
testutil.AssertEqual(t, 1, values.Peek())
|
||||||
assert.Equal(5, values.PeekBack())
|
testutil.AssertEqual(t, 5, values.PeekBack())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBufferGrowth(t *testing.T) {
|
func TestBufferGrowth(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
values := NewValueBuffer(1, 2, 3, 4, 5)
|
values := NewValueBuffer(1, 2, 3, 4, 5)
|
||||||
for i := 0; i < 1<<10; i++ {
|
for i := 0; i < 1<<10; i++ {
|
||||||
values.Enqueue(float64(i))
|
values.Enqueue(float64(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(1<<10-1, values.PeekBack())
|
testutil.AssertEqual(t, 1<<10-1, values.PeekBack())
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTimeValueFormatterWithFormat(t *testing.T) {
|
func TestTimeValueFormatterWithFormat(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
d := time.Now()
|
d := time.Now()
|
||||||
di := TimeToFloat64(d)
|
di := TimeToFloat64(d)
|
||||||
|
@ -17,42 +17,42 @@ func TestTimeValueFormatterWithFormat(t *testing.T) {
|
||||||
s := formatTime(d, DefaultDateFormat)
|
s := formatTime(d, DefaultDateFormat)
|
||||||
si := formatTime(di, DefaultDateFormat)
|
si := formatTime(di, DefaultDateFormat)
|
||||||
sf := formatTime(df, DefaultDateFormat)
|
sf := formatTime(df, DefaultDateFormat)
|
||||||
assert.Equal(s, si)
|
testutil.AssertEqual(t, s, si)
|
||||||
assert.Equal(s, sf)
|
testutil.AssertEqual(t, s, sf)
|
||||||
|
|
||||||
sd := TimeValueFormatter(d)
|
sd := TimeValueFormatter(d)
|
||||||
sdi := TimeValueFormatter(di)
|
sdi := TimeValueFormatter(di)
|
||||||
sdf := TimeValueFormatter(df)
|
sdf := TimeValueFormatter(df)
|
||||||
assert.Equal(s, sd)
|
testutil.AssertEqual(t, s, sd)
|
||||||
assert.Equal(s, sdi)
|
testutil.AssertEqual(t, s, sdi)
|
||||||
assert.Equal(s, sdf)
|
testutil.AssertEqual(t, s, sdf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFloatValueFormatter(t *testing.T) {
|
func TestFloatValueFormatter(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
assert.Equal("1234.00", FloatValueFormatter(1234.00))
|
testutil.AssertEqual(t, "1234.00", FloatValueFormatter(1234.00))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFloatValueFormatterWithFloat32Input(t *testing.T) {
|
func TestFloatValueFormatterWithFloat32Input(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
assert.Equal("1234.00", FloatValueFormatter(float32(1234.00)))
|
testutil.AssertEqual(t, "1234.00", FloatValueFormatter(float32(1234.00)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFloatValueFormatterWithIntegerInput(t *testing.T) {
|
func TestFloatValueFormatterWithIntegerInput(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
assert.Equal("1234.00", FloatValueFormatter(1234))
|
testutil.AssertEqual(t, "1234.00", FloatValueFormatter(1234))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFloatValueFormatterWithInt64Input(t *testing.T) {
|
func TestFloatValueFormatterWithInt64Input(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
assert.Equal("1234.00", FloatValueFormatter(int64(1234)))
|
testutil.AssertEqual(t, "1234.00", FloatValueFormatter(int64(1234)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFloatValueFormatterWithFormat(t *testing.T) {
|
func TestFloatValueFormatterWithFormat(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
v := 123.456
|
v := 123.456
|
||||||
sv := FloatValueFormatterWithFormat(v, "%.3f")
|
sv := FloatValueFormatterWithFormat(v, "%.3f")
|
||||||
assert.Equal("123.456", sv)
|
testutil.AssertEqual(t, "123.456", sv)
|
||||||
assert.Equal("123.000", FloatValueFormatterWithFormat(123, "%.3f"))
|
testutil.AssertEqual(t, "123.000", FloatValueFormatterWithFormat(123, "%.3f"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package chart
|
package chart
|
||||||
|
|
||||||
import "github.com/wcharczuk/go-chart/drawing"
|
import "github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
|
|
||||||
// ValuesProvider is a type that produces values.
|
// ValuesProvider is a type that produces values.
|
||||||
type ValuesProvider interface {
|
type ValuesProvider interface {
|
||||||
|
|
|
@ -3,11 +3,11 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assert "github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValuesValues(t *testing.T) {
|
func TestValuesValues(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
vs := []Value{
|
vs := []Value{
|
||||||
{Value: 10, Label: "Blue"},
|
{Value: 10, Label: "Blue"},
|
||||||
|
@ -20,18 +20,18 @@ func TestValuesValues(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
values := Values(vs).Values()
|
values := Values(vs).Values()
|
||||||
assert.Len(values, 7)
|
testutil.AssertLen(t, values, 7)
|
||||||
assert.Equal(10, values[0])
|
testutil.AssertEqual(t, 10, values[0])
|
||||||
assert.Equal(9, values[1])
|
testutil.AssertEqual(t, 9, values[1])
|
||||||
assert.Equal(8, values[2])
|
testutil.AssertEqual(t, 8, values[2])
|
||||||
assert.Equal(7, values[3])
|
testutil.AssertEqual(t, 7, values[3])
|
||||||
assert.Equal(6, values[4])
|
testutil.AssertEqual(t, 6, values[4])
|
||||||
assert.Equal(5, values[5])
|
testutil.AssertEqual(t, 5, values[5])
|
||||||
assert.Equal(2, values[6])
|
testutil.AssertEqual(t, 2, values[6])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValuesValuesNormalized(t *testing.T) {
|
func TestValuesValuesNormalized(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
vs := []Value{
|
vs := []Value{
|
||||||
{Value: 10, Label: "Blue"},
|
{Value: 10, Label: "Blue"},
|
||||||
|
@ -44,13 +44,13 @@ func TestValuesValuesNormalized(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
values := Values(vs).ValuesNormalized()
|
values := Values(vs).ValuesNormalized()
|
||||||
assert.Len(values, 7)
|
testutil.AssertLen(t, values, 7)
|
||||||
assert.Equal(0.2127, values[0])
|
testutil.AssertEqual(t, 0.2127, values[0])
|
||||||
assert.Equal(0.0425, values[6])
|
testutil.AssertEqual(t, 0.0425, values[6])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValuesNormalize(t *testing.T) {
|
func TestValuesNormalize(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
vs := []Value{
|
vs := []Value{
|
||||||
{Value: 10, Label: "Blue"},
|
{Value: 10, Label: "Blue"},
|
||||||
|
@ -63,7 +63,7 @@ func TestValuesNormalize(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
values := Values(vs).Normalize()
|
values := Values(vs).Normalize()
|
||||||
assert.Len(values, 7)
|
testutil.AssertLen(t, values, 7)
|
||||||
assert.Equal(0.2127, values[0].Value)
|
testutil.AssertEqual(t, 0.2127, values[0].Value)
|
||||||
assert.Equal(0.0425, values[6].Value)
|
testutil.AssertEqual(t, 0.0425, values[6].Value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"golang.org/x/image/font"
|
"golang.org/x/image/font"
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"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.
|
// SVG returns a new png/raster renderer.
|
||||||
|
|
|
@ -6,18 +6,18 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVectorRendererPath(t *testing.T) {
|
func TestVectorRendererPath(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
vr, err := SVG(100, 100)
|
vr, err := SVG(100, 100)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
typed, isTyped := vr.(*vectorRenderer)
|
typed, isTyped := vr.(*vectorRenderer)
|
||||||
assert.True(isTyped)
|
testutil.AssertTrue(t, isTyped)
|
||||||
|
|
||||||
typed.MoveTo(0, 0)
|
typed.MoveTo(0, 0)
|
||||||
typed.LineTo(100, 100)
|
typed.LineTo(100, 100)
|
||||||
|
@ -27,37 +27,37 @@ func TestVectorRendererPath(t *testing.T) {
|
||||||
|
|
||||||
buffer := bytes.NewBuffer([]byte{})
|
buffer := bytes.NewBuffer([]byte{})
|
||||||
err = typed.Save(buffer)
|
err = typed.Save(buffer)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
raw := string(buffer.Bytes())
|
raw := string(buffer.Bytes())
|
||||||
|
|
||||||
assert.True(strings.HasPrefix(raw, "<svg"))
|
testutil.AssertTrue(t, strings.HasPrefix(raw, "<svg"))
|
||||||
assert.True(strings.HasSuffix(raw, "</svg>"))
|
testutil.AssertTrue(t, strings.HasSuffix(raw, "</svg>"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVectorRendererMeasureText(t *testing.T) {
|
func TestVectorRendererMeasureText(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
vr, err := SVG(100, 100)
|
vr, err := SVG(100, 100)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
vr.SetDPI(DefaultDPI)
|
vr.SetDPI(DefaultDPI)
|
||||||
vr.SetFont(f)
|
vr.SetFont(f)
|
||||||
vr.SetFontSize(12.0)
|
vr.SetFontSize(12.0)
|
||||||
|
|
||||||
tb := vr.MeasureText("Ljp")
|
tb := vr.MeasureText("Ljp")
|
||||||
assert.Equal(21, tb.Width())
|
testutil.AssertEqual(t, 21, tb.Width())
|
||||||
assert.Equal(15, tb.Height())
|
testutil.AssertEqual(t, 15, tb.Height())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCanvasStyleSVG(t *testing.T) {
|
func TestCanvasStyleSVG(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
set := Style{
|
set := Style{
|
||||||
StrokeColor: drawing.ColorWhite,
|
StrokeColor: drawing.ColorWhite,
|
||||||
|
@ -71,24 +71,22 @@ func TestCanvasStyleSVG(t *testing.T) {
|
||||||
canvas := &canvas{dpi: DefaultDPI}
|
canvas := &canvas{dpi: DefaultDPI}
|
||||||
|
|
||||||
svgString := canvas.styleAsSVG(set)
|
svgString := canvas.styleAsSVG(set)
|
||||||
assert.NotEmpty(svgString)
|
testutil.AssertNotEmpty(t, svgString)
|
||||||
assert.True(strings.HasPrefix(svgString, "style=\""))
|
testutil.AssertTrue(t, strings.HasPrefix(svgString, "style=\""))
|
||||||
assert.True(strings.Contains(svgString, "stroke:rgba(255,255,255,1.0)"))
|
testutil.AssertTrue(t, strings.Contains(svgString, "stroke:rgba(255,255,255,1.0)"))
|
||||||
assert.True(strings.Contains(svgString, "stroke-width:5"))
|
testutil.AssertTrue(t, strings.Contains(svgString, "stroke-width:5"))
|
||||||
assert.True(strings.Contains(svgString, "fill:rgba(255,255,255,1.0)"))
|
testutil.AssertTrue(t, strings.Contains(svgString, "fill:rgba(255,255,255,1.0)"))
|
||||||
assert.True(strings.HasSuffix(svgString, "\""))
|
testutil.AssertTrue(t, strings.HasSuffix(svgString, "\""))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCanvasClassSVG(t *testing.T) {
|
func TestCanvasClassSVG(t *testing.T) {
|
||||||
as := assert.New(t)
|
|
||||||
|
|
||||||
set := Style{
|
set := Style{
|
||||||
ClassName: "test-class",
|
ClassName: "test-class",
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas := &canvas{dpi: DefaultDPI}
|
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) {
|
func TestCanvasCustomInlineStylesheet(t *testing.T) {
|
||||||
|
@ -101,7 +99,7 @@ func TestCanvasCustomInlineStylesheet(t *testing.T) {
|
||||||
|
|
||||||
canvas.Start(200, 200)
|
canvas.Start(200, 200)
|
||||||
|
|
||||||
assert.New(t).Contains(b.String(), fmt.Sprintf(`<style type="text/css"><![CDATA[%s]]></style>`, canvas.css))
|
testutil.AssertContains(t, b.String(), fmt.Sprintf(`<style type="text/css"><![CDATA[%s]]></style>`, canvas.css))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCanvasCustomInlineStylesheetWithNonce(t *testing.T) {
|
func TestCanvasCustomInlineStylesheetWithNonce(t *testing.T) {
|
||||||
|
@ -115,5 +113,5 @@ func TestCanvasCustomInlineStylesheetWithNonce(t *testing.T) {
|
||||||
|
|
||||||
canvas.Start(200, 200)
|
canvas.Start(200, 200)
|
||||||
|
|
||||||
assert.New(t).Contains(b.String(), fmt.Sprintf(`<style type="text/css" nonce="%s"><![CDATA[%s]]></style>`, canvas.nonce, canvas.css))
|
testutil.AssertContains(t, b.String(), fmt.Sprintf(`<style type="text/css" nonce="%s"><![CDATA[%s]]></style>`, canvas.nonce, canvas.css))
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package chart
|
package chart
|
||||||
|
|
||||||
import "github.com/wcharczuk/go-chart/drawing"
|
import "github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
|
|
||||||
var viridisColors = [256]drawing.Color{
|
var viridisColors = [256]drawing.Color{
|
||||||
drawing.Color{R: 0x44, G: 0x1, B: 0x54, A: 0xff},
|
drawing.Color{R: 0x44, G: 0x1, B: 0x54, A: 0xff},
|
||||||
|
|
|
@ -3,17 +3,17 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestXAxisGetTicks(t *testing.T) {
|
func TestXAxisGetTicks(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
r, err := PNG(1024, 1024)
|
r, err := PNG(1024, 1024)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
xa := XAxis{}
|
xa := XAxis{}
|
||||||
xr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024}
|
xr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024}
|
||||||
|
@ -23,17 +23,17 @@ func TestXAxisGetTicks(t *testing.T) {
|
||||||
}
|
}
|
||||||
vf := FloatValueFormatter
|
vf := FloatValueFormatter
|
||||||
ticks := xa.GetTicks(r, xr, styleDefaults, vf)
|
ticks := xa.GetTicks(r, xr, styleDefaults, vf)
|
||||||
assert.Len(ticks, 16)
|
testutil.AssertLen(t, ticks, 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestXAxisGetTicksWithUserDefaults(t *testing.T) {
|
func TestXAxisGetTicksWithUserDefaults(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
r, err := PNG(1024, 1024)
|
r, err := PNG(1024, 1024)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
xa := XAxis{
|
xa := XAxis{
|
||||||
Ticks: []Tick{{Value: 1.0, Label: "1.0"}},
|
Ticks: []Tick{{Value: 1.0, Label: "1.0"}},
|
||||||
|
@ -45,23 +45,23 @@ func TestXAxisGetTicksWithUserDefaults(t *testing.T) {
|
||||||
}
|
}
|
||||||
vf := FloatValueFormatter
|
vf := FloatValueFormatter
|
||||||
ticks := xa.GetTicks(r, xr, styleDefaults, vf)
|
ticks := xa.GetTicks(r, xr, styleDefaults, vf)
|
||||||
assert.Len(ticks, 1)
|
testutil.AssertLen(t, ticks, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestXAxisMeasure(t *testing.T) {
|
func TestXAxisMeasure(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
style := Style{
|
style := Style{
|
||||||
Font: f,
|
Font: f,
|
||||||
FontSize: 10.0,
|
FontSize: 10.0,
|
||||||
}
|
}
|
||||||
r, err := PNG(100, 100)
|
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"}}
|
ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}}
|
||||||
xa := XAxis{}
|
xa := XAxis{}
|
||||||
xab := xa.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks)
|
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())
|
testutil.AssertEqual(t, 122, xab.Width())
|
||||||
assert.Equal(21, xab.Height())
|
testutil.AssertEqual(t, 21, xab.Height())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,17 +3,17 @@ package chart
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/blend/go-sdk/assert"
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestYAxisGetTicks(t *testing.T) {
|
func TestYAxisGetTicks(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
r, err := PNG(1024, 1024)
|
r, err := PNG(1024, 1024)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
ya := YAxis{}
|
ya := YAxis{}
|
||||||
yr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024}
|
yr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024}
|
||||||
|
@ -23,17 +23,17 @@ func TestYAxisGetTicks(t *testing.T) {
|
||||||
}
|
}
|
||||||
vf := FloatValueFormatter
|
vf := FloatValueFormatter
|
||||||
ticks := ya.GetTicks(r, yr, styleDefaults, vf)
|
ticks := ya.GetTicks(r, yr, styleDefaults, vf)
|
||||||
assert.Len(ticks, 32)
|
testutil.AssertLen(t, ticks, 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestYAxisGetTicksWithUserDefaults(t *testing.T) {
|
func TestYAxisGetTicksWithUserDefaults(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
r, err := PNG(1024, 1024)
|
r, err := PNG(1024, 1024)
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
|
|
||||||
ya := YAxis{
|
ya := YAxis{
|
||||||
Ticks: []Tick{{Value: 1.0, Label: "1.0"}},
|
Ticks: []Tick{{Value: 1.0, Label: "1.0"}},
|
||||||
|
@ -45,41 +45,41 @@ func TestYAxisGetTicksWithUserDefaults(t *testing.T) {
|
||||||
}
|
}
|
||||||
vf := FloatValueFormatter
|
vf := FloatValueFormatter
|
||||||
ticks := ya.GetTicks(r, yr, styleDefaults, vf)
|
ticks := ya.GetTicks(r, yr, styleDefaults, vf)
|
||||||
assert.Len(ticks, 1)
|
testutil.AssertLen(t, ticks, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestYAxisMeasure(t *testing.T) {
|
func TestYAxisMeasure(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
style := Style{
|
style := Style{
|
||||||
Font: f,
|
Font: f,
|
||||||
FontSize: 10.0,
|
FontSize: 10.0,
|
||||||
}
|
}
|
||||||
r, err := PNG(100, 100)
|
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"}}
|
ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}}
|
||||||
ya := YAxis{}
|
ya := YAxis{}
|
||||||
yab := ya.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks)
|
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())
|
testutil.AssertEqual(t, 32, yab.Width())
|
||||||
assert.Equal(110, yab.Height())
|
testutil.AssertEqual(t, 110, yab.Height())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestYAxisSecondaryMeasure(t *testing.T) {
|
func TestYAxisSecondaryMeasure(t *testing.T) {
|
||||||
assert := assert.New(t)
|
// replaced new assertions helper
|
||||||
|
|
||||||
f, err := GetDefaultFont()
|
f, err := GetDefaultFont()
|
||||||
assert.Nil(err)
|
testutil.AssertNil(t, err)
|
||||||
style := Style{
|
style := Style{
|
||||||
Font: f,
|
Font: f,
|
||||||
FontSize: 10.0,
|
FontSize: 10.0,
|
||||||
}
|
}
|
||||||
r, err := PNG(100, 100)
|
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"}}
|
ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}}
|
||||||
ya := YAxis{AxisType: YAxisSecondary}
|
ya := YAxis{AxisType: YAxisSecondary}
|
||||||
yab := ya.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks)
|
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())
|
testutil.AssertEqual(t, 32, yab.Width())
|
||||||
assert.Equal(110, yab.Height())
|
testutil.AssertEqual(t, 110, yab.Height())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue