From 81e9cbaa9dc9e879059c67b4959f52f2c5cbbc70 Mon Sep 17 00:00:00 2001 From: Alexander Weinhold Date: Thu, 6 Dec 2018 18:02:38 +0100 Subject: [PATCH] remove any mention of github.com/blend --- Makefile | 18 - PROFANITY | 8 - annotation_series_test.go | 118 ------- bar_chart_test.go | 320 ------------------ bollinger_band_series_test.go | 53 --- box_test.go | 188 ----------- chart_test.go | 556 ------------------------------- concat_series_test.go | 42 --- continuous_range_test.go | 23 -- continuous_series_test.go | 73 ---- drawing/color_test.go | 53 --- drawing/curve_test.go | 35 -- ema_series_test.go | 106 ------ first_value_annotation_test.go | 22 -- grid_line_test.go | 24 -- histogram_series_test.go | 32 -- last_value_annotation_test.go | 22 -- legend_test.go | 31 -- linear_regression_series_test.go | 78 ----- macd_series_test.go | 88 ----- matrix/matrix_test.go | 396 ---------------------- matrix/regression_test.go | 22 -- pie_chart_test.go | 69 ---- polynomial_regression_test.go | 35 -- seq/buffer_test.go | 192 ----------- seq/linear_test.go | 48 --- seq/random_test.go | 20 -- seq/seq_test.go | 95 ------ seq/time_test.go | 85 ----- sma_series_test.go | 113 ------- style_test.go | 214 ------------ text_test.go | 60 ---- tick_test.go | 60 ---- time_series_test.go | 69 ---- util/date_test.go | 148 -------- util/math_test.go | 151 --------- util/time_test.go | 64 ---- value_formatter_test.go | 59 ---- value_test.go | 69 ---- vector_renderer_test.go | 119 ------- xaxis_test.go | 67 ---- yaxis_test.go | 85 ----- 42 files changed, 4130 deletions(-) delete mode 100644 Makefile delete mode 100644 PROFANITY delete mode 100644 annotation_series_test.go delete mode 100644 bar_chart_test.go delete mode 100644 bollinger_band_series_test.go delete mode 100644 box_test.go delete mode 100644 chart_test.go delete mode 100644 concat_series_test.go delete mode 100644 continuous_range_test.go delete mode 100644 continuous_series_test.go delete mode 100644 drawing/color_test.go delete mode 100644 drawing/curve_test.go delete mode 100644 ema_series_test.go delete mode 100644 first_value_annotation_test.go delete mode 100644 grid_line_test.go delete mode 100644 histogram_series_test.go delete mode 100644 last_value_annotation_test.go delete mode 100644 legend_test.go delete mode 100644 linear_regression_series_test.go delete mode 100644 macd_series_test.go delete mode 100644 matrix/matrix_test.go delete mode 100644 matrix/regression_test.go delete mode 100644 pie_chart_test.go delete mode 100644 polynomial_regression_test.go delete mode 100644 seq/buffer_test.go delete mode 100644 seq/linear_test.go delete mode 100644 seq/random_test.go delete mode 100644 seq/seq_test.go delete mode 100644 seq/time_test.go delete mode 100644 sma_series_test.go delete mode 100644 style_test.go delete mode 100644 text_test.go delete mode 100644 tick_test.go delete mode 100644 time_series_test.go delete mode 100644 util/date_test.go delete mode 100644 util/math_test.go delete mode 100644 util/time_test.go delete mode 100644 value_formatter_test.go delete mode 100644 value_test.go delete mode 100644 vector_renderer_test.go delete mode 100644 xaxis_test.go delete mode 100644 yaxis_test.go diff --git a/Makefile b/Makefile deleted file mode 100644 index 84f7228..0000000 --- a/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -all: test - -ci: profanity coverage - -new-install: - @go get -v -u ./... - @go get -v -u github.com/blend/go-sdk/cmd/coverage - @go get -v -u github.com/blend/go-sdk/cmd/profanity - -test: - @go test ./... - -.PHONY: profanity -profanity: - @profanity -include="*.go,Makefile,README.md" - -coverage: - @coverage \ No newline at end of file diff --git a/PROFANITY b/PROFANITY deleted file mode 100644 index cdf3646..0000000 --- a/PROFANITY +++ /dev/null @@ -1,8 +0,0 @@ -- contains: "github.com/blend/go-sdk/" - message: "should not include go-sdk in this (outside tests)" - include: "*.go" - exclude: "*_test.go" -- contains: "github.com/blendlabs/go-" - message: "should not include blend go-* packages in this" - include: "*.go" - diff --git a/annotation_series_test.go b/annotation_series_test.go deleted file mode 100644 index b3f1579..0000000 --- a/annotation_series_test.go +++ /dev/null @@ -1,118 +0,0 @@ -package chart - -import ( - "image/color" - "testing" - - "github.com/blend/go-sdk/assert" - - "git.gutmet.org/go-chart.git/drawing" -) - -func TestAnnotationSeriesMeasure(t *testing.T) { - assert := assert.New(t) - - as := AnnotationSeries{ - Style: StyleShow(), - Annotations: []Value2{ - {XValue: 1.0, YValue: 1.0, Label: "1.0"}, - {XValue: 2.0, YValue: 2.0, Label: "2.0"}, - {XValue: 3.0, YValue: 3.0, Label: "3.0"}, - {XValue: 4.0, YValue: 4.0, Label: "4.0"}, - }, - } - - r, err := PNG(110, 110) - assert.Nil(err) - - f, err := GetDefaultFont() - assert.Nil(err) - - xrange := &ContinuousRange{ - Min: 1.0, - Max: 4.0, - Domain: 100, - } - yrange := &ContinuousRange{ - Min: 1.0, - Max: 4.0, - Domain: 100, - } - - cb := Box{ - Top: 5, - Left: 5, - Right: 105, - Bottom: 105, - } - sd := Style{ - FontSize: 10.0, - Font: f, - } - - box := as.Measure(r, cb, xrange, yrange, sd) - assert.False(box.IsZero()) - assert.Equal(-5.0, box.Top) - assert.Equal(5.0, box.Left) - assert.Equal(146.0, box.Right) //the top,left annotation sticks up 5px and out ~44px. - assert.Equal(115.0, box.Bottom) -} - -func TestAnnotationSeriesRender(t *testing.T) { - assert := assert.New(t) - - as := AnnotationSeries{ - Style: Style{ - Show: true, - FillColor: drawing.ColorWhite, - StrokeColor: drawing.ColorBlack, - }, - Annotations: []Value2{ - {XValue: 1.0, YValue: 1.0, Label: "1.0"}, - {XValue: 2.0, YValue: 2.0, Label: "2.0"}, - {XValue: 3.0, YValue: 3.0, Label: "3.0"}, - {XValue: 4.0, YValue: 4.0, Label: "4.0"}, - }, - } - - r, err := PNG(110, 110) - assert.Nil(err) - - f, err := GetDefaultFont() - assert.Nil(err) - - xrange := &ContinuousRange{ - Min: 1.0, - Max: 4.0, - Domain: 100, - } - yrange := &ContinuousRange{ - Min: 1.0, - Max: 4.0, - Domain: 100, - } - - cb := Box{ - Top: 5, - Left: 5, - Right: 105, - Bottom: 105, - } - sd := Style{ - FontSize: 10.0, - Font: f, - } - - as.Render(r, cb, xrange, yrange, sd) - - rr, isRaster := r.(*rasterRenderer) - assert.True(isRaster) - assert.NotNil(rr) - - c := rr.i.At(38, 70) - converted, isRGBA := color.RGBAModel.Convert(c).(color.RGBA) - assert.True(isRGBA) - assert.Equal(0, converted.R) - assert.Equal(0, converted.G) - assert.Equal(0, converted.B) -} diff --git a/bar_chart_test.go b/bar_chart_test.go deleted file mode 100644 index 14dc231..0000000 --- a/bar_chart_test.go +++ /dev/null @@ -1,320 +0,0 @@ -package chart - -import ( - "bytes" - "math" - "testing" - - assert "github.com/blend/go-sdk/assert" -) - -func TestBarChartRender(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{ - Width: 1024, - Title: "Test Title", - TitleStyle: StyleShow(), - XAxis: StyleShow(), - YAxis: YAxis{ - Style: StyleShow(), - }, - Bars: []Value{ - {Value: 1.0, Label: "One"}, - {Value: 2.0, Label: "Two"}, - {Value: 3.0, Label: "Three"}, - {Value: 4.0, Label: "Four"}, - {Value: 5.0, Label: "Five"}, - }, - } - - buf := bytes.NewBuffer([]byte{}) - err := bc.Render(PNG, buf) - assert.Nil(err) - assert.NotZero(buf.Len()) -} - -func TestBarChartRenderZero(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{ - Width: 1024, - Title: "Test Title", - TitleStyle: StyleShow(), - XAxis: StyleShow(), - YAxis: YAxis{ - Style: StyleShow(), - }, - Bars: []Value{ - {Value: 0.0, Label: "One"}, - {Value: 0.0, Label: "Two"}, - }, - } - - buf := bytes.NewBuffer([]byte{}) - err := bc.Render(PNG, buf) - assert.NotNil(err) -} - -func TestBarChartProps(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{} - - assert.Equal(DefaultDPI, bc.GetDPI()) - bc.DPI = 100 - assert.Equal(100, bc.GetDPI()) - - assert.Nil(bc.GetFont()) - f, err := GetDefaultFont() - assert.Nil(err) - bc.Font = f - assert.NotNil(bc.GetFont()) - - assert.Equal(DefaultChartWidth, bc.GetWidth()) - bc.Width = DefaultChartWidth - 1 - assert.Equal(DefaultChartWidth-1, bc.GetWidth()) - - assert.Equal(DefaultChartHeight, bc.GetHeight()) - bc.Height = DefaultChartHeight - 1 - assert.Equal(DefaultChartHeight-1, bc.GetHeight()) - - assert.Equal(DefaultBarSpacing, bc.GetBarSpacing()) - bc.BarSpacing = 150 - assert.Equal(150, bc.GetBarSpacing()) - - assert.Equal(DefaultBarWidth, bc.GetBarWidth()) - bc.BarWidth = 75 - assert.Equal(75, bc.GetBarWidth()) -} - -func TestBarChartRenderNoBars(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{} - err := bc.Render(PNG, bytes.NewBuffer([]byte{})) - assert.NotNil(err) -} - -func TestBarChartGetRanges(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{} - - yr := bc.getRanges() - assert.NotNil(yr) - assert.False(yr.IsZero()) - - assert.Equal(-math.MaxFloat64, yr.GetMax()) - assert.Equal(math.MaxFloat64, yr.GetMin()) -} - -func TestBarChartGetRangesBarsMinMax(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{ - Bars: []Value{ - {Value: 1.0}, - {Value: 10.0}, - }, - } - - yr := bc.getRanges() - assert.NotNil(yr) - assert.False(yr.IsZero()) - - assert.Equal(10, yr.GetMax()) - assert.Equal(1, yr.GetMin()) -} - -func TestBarChartGetRangesMinMax(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{ - YAxis: YAxis{ - Range: &ContinuousRange{ - Min: 5.0, - Max: 15.0, - }, - Ticks: []Tick{ - {Value: 7.0, Label: "Foo"}, - {Value: 11.0, Label: "Foo2"}, - }, - }, - Bars: []Value{ - {Value: 1.0}, - {Value: 10.0}, - }, - } - - yr := bc.getRanges() - assert.NotNil(yr) - assert.False(yr.IsZero()) - - assert.Equal(15, yr.GetMax()) - assert.Equal(5, yr.GetMin()) -} - -func TestBarChartGetRangesTicksMinMax(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{ - YAxis: YAxis{ - Ticks: []Tick{ - {Value: 7.0, Label: "Foo"}, - {Value: 11.0, Label: "Foo2"}, - }, - }, - Bars: []Value{ - {Value: 1.0}, - {Value: 10.0}, - }, - } - - yr := bc.getRanges() - assert.NotNil(yr) - assert.False(yr.IsZero()) - - assert.Equal(11, yr.GetMax()) - assert.Equal(7, yr.GetMin()) -} - -func TestBarChartHasAxes(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{} - assert.False(bc.hasAxes()) - bc.YAxis = YAxis{ - Style: StyleShow(), - } - - assert.True(bc.hasAxes()) -} - -func TestBarChartGetDefaultCanvasBox(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{} - b := bc.getDefaultCanvasBox() - assert.False(b.IsZero()) -} - -func TestBarChartSetRangeDomains(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{} - cb := bc.box() - yr := bc.getRanges() - yr2 := bc.setRangeDomains(cb, yr) - assert.NotZero(yr2.GetDomain()) -} - -func TestBarChartGetValueFormatters(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{} - vf := bc.getValueFormatters() - assert.NotNil(vf) - assert.Equal("1234.00", vf(1234.0)) - - bc.YAxis.ValueFormatter = func(_ interface{}) string { return "test" } - assert.Equal("test", bc.getValueFormatters()(1234)) -} - -func TestBarChartGetAxesTicks(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{ - Bars: []Value{ - {Value: 1.0}, - {Value: 2.0}, - {Value: 3.0}, - }, - } - - r, err := PNG(128, 128) - assert.Nil(err) - yr := bc.getRanges() - yf := bc.getValueFormatters() - - ticks := bc.getAxesTicks(r, yr, yf) - assert.Empty(ticks) - - bc.YAxis.Style.Show = true - ticks = bc.getAxesTicks(r, yr, yf) - assert.Len(ticks, 2) -} - -func TestBarChartCalculateEffectiveBarSpacing(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{ - Width: 1024, - BarWidth: 10, - Bars: []Value{ - {Value: 1.0, Label: "One"}, - {Value: 2.0, Label: "Two"}, - {Value: 3.0, Label: "Three"}, - {Value: 4.0, Label: "Four"}, - {Value: 5.0, Label: "Five"}, - }, - } - - spacing := bc.calculateEffectiveBarSpacing(bc.box()) - assert.NotZero(spacing) - - bc.BarWidth = 250 - spacing = bc.calculateEffectiveBarSpacing(bc.box()) - assert.Zero(spacing) -} - -func TestBarChartCalculateEffectiveBarWidth(t *testing.T) { - assert := assert.New(t) - - bc := BarChart{ - Width: 1024, - BarWidth: 10, - Bars: []Value{ - {Value: 1.0, Label: "One"}, - {Value: 2.0, Label: "Two"}, - {Value: 3.0, Label: "Three"}, - {Value: 4.0, Label: "Four"}, - {Value: 5.0, Label: "Five"}, - }, - } - - cb := bc.box() - - spacing := bc.calculateEffectiveBarSpacing(bc.box()) - assert.NotZero(spacing) - - barWidth := bc.calculateEffectiveBarWidth(bc.box(), spacing) - assert.Equal(10, barWidth) - - bc.BarWidth = 250 - spacing = bc.calculateEffectiveBarSpacing(bc.box()) - assert.Zero(spacing) - barWidth = bc.calculateEffectiveBarWidth(bc.box(), spacing) - assert.Equal(199, barWidth) - - assert.Equal(cb.Width()+1, bc.calculateTotalBarWidth(barWidth, spacing)) - - bw, bs, total := bc.calculateScaledTotalWidth(cb) - assert.Equal(spacing, bs) - assert.Equal(barWidth, bw) - assert.Equal(cb.Width()+1, total) -} - -func TestBarChatGetTitleFontSize(t *testing.T) { - assert := assert.New(t) - size := BarChart{Width: 2049, Height: 2049}.getTitleFontSize() - assert.Equal(48, size) - size = BarChart{Width: 1025, Height: 1025}.getTitleFontSize() - assert.Equal(24, size) - size = BarChart{Width: 513, Height: 513}.getTitleFontSize() - assert.Equal(18, size) - size = BarChart{Width: 257, Height: 257}.getTitleFontSize() - assert.Equal(12, size) - size = BarChart{Width: 128, Height: 128}.getTitleFontSize() - assert.Equal(10, size) -} diff --git a/bollinger_band_series_test.go b/bollinger_band_series_test.go deleted file mode 100644 index 8d1243a..0000000 --- a/bollinger_band_series_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package chart - -import ( - "fmt" - "math" - "testing" - - "github.com/blend/go-sdk/assert" - "git.gutmet.org/go-chart.git/seq" -) - -func TestBollingerBandSeries(t *testing.T) { - assert := assert.New(t) - - s1 := mockValuesProvider{ - X: seq.Range(1.0, 100.0), - Y: seq.RandomValuesWithMax(100, 1024), - } - - bbs := &BollingerBandsSeries{ - InnerSeries: s1, - } - - xvalues := make([]float64, 100) - y1values := make([]float64, 100) - y2values := make([]float64, 100) - - for x := 0; x < 100; x++ { - xvalues[x], y1values[x], y2values[x] = bbs.GetBoundedValues(x) - } - - for x := bbs.GetPeriod(); x < 100; x++ { - assert.True(y1values[x] > y2values[x], fmt.Sprintf("%v vs. %v", y1values[x], y2values[x])) - } -} - -func TestBollingerBandLastValue(t *testing.T) { - assert := assert.New(t) - - s1 := mockValuesProvider{ - X: seq.Range(1.0, 100.0), - Y: seq.Range(1.0, 100.0), - } - - bbs := &BollingerBandsSeries{ - InnerSeries: s1, - } - - x, y1, y2 := bbs.GetBoundedLastValues() - assert.Equal(100.0, x) - assert.Equal(101, math.Floor(y1)) - assert.Equal(83, math.Floor(y2)) -} diff --git a/box_test.go b/box_test.go deleted file mode 100644 index 4bc3f71..0000000 --- a/box_test.go +++ /dev/null @@ -1,188 +0,0 @@ -package chart - -import ( - "math" - "testing" - - "github.com/blend/go-sdk/assert" -) - -func TestBoxClone(t *testing.T) { - assert := assert.New(t) - a := Box{Top: 5, Left: 5, Right: 15, Bottom: 15} - b := a.Clone() - assert.True(a.Equals(b)) - assert.True(b.Equals(a)) -} - -func TestBoxEquals(t *testing.T) { - assert := assert.New(t) - - a := Box{Top: 5, Left: 5, Right: 15, Bottom: 15} - b := Box{Top: 10, Left: 10, Right: 30, Bottom: 30} - c := Box{Top: 5, Left: 5, Right: 15, Bottom: 15} - assert.True(a.Equals(a)) - assert.True(a.Equals(c)) - assert.True(c.Equals(a)) - assert.False(a.Equals(b)) - assert.False(c.Equals(b)) - assert.False(b.Equals(a)) - assert.False(b.Equals(c)) -} - -func TestBoxIsBiggerThan(t *testing.T) { - assert := assert.New(t) - - a := Box{Top: 5, Left: 5, Right: 25, Bottom: 25} - b := Box{Top: 10, Left: 10, Right: 20, Bottom: 20} // only half bigger - c := Box{Top: 1, Left: 1, Right: 30, Bottom: 30} //bigger - assert.True(a.IsBiggerThan(b)) - assert.False(a.IsBiggerThan(c)) - assert.True(c.IsBiggerThan(a)) -} - -func TestBoxIsSmallerThan(t *testing.T) { - assert := assert.New(t) - - a := Box{Top: 5, Left: 5, Right: 25, Bottom: 25} - b := Box{Top: 10, Left: 10, Right: 20, Bottom: 20} // only half bigger - c := Box{Top: 1, Left: 1, Right: 30, Bottom: 30} //bigger - assert.False(a.IsSmallerThan(b)) - assert.True(a.IsSmallerThan(c)) - assert.False(c.IsSmallerThan(a)) -} - -func TestBoxGrow(t *testing.T) { - assert := assert.New(t) - - a := Box{Top: 1, Left: 2, Right: 15, Bottom: 15} - b := Box{Top: 4, Left: 5, Right: 30, Bottom: 35} - c := a.Grow(b) - assert.False(c.Equals(b)) - assert.False(c.Equals(a)) - assert.Equal(1, c.Top) - assert.Equal(2, c.Left) - assert.Equal(30, c.Right) - assert.Equal(35, c.Bottom) -} - -func TestBoxFit(t *testing.T) { - assert := assert.New(t) - - a := Box{Top: 64, Left: 64, Right: 192, Bottom: 192} - b := Box{Top: 16, Left: 16, Right: 256, Bottom: 170} - c := Box{Top: 16, Left: 16, Right: 170, Bottom: 256} - - fab := a.Fit(b) - assert.Equal(a.Left, fab.Left) - assert.Equal(a.Right, fab.Right) - assert.True(fab.Top < fab.Bottom) - assert.True(fab.Left < fab.Right) - assert.True(math.Abs(b.Aspect()-fab.Aspect()) < 0.02) - - fac := a.Fit(c) - assert.Equal(a.Top, fac.Top) - assert.Equal(a.Bottom, fac.Bottom) - assert.True(math.Abs(c.Aspect()-fac.Aspect()) < 0.02) -} - -func TestBoxConstrain(t *testing.T) { - assert := assert.New(t) - - a := Box{Top: 64, Left: 64, Right: 192, Bottom: 192} - b := Box{Top: 16, Left: 16, Right: 256, Bottom: 170} - c := Box{Top: 16, Left: 16, Right: 170, Bottom: 256} - - cab := a.Constrain(b) - assert.Equal(64, cab.Top) - assert.Equal(64, cab.Left) - assert.Equal(192, cab.Right) - assert.Equal(170, cab.Bottom) - - cac := a.Constrain(c) - assert.Equal(64, cac.Top) - assert.Equal(64, cac.Left) - assert.Equal(170, cac.Right) - assert.Equal(192, cac.Bottom) -} - -func TestBoxOuterConstrain(t *testing.T) { - assert := assert.New(t) - - box := NewBox(0, 0, 100, 100) - canvas := NewBox(5, 5, 95, 95) - taller := NewBox(-10, 5, 50, 50) - - c := canvas.OuterConstrain(box, taller) - assert.Equal(15, c.Top, c.String()) - assert.Equal(5, c.Left, c.String()) - assert.Equal(95, c.Right, c.String()) - assert.Equal(95, c.Bottom, c.String()) - - wider := NewBox(5, 5, 110, 50) - d := canvas.OuterConstrain(box, wider) - assert.Equal(5, d.Top, d.String()) - assert.Equal(5, d.Left, d.String()) - assert.Equal(85, d.Right, d.String()) - assert.Equal(95, d.Bottom, d.String()) -} - -func TestBoxShift(t *testing.T) { - assert := assert.New(t) - - b := Box{ - Top: 5, - Left: 5, - Right: 10, - Bottom: 10, - } - - shifted := b.Shift(1, 2) - assert.Equal(7, shifted.Top) - assert.Equal(6, shifted.Left) - assert.Equal(11, shifted.Right) - assert.Equal(12, shifted.Bottom) -} - -func TestBoxCenter(t *testing.T) { - assert := assert.New(t) - - b := Box{ - Top: 10, - Left: 10, - Right: 20, - Bottom: 30, - } - cx, cy := b.Center() - assert.Equal(15, cx) - assert.Equal(20, cy) -} - -func TestBoxCornersCenter(t *testing.T) { - assert := assert.New(t) - - bc := BoxCorners{ - TopLeft: Point{5, 5}, - TopRight: Point{15, 5}, - BottomRight: Point{15, 15}, - BottomLeft: Point{5, 15}, - } - - cx, cy := bc.Center() - assert.Equal(10, cx) - assert.Equal(10, cy) -} - -func TestBoxCornersRotate(t *testing.T) { - assert := assert.New(t) - - bc := BoxCorners{ - TopLeft: Point{5, 5}, - TopRight: Point{15, 5}, - BottomRight: Point{15, 15}, - BottomLeft: Point{5, 15}, - } - - rotated := bc.Rotate(45) - assert.True(rotated.TopLeft.Equals(Point{10, 3}), rotated.String()) -} diff --git a/chart_test.go b/chart_test.go deleted file mode 100644 index dc150dc..0000000 --- a/chart_test.go +++ /dev/null @@ -1,556 +0,0 @@ -package chart - -import ( - "bytes" - "image" - "image/png" - "math" - "testing" - "time" - - - "github.com/blend/go-sdk/assert" - - "git.gutmet.org/go-chart.git/drawing" - "git.gutmet.org/go-chart.git/seq" -) - -func TestChartGetDPI(t *testing.T) { - assert := assert.New(t) - - unset := Chart{} - assert.Equal(DefaultDPI, unset.GetDPI()) - assert.Equal(192, unset.GetDPI(192)) - - set := Chart{DPI: 128} - assert.Equal(128, set.GetDPI()) - assert.Equal(128, set.GetDPI(192)) -} - -func TestChartGetFont(t *testing.T) { - assert := assert.New(t) - - f, err := GetDefaultFont() - assert.Nil(err) - - unset := Chart{} - assert.Nil(unset.GetFont()) - - set := Chart{Font: f} - assert.NotNil(set.GetFont()) -} - -func TestChartGetWidth(t *testing.T) { - assert := assert.New(t) - - unset := Chart{} - assert.Equal(DefaultChartWidth, unset.GetWidth()) - - set := Chart{Width: DefaultChartWidth + 10} - assert.Equal(DefaultChartWidth+10, set.GetWidth()) -} - -func TestChartGetHeight(t *testing.T) { - assert := assert.New(t) - - unset := Chart{} - assert.Equal(DefaultChartHeight, unset.GetHeight()) - - set := Chart{Height: DefaultChartHeight + 10} - assert.Equal(DefaultChartHeight+10, set.GetHeight()) -} - -func TestChartGetRanges(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - Series: []Series{ - ContinuousSeries{ - XValues: []float64{-2.0, -1.0, 0, 1.0, 2.0}, - YValues: []float64{1.0, 2.0, 3.0, 4.0, 4.5}, - }, - ContinuousSeries{ - XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, - YValues: []float64{-2.1, -1.0, 0, 1.0, 2.0}, - }, - ContinuousSeries{ - YAxis: YAxisSecondary, - XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, - YValues: []float64{10.0, 11.0, 12.0, 13.0, 14.0}, - }, - }, - } - - xrange, yrange, yrangeAlt := c.getRanges() - assert.Equal(-2.0, xrange.GetMin()) - assert.Equal(5.0, xrange.GetMax()) - - assert.Equal(-2.1, yrange.GetMin()) - assert.Equal(4.5, yrange.GetMax()) - - assert.Equal(10.0, yrangeAlt.GetMin()) - assert.Equal(14.0, yrangeAlt.GetMax()) - - cSet := Chart{ - XAxis: XAxis{ - Range: &ContinuousRange{Min: 9.8, Max: 19.8}, - }, - YAxis: YAxis{ - Range: &ContinuousRange{Min: 9.9, Max: 19.9}, - }, - YAxisSecondary: YAxis{ - Range: &ContinuousRange{Min: 9.7, Max: 19.7}, - }, - Series: []Series{ - ContinuousSeries{ - XValues: []float64{-2.0, -1.0, 0, 1.0, 2.0}, - YValues: []float64{1.0, 2.0, 3.0, 4.0, 4.5}, - }, - ContinuousSeries{ - XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, - YValues: []float64{-2.1, -1.0, 0, 1.0, 2.0}, - }, - ContinuousSeries{ - YAxis: YAxisSecondary, - XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, - YValues: []float64{10.0, 11.0, 12.0, 13.0, 14.0}, - }, - }, - } - - xr2, yr2, yra2 := cSet.getRanges() - assert.Equal(9.8, xr2.GetMin()) - assert.Equal(19.8, xr2.GetMax()) - - assert.Equal(9.9, yr2.GetMin()) - assert.Equal(19.9, yr2.GetMax()) - - assert.Equal(9.7, yra2.GetMin()) - assert.Equal(19.7, yra2.GetMax()) -} - -func TestChartGetRangesUseTicks(t *testing.T) { - assert := assert.New(t) - - // this test asserts that ticks should supercede manual ranges when generating the overall ranges. - - c := Chart{ - YAxis: YAxis{ - Ticks: []Tick{ - {0.0, "Zero"}, - {1.0, "1.0"}, - {2.0, "2.0"}, - {3.0, "3.0"}, - {4.0, "4.0"}, - {5.0, "Five"}, - }, - Range: &ContinuousRange{ - Min: -5.0, - Max: 5.0, - }, - }, - Series: []Series{ - ContinuousSeries{ - XValues: []float64{-2.0, -1.0, 0, 1.0, 2.0}, - YValues: []float64{1.0, 2.0, 3.0, 4.0, 4.5}, - }, - }, - } - - xr, yr, yar := c.getRanges() - assert.Equal(-2.0, xr.GetMin()) - assert.Equal(2.0, xr.GetMax()) - assert.Equal(0.0, yr.GetMin()) - assert.Equal(5.0, yr.GetMax()) - assert.True(yar.IsZero(), yar.String()) -} - -func TestChartGetRangesUseUserRanges(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - YAxis: YAxis{ - Range: &ContinuousRange{ - Min: -5.0, - Max: 5.0, - }, - }, - Series: []Series{ - ContinuousSeries{ - XValues: []float64{-2.0, -1.0, 0, 1.0, 2.0}, - YValues: []float64{1.0, 2.0, 3.0, 4.0, 4.5}, - }, - }, - } - - xr, yr, yar := c.getRanges() - assert.Equal(-2.0, xr.GetMin()) - assert.Equal(2.0, xr.GetMax()) - assert.Equal(-5.0, yr.GetMin()) - assert.Equal(5.0, yr.GetMax()) - assert.True(yar.IsZero(), yar.String()) -} - -func TestChartGetBackgroundStyle(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - Background: Style{ - FillColor: drawing.ColorBlack, - }, - } - - bs := c.getBackgroundStyle() - assert.Equal(bs.FillColor.String(), drawing.ColorBlack.String()) -} - -func TestChartGetCanvasStyle(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - Canvas: Style{ - FillColor: drawing.ColorBlack, - }, - } - - bs := c.getCanvasStyle() - assert.Equal(bs.FillColor.String(), drawing.ColorBlack.String()) -} - -func TestChartGetDefaultCanvasBox(t *testing.T) { - assert := assert.New(t) - - c := Chart{} - canvasBoxDefault := c.getDefaultCanvasBox() - assert.False(canvasBoxDefault.IsZero()) - assert.Equal(DefaultBackgroundPadding.Top, canvasBoxDefault.Top) - assert.Equal(DefaultBackgroundPadding.Left, canvasBoxDefault.Left) - assert.Equal(c.GetWidth()-DefaultBackgroundPadding.Right, canvasBoxDefault.Right) - assert.Equal(c.GetHeight()-DefaultBackgroundPadding.Bottom, canvasBoxDefault.Bottom) - - custom := Chart{ - Background: Style{ - Padding: Box{ - Top: DefaultBackgroundPadding.Top + 1, - Left: DefaultBackgroundPadding.Left + 1, - Right: DefaultBackgroundPadding.Right + 1, - Bottom: DefaultBackgroundPadding.Bottom + 1, - }, - }, - } - canvasBoxCustom := custom.getDefaultCanvasBox() - assert.False(canvasBoxCustom.IsZero()) - assert.Equal(DefaultBackgroundPadding.Top+1, canvasBoxCustom.Top) - assert.Equal(DefaultBackgroundPadding.Left+1, canvasBoxCustom.Left) - assert.Equal(c.GetWidth()-(DefaultBackgroundPadding.Right+1), canvasBoxCustom.Right) - assert.Equal(c.GetHeight()-(DefaultBackgroundPadding.Bottom+1), canvasBoxCustom.Bottom) -} - -func TestChartGetValueFormatters(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - Series: []Series{ - ContinuousSeries{ - XValues: []float64{-2.0, -1.0, 0, 1.0, 2.0}, - YValues: []float64{1.0, 2.0, 3.0, 4.0, 4.5}, - }, - ContinuousSeries{ - XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, - YValues: []float64{-2.1, -1.0, 0, 1.0, 2.0}, - }, - ContinuousSeries{ - YAxis: YAxisSecondary, - XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, - YValues: []float64{10.0, 11.0, 12.0, 13.0, 14.0}, - }, - }, - } - - dxf, dyf, dyaf := c.getValueFormatters() - assert.NotNil(dxf) - assert.NotNil(dyf) - assert.NotNil(dyaf) -} - -func TestChartHasAxes(t *testing.T) { - assert := assert.New(t) - - assert.False(Chart{}.hasAxes()) - - x := Chart{ - XAxis: XAxis{ - Style: StyleShow(), - }, - } - assert.True(x.hasAxes()) - - y := Chart{ - YAxis: YAxis{ - Style: StyleShow(), - }, - } - assert.True(y.hasAxes()) - - ya := Chart{ - YAxisSecondary: YAxis{ - Style: StyleShow(), - }, - } - assert.True(ya.hasAxes()) -} - -func TestChartGetAxesTicks(t *testing.T) { - assert := assert.New(t) - - r, err := PNG(1024, 1024) - assert.Nil(err) - - c := Chart{ - XAxis: XAxis{ - Style: StyleShow(), - Range: &ContinuousRange{Min: 9.8, Max: 19.8}, - }, - YAxis: YAxis{ - Style: StyleShow(), - Range: &ContinuousRange{Min: 9.9, Max: 19.9}, - }, - YAxisSecondary: YAxis{ - Style: StyleShow(), - Range: &ContinuousRange{Min: 9.7, Max: 19.7}, - }, - } - xr, yr, yar := c.getRanges() - - xt, yt, yat := c.getAxesTicks(r, xr, yr, yar, FloatValueFormatter, FloatValueFormatter, FloatValueFormatter) - assert.NotEmpty(xt) - assert.NotEmpty(yt) - assert.NotEmpty(yat) -} - -func TestChartSingleSeries(t *testing.T) { - assert := assert.New(t) - now := time.Now() - c := Chart{ - Title: "Hello!", - TitleStyle: StyleShow(), - Width: 1024, - Height: 400, - YAxis: YAxis{ - Style: StyleShow(), - Range: &ContinuousRange{ - Min: 0.0, - Max: 4.0, - }, - }, - XAxis: XAxis{ - Style: StyleShow(), - }, - Series: []Series{ - TimeSeries{ - Name: "goog", - XValues: []time.Time{now.AddDate(0, 0, -3), now.AddDate(0, 0, -2), now.AddDate(0, 0, -1)}, - YValues: []float64{1.0, 2.0, 3.0}, - }, - }, - } - - buffer := bytes.NewBuffer([]byte{}) - c.Render(PNG, buffer) - assert.NotEmpty(buffer.Bytes()) -} - -func TestChartRegressionBadRanges(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - Series: []Series{ - ContinuousSeries{ - XValues: []float64{math.Inf(1), math.Inf(1), math.Inf(1), math.Inf(1), math.Inf(1)}, - YValues: []float64{1.0, 2.0, 3.0, 4.0, 4.5}, - }, - }, - } - buffer := bytes.NewBuffer([]byte{}) - c.Render(PNG, buffer) - assert.True(true, "Render needs to finish.") -} - -func TestChartRegressionBadRangesByUser(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - YAxis: YAxis{ - Range: &ContinuousRange{ - Min: math.Inf(-1), - Max: math.Inf(1), // this could really happen? eh. - }, - }, - Series: []Series{ - ContinuousSeries{ - XValues: seq.Range(1.0, 10.0), - YValues: seq.Range(1.0, 10.0), - }, - }, - } - buffer := bytes.NewBuffer([]byte{}) - c.Render(PNG, buffer) - assert.True(true, "Render needs to finish.") -} - -func TestChartValidatesSeries(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - Series: []Series{ - ContinuousSeries{ - XValues: seq.Range(1.0, 10.0), - YValues: seq.Range(1.0, 10.0), - }, - }, - } - - assert.Nil(c.validateSeries()) - - c = Chart{ - Series: []Series{ - ContinuousSeries{ - XValues: seq.Range(1.0, 10.0), - }, - }, - } - - assert.NotNil(c.validateSeries()) -} - -func TestChartCheckRanges(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - Series: []Series{ - ContinuousSeries{ - XValues: []float64{1.0, 2.0}, - YValues: []float64{3.10, 3.14}, - }, - }, - } - - xr, yr, yra := c.getRanges() - assert.Nil(c.checkRanges(xr, yr, yra)) -} - -func TestChartCheckRangesWithRanges(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - XAxis: XAxis{ - Range: &ContinuousRange{ - Min: 0, - Max: 10, - }, - }, - YAxis: YAxis{ - Range: &ContinuousRange{ - Min: 0, - Max: 5, - }, - }, - Series: []Series{ - ContinuousSeries{ - XValues: []float64{1.0, 2.0}, - YValues: []float64{3.14, 3.14}, - }, - }, - } - - xr, yr, yra := c.getRanges() - assert.Nil(c.checkRanges(xr, yr, yra)) -} - -func at(i image.Image, x, y int) drawing.Color { - return drawing.ColorFromAlphaMixedRGBA(i.At(x, y).RGBA()) -} - -func TestChartE2ELine(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - Height: 50, - Width: 50, - Canvas: Style{ - Padding: BoxZero, - }, - Background: Style{ - Padding: BoxZero, - }, - Series: []Series{ - ContinuousSeries{ - XValues: seq.RangeWithStep(0, 4, 1), - YValues: seq.RangeWithStep(0, 4, 1), - }, - }, - } - - var buffer = &bytes.Buffer{} - err := c.Render(PNG, buffer) - assert.Nil(err) - - // do color tests ... - - i, err := png.Decode(buffer) - assert.Nil(err) - - // test the bottom and top of the line - assert.Equal(drawing.ColorWhite, at(i, 0, 0)) - assert.Equal(drawing.ColorWhite, at(i, 49, 49)) - - // test a line mid point - defaultSeriesColor := GetDefaultColor(0) - assert.Equal(defaultSeriesColor, at(i, 0, 49)) - assert.Equal(defaultSeriesColor, at(i, 49, 0)) - assert.Equal(drawing.ColorFromHex("bddbf6"), at(i, 24, 24)) -} - -func TestChartE2ELineWithFill(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - Height: 50, - Width: 50, - Canvas: Style{ - Padding: BoxZero, - }, - Background: Style{ - Padding: BoxZero, - }, - Series: []Series{ - ContinuousSeries{ - Style: Style{ - Show: true, - StrokeColor: drawing.ColorBlue, - FillColor: drawing.ColorRed, - }, - XValues: seq.RangeWithStep(0, 4, 1), - YValues: seq.RangeWithStep(0, 4, 1), - }, - }, - } - - var buffer = &bytes.Buffer{} - err := c.Render(PNG, buffer) - assert.Nil(err) - - // do color tests ... - - i, err := png.Decode(buffer) - assert.Nil(err) - - // test the bottom and top of the line - assert.Equal(drawing.ColorWhite, at(i, 0, 0)) - assert.Equal(drawing.ColorRed, at(i, 49, 49)) - - // test a line mid point - defaultSeriesColor := drawing.ColorBlue - assert.Equal(defaultSeriesColor, at(i, 0, 49)) - assert.Equal(defaultSeriesColor, at(i, 49, 0)) -} diff --git a/concat_series_test.go b/concat_series_test.go deleted file mode 100644 index 7ee422c..0000000 --- a/concat_series_test.go +++ /dev/null @@ -1,42 +0,0 @@ -package chart - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" - "git.gutmet.org/go-chart.git/seq" -) - -func TestConcatSeries(t *testing.T) { - assert := assert.New(t) - - s1 := ContinuousSeries{ - XValues: seq.Range(1.0, 10.0), - YValues: seq.Range(1.0, 10.0), - } - - s2 := ContinuousSeries{ - XValues: seq.Range(11, 20.0), - YValues: seq.Range(10.0, 1.0), - } - - s3 := ContinuousSeries{ - XValues: seq.Range(21, 30.0), - YValues: seq.Range(1.0, 10.0), - } - - cs := ConcatSeries([]Series{s1, s2, s3}) - assert.Equal(30, cs.Len()) - - x0, y0 := cs.GetValue(0) - assert.Equal(1.0, x0) - assert.Equal(1.0, y0) - - xm, ym := cs.GetValue(19) - assert.Equal(20.0, xm) - assert.Equal(1.0, ym) - - xn, yn := cs.GetValue(29) - assert.Equal(30.0, xn) - assert.Equal(10.0, yn) -} diff --git a/continuous_range_test.go b/continuous_range_test.go deleted file mode 100644 index 12f581b..0000000 --- a/continuous_range_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package chart - -import ( - "testing" - - "github.com/blend/go-sdk/assert" - "git.gutmet.org/go-chart.git/util" -) - -func TestRangeTranslate(t *testing.T) { - assert := assert.New(t) - values := []float64{1.0, 2.0, 2.5, 2.7, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0} - r := ContinuousRange{Domain: 1000} - r.Min, r.Max = util.Math.MinAndMax(values...) - - // delta = ~7.0 - // value = ~5.0 - // domain = ~1000 - // 5/8 * 1000 ~= - assert.Equal(0, r.Translate(1.0)) - assert.Equal(1000, r.Translate(8.0)) - assert.Equal(572, r.Translate(5.0)) -} diff --git a/continuous_series_test.go b/continuous_series_test.go deleted file mode 100644 index 7d5359c..0000000 --- a/continuous_series_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package chart - -import ( - "fmt" - "testing" - - assert "github.com/blend/go-sdk/assert" - "git.gutmet.org/go-chart.git/seq" -) - -func TestContinuousSeries(t *testing.T) { - assert := assert.New(t) - - cs := ContinuousSeries{ - Name: "Test Series", - XValues: seq.Range(1.0, 10.0), - YValues: seq.Range(1.0, 10.0), - } - - assert.Equal("Test Series", cs.GetName()) - assert.Equal(10, cs.Len()) - x0, y0 := cs.GetValues(0) - assert.Equal(1.0, x0) - assert.Equal(1.0, y0) - - xn, yn := cs.GetValues(9) - assert.Equal(10.0, xn) - assert.Equal(10.0, yn) - - xn, yn = cs.GetLastValues() - assert.Equal(10.0, xn) - assert.Equal(10.0, yn) -} - -func TestContinuousSeriesValueFormatter(t *testing.T) { - assert := assert.New(t) - - cs := ContinuousSeries{ - XValueFormatter: func(v interface{}) string { - return fmt.Sprintf("%f foo", v) - }, - YValueFormatter: func(v interface{}) string { - return fmt.Sprintf("%f bar", v) - }, - } - - xf, yf := cs.GetValueFormatters() - assert.Equal("0.100000 foo", xf(0.1)) - assert.Equal("0.100000 bar", yf(0.1)) -} - -func TestContinuousSeriesValidate(t *testing.T) { - assert := assert.New(t) - - cs := ContinuousSeries{ - Name: "Test Series", - XValues: seq.Range(1.0, 10.0), - YValues: seq.Range(1.0, 10.0), - } - assert.Nil(cs.Validate()) - - cs = ContinuousSeries{ - Name: "Test Series", - XValues: seq.Range(1.0, 10.0), - } - assert.NotNil(cs.Validate()) - - cs = ContinuousSeries{ - Name: "Test Series", - YValues: seq.Range(1.0, 10.0), - } - assert.NotNil(cs.Validate()) -} diff --git a/drawing/color_test.go b/drawing/color_test.go deleted file mode 100644 index 1b38ba6..0000000 --- a/drawing/color_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package drawing - -import ( - "testing" - - "image/color" - - "github.com/blend/go-sdk/assert" -) - -func TestColorFromHex(t *testing.T) { - assert := assert.New(t) - - white := ColorFromHex("FFFFFF") - assert.Equal(ColorWhite, white) - - shortWhite := ColorFromHex("FFF") - assert.Equal(ColorWhite, shortWhite) - - black := ColorFromHex("000000") - assert.Equal(ColorBlack, black) - - shortBlack := ColorFromHex("000") - assert.Equal(ColorBlack, shortBlack) - - red := ColorFromHex("FF0000") - assert.Equal(ColorRed, red) - - shortRed := ColorFromHex("F00") - assert.Equal(ColorRed, shortRed) - - green := ColorFromHex("00FF00") - assert.Equal(ColorGreen, green) - - shortGreen := ColorFromHex("0F0") - assert.Equal(ColorGreen, shortGreen) - - blue := ColorFromHex("0000FF") - assert.Equal(ColorBlue, blue) - - shortBlue := ColorFromHex("00F") - assert.Equal(ColorBlue, shortBlue) -} - -func TestColorFromAlphaMixedRGBA(t *testing.T) { - assert := assert.New(t) - - black := ColorFromAlphaMixedRGBA(color.Black.RGBA()) - assert.True(black.Equals(ColorBlack), black.String()) - - white := ColorFromAlphaMixedRGBA(color.White.RGBA()) - assert.True(white.Equals(ColorWhite), white.String()) -} diff --git a/drawing/curve_test.go b/drawing/curve_test.go deleted file mode 100644 index 3e792eb..0000000 --- a/drawing/curve_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package drawing - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" -) - -type point struct { - X, Y float64 -} - -type mockLine struct { - inner []point -} - -func (ml *mockLine) LineTo(x, y float64) { - ml.inner = append(ml.inner, point{x, y}) -} - -func (ml mockLine) Len() int { - return len(ml.inner) -} - -func TestTraceQuad(t *testing.T) { - assert := assert.New(t) - - // Quad - // x1, y1, cpx1, cpy2, x2, y2 float64 - // do the 9->12 circle segment - quad := []float64{10, 20, 20, 20, 20, 10} - liner := &mockLine{} - TraceQuad(liner, quad, 0.5) - assert.NotZero(liner.Len()) -} diff --git a/ema_series_test.go b/ema_series_test.go deleted file mode 100644 index 9af2a3e..0000000 --- a/ema_series_test.go +++ /dev/null @@ -1,106 +0,0 @@ -package chart - -import ( - "testing" - - "github.com/blend/go-sdk/assert" - "git.gutmet.org/go-chart.git/seq" -) - -var ( - emaXValues = seq.Range(1.0, 50.0) - emaYValues = []float64{ - 1, 2, 3, 4, 5, 4, 3, 2, - 1, 2, 3, 4, 5, 4, 3, 2, - 1, 2, 3, 4, 5, 4, 3, 2, - 1, 2, 3, 4, 5, 4, 3, 2, - 1, 2, 3, 4, 5, 4, 3, 2, - 1, 2, 3, 4, 5, 4, 3, 2, - 1, 2, - } - emaExpected = []float64{ - 1, - 1.074074074, - 1.216735254, - 1.422903013, - 1.68787316, - 1.859141815, - 1.943649828, - 1.947823915, - 1.877614736, - 1.886680311, - 1.969148437, - 2.119581886, - 2.33294619, - 2.456431658, - 2.496695979, - 2.459903685, - 2.351762671, - 2.325706177, - 2.375653867, - 2.495975803, - 2.681459077, - 2.779128775, - 2.795489607, - 2.73656445, - 2.607930047, - 2.562898191, - 2.595276103, - 2.699329725, - 2.869749746, - 2.953471987, - 2.956918506, - 2.886035654, - 2.746329309, - 2.691045657, - 2.713931163, - 2.809195522, - 2.971477335, - 3.047664199, - 3.044133518, - 2.966790294, - 2.821102124, - 2.760279745, - 2.778036801, - 2.868552593, - 3.026437586, - 3.098553321, - 3.091253075, - 3.010419514, - 2.86149955, - 2.797684768, - } - emaDelta = 0.0001 -) - -func TestEMASeries(t *testing.T) { - assert := assert.New(t) - - mockSeries := mockValuesProvider{ - emaXValues, - emaYValues, - } - assert.Equal(50, mockSeries.Len()) - - ema := &EMASeries{ - InnerSeries: mockSeries, - Period: 26, - } - - sig := ema.GetSigma() - assert.Equal(2.0/(26.0+1), sig) - - var yvalues []float64 - for x := 0; x < ema.Len(); x++ { - _, y := ema.GetValues(x) - yvalues = append(yvalues, y) - } - - for index, yv := range yvalues { - assert.InDelta(yv, emaExpected[index], emaDelta) - } - - lvx, lvy := ema.GetLastValues() - assert.Equal(50.0, lvx) - assert.InDelta(lvy, emaExpected[49], emaDelta) -} diff --git a/first_value_annotation_test.go b/first_value_annotation_test.go deleted file mode 100644 index 1f1d4cf..0000000 --- a/first_value_annotation_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package chart - -import ( - "testing" - - "github.com/blend/go-sdk/assert" -) - -func TestFirstValueAnnotation(t *testing.T) { - assert := assert.New(t) - - series := ContinuousSeries{ - XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, - YValues: []float64{5.0, 3.0, 3.0, 2.0, 1.0}, - } - - fva := FirstValueAnnotation(series) - assert.NotEmpty(fva.Annotations) - fvaa := fva.Annotations[0] - assert.Equal(1, fvaa.XValue) - assert.Equal(5, fvaa.YValue) -} diff --git a/grid_line_test.go b/grid_line_test.go deleted file mode 100644 index cbaedec..0000000 --- a/grid_line_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package chart - -import ( - "testing" - - "github.com/blend/go-sdk/assert" -) - -func TestGenerateGridLines(t *testing.T) { - assert := assert.New(t) - - ticks := []Tick{ - {Value: 1.0, Label: "1.0"}, - {Value: 2.0, Label: "2.0"}, - {Value: 3.0, Label: "3.0"}, - {Value: 4.0, Label: "4.0"}, - } - - gl := GenerateGridLines(ticks, Style{}, Style{}) - assert.Len(gl, 2) - - assert.Equal(2.0, gl[0].Value) - assert.Equal(3.0, gl[1].Value) -} diff --git a/histogram_series_test.go b/histogram_series_test.go deleted file mode 100644 index 2eef96e..0000000 --- a/histogram_series_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package chart - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" - "git.gutmet.org/go-chart.git/seq" -) - -func TestHistogramSeries(t *testing.T) { - assert := assert.New(t) - - cs := ContinuousSeries{ - Name: "Test Series", - XValues: seq.Range(1.0, 20.0), - YValues: seq.Range(10.0, -10.0), - } - - hs := HistogramSeries{ - InnerSeries: cs, - } - - for x := 0; x < hs.Len(); x++ { - csx, csy := cs.GetValues(0) - hsx, hsy1, hsy2 := hs.GetBoundedValues(0) - assert.Equal(csx, hsx) - assert.True(hsy1 > 0) - assert.True(hsy2 <= 0) - assert.True(csy < 0 || (csy > 0 && csy == hsy1)) - assert.True(csy > 0 || (csy < 0 && csy == hsy2)) - } -} diff --git a/last_value_annotation_test.go b/last_value_annotation_test.go deleted file mode 100644 index 3d1931f..0000000 --- a/last_value_annotation_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package chart - -import ( - "testing" - - "github.com/blend/go-sdk/assert" -) - -func TestLastValueAnnotation(t *testing.T) { - assert := assert.New(t) - - series := ContinuousSeries{ - XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, - YValues: []float64{5.0, 3.0, 3.0, 2.0, 1.0}, - } - - lva := LastValueAnnotation(series) - assert.NotEmpty(lva.Annotations) - lvaa := lva.Annotations[0] - assert.Equal(5, lvaa.XValue) - assert.Equal(1, lvaa.YValue) -} diff --git a/legend_test.go b/legend_test.go deleted file mode 100644 index 7f8fae8..0000000 --- a/legend_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package chart - -import ( - "bytes" - "testing" - - "github.com/blend/go-sdk/assert" -) - -func TestLegend(t *testing.T) { - assert := assert.New(t) - - graph := Chart{ - Series: []Series{ - ContinuousSeries{ - Name: "A test series", - XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, - YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, - }, - }, - } - - //note we have to do this as a separate step because we need a reference to graph - graph.Elements = []Renderable{ - Legend(&graph), - } - buf := bytes.NewBuffer([]byte{}) - err := graph.Render(PNG, buf) - assert.Nil(err) - assert.NotZero(buf.Len()) -} diff --git a/linear_regression_series_test.go b/linear_regression_series_test.go deleted file mode 100644 index 0841d98..0000000 --- a/linear_regression_series_test.go +++ /dev/null @@ -1,78 +0,0 @@ -package chart - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" - "git.gutmet.org/go-chart.git/seq" -) - -func TestLinearRegressionSeries(t *testing.T) { - assert := assert.New(t) - - mainSeries := ContinuousSeries{ - Name: "A test series", - XValues: seq.Range(1.0, 100.0), - YValues: seq.Range(1.0, 100.0), - } - - linRegSeries := &LinearRegressionSeries{ - InnerSeries: mainSeries, - } - - lrx0, lry0 := linRegSeries.GetValues(0) - assert.InDelta(1.0, lrx0, 0.0000001) - assert.InDelta(1.0, lry0, 0.0000001) - - lrxn, lryn := linRegSeries.GetLastValues() - assert.InDelta(100.0, lrxn, 0.0000001) - assert.InDelta(100.0, lryn, 0.0000001) -} - -func TestLinearRegressionSeriesDesc(t *testing.T) { - assert := assert.New(t) - - mainSeries := ContinuousSeries{ - Name: "A test series", - XValues: seq.Range(100.0, 1.0), - YValues: seq.Range(100.0, 1.0), - } - - linRegSeries := &LinearRegressionSeries{ - InnerSeries: mainSeries, - } - - lrx0, lry0 := linRegSeries.GetValues(0) - assert.InDelta(100.0, lrx0, 0.0000001) - assert.InDelta(100.0, lry0, 0.0000001) - - lrxn, lryn := linRegSeries.GetLastValues() - assert.InDelta(1.0, lrxn, 0.0000001) - assert.InDelta(1.0, lryn, 0.0000001) -} - -func TestLinearRegressionSeriesWindowAndOffset(t *testing.T) { - assert := assert.New(t) - - mainSeries := ContinuousSeries{ - Name: "A test series", - XValues: seq.Range(100.0, 1.0), - YValues: seq.Range(100.0, 1.0), - } - - linRegSeries := &LinearRegressionSeries{ - InnerSeries: mainSeries, - Offset: 10, - Limit: 10, - } - - assert.Equal(10, linRegSeries.Len()) - - lrx0, lry0 := linRegSeries.GetValues(0) - assert.InDelta(90.0, lrx0, 0.0000001) - assert.InDelta(90.0, lry0, 0.0000001) - - lrxn, lryn := linRegSeries.GetLastValues() - assert.InDelta(80.0, lrxn, 0.0000001) - assert.InDelta(80.0, lryn, 0.0000001) -} diff --git a/macd_series_test.go b/macd_series_test.go deleted file mode 100644 index fa7c7fd..0000000 --- a/macd_series_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package chart - -import ( - "fmt" - "testing" - - "github.com/blend/go-sdk/assert" -) - -var ( - macdExpected = []float64{ - 0, - 0.06381766382, - 0.1641441222, - 0.2817201894, - 0.4033023481, - 0.3924673744, - 0.2983093823, - 0.1561821464, - -0.008916708129, - -0.05210332292, - -0.01649503993, - 0.06667130899, - 0.1751344574, - 0.1657328378, - 0.08257097469, - -0.04265109369, - -0.1875741257, - -0.2091853882, - -0.1518975486, - -0.04781419838, - 0.08025242841, - 0.08881960494, - 0.02183529775, - -0.08904155476, - -0.2214141128, - -0.2321805992, - -0.1656331722, - -0.05373789678, - 0.08083727586, - 0.09475354363, - 0.03209767112, - -0.07534076818, - -0.2050442354, - -0.2138010557, - -0.1458045181, - -0.03293263556, - 0.1022243734, - 0.1163957964, - 0.05372761902, - -0.05393941791, - -0.1840438454, - -0.1933365048, - -0.1259788988, - -0.01382225715, - 0.1205656194, - 0.1339326478, - 0.07044017167, - -0.03805851969, - -0.1689918111, - -0.1791024416, - } -) - -func TestMACDSeries(t *testing.T) { - assert := assert.New(t) - - mockSeries := mockValuesProvider{ - emaXValues, - emaYValues, - } - assert.Equal(50, mockSeries.Len()) - - mas := &MACDSeries{ - InnerSeries: mockSeries, - } - - var yvalues []float64 - for x := 0; x < mas.Len(); x++ { - _, y := mas.GetValues(x) - yvalues = append(yvalues, y) - } - - assert.NotEmpty(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])) - } -} diff --git a/matrix/matrix_test.go b/matrix/matrix_test.go deleted file mode 100644 index eb14e33..0000000 --- a/matrix/matrix_test.go +++ /dev/null @@ -1,396 +0,0 @@ -package matrix - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" -) - -func TestNew(t *testing.T) { - assert := assert.New(t) - - m := New(10, 5) - rows, cols := m.Size() - assert.Equal(10, rows) - assert.Equal(5, cols) - assert.Zero(m.Get(0, 0)) - assert.Zero(m.Get(9, 4)) -} - -func TestNewWithValues(t *testing.T) { - assert := assert.New(t) - - m := New(5, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - rows, cols := m.Size() - assert.Equal(5, rows) - assert.Equal(2, cols) - assert.Equal(1, m.Get(0, 0)) - assert.Equal(10, m.Get(4, 1)) -} - -func TestIdentitiy(t *testing.T) { - assert := assert.New(t) - - id := Identity(5) - rows, cols := id.Size() - assert.Equal(5, rows) - assert.Equal(5, cols) - assert.Equal(1, id.Get(0, 0)) - assert.Equal(1, id.Get(1, 1)) - assert.Equal(1, id.Get(2, 2)) - assert.Equal(1, id.Get(3, 3)) - assert.Equal(1, id.Get(4, 4)) - assert.Equal(0, id.Get(0, 1)) - assert.Equal(0, id.Get(1, 0)) - assert.Equal(0, id.Get(4, 0)) - assert.Equal(0, id.Get(0, 4)) -} - -func TestNewFromArrays(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 2, 3, 4}, - {5, 6, 7, 8}, - }) - assert.NotNil(m) - - rows, cols := m.Size() - assert.Equal(2, rows) - assert.Equal(4, cols) -} - -func TestOnes(t *testing.T) { - assert := assert.New(t) - - ones := Ones(5, 10) - rows, cols := ones.Size() - assert.Equal(5, rows) - assert.Equal(10, cols) - - for row := 0; row < rows; row++ { - for col := 0; col < cols; col++ { - assert.Equal(1, ones.Get(row, col)) - } - } -} - -func TestMatrixEpsilon(t *testing.T) { - assert := assert.New(t) - - ones := Ones(2, 2) - ones = ones.WithEpsilon(0.001) - assert.Equal(0.001, ones.Epsilon()) -} - -func TestMatrixArrays(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - }) - - assert.NotNil(m) - - arrays := m.Arrays() - - assert.Equal(arrays, [][]float64{ - {1, 2, 3}, - {4, 5, 6}, - }) -} - -func TestMatrixIsSquare(t *testing.T) { - assert := assert.New(t) - - assert.False(NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - }).IsSquare()) - - assert.False(NewFromArrays([][]float64{ - {1, 2}, - {3, 4}, - {5, 6}, - }).IsSquare()) - - assert.True(NewFromArrays([][]float64{ - {1, 2}, - {3, 4}, - }).IsSquare()) -} - -func TestMatrixIsSymmetric(t *testing.T) { - assert := assert.New(t) - - assert.False(NewFromArrays([][]float64{ - {1, 2, 3}, - {2, 1, 2}, - }).IsSymmetric()) - - assert.False(NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9}, - }).IsSymmetric()) - - assert.True(NewFromArrays([][]float64{ - {1, 2, 3}, - {2, 1, 2}, - {3, 2, 1}, - }).IsSymmetric()) - -} - -func TestMatrixGet(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9}, - }) - - assert.Equal(1, m.Get(0, 0)) - assert.Equal(2, m.Get(0, 1)) - assert.Equal(3, m.Get(0, 2)) - assert.Equal(4, m.Get(1, 0)) - assert.Equal(5, m.Get(1, 1)) - assert.Equal(6, m.Get(1, 2)) - assert.Equal(7, m.Get(2, 0)) - assert.Equal(8, m.Get(2, 1)) - assert.Equal(9, m.Get(2, 2)) -} - -func TestMatrixSet(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9}, - }) - - m.Set(1, 1, 99) - assert.Equal(99, m.Get(1, 1)) -} - -func TestMatrixCol(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9}, - }) - - assert.Equal([]float64{1, 4, 7}, m.Col(0)) - assert.Equal([]float64{2, 5, 8}, m.Col(1)) - assert.Equal([]float64{3, 6, 9}, m.Col(2)) -} - -func TestMatrixRow(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9}, - }) - - assert.Equal([]float64{1, 2, 3}, m.Row(0)) - assert.Equal([]float64{4, 5, 6}, m.Row(1)) - assert.Equal([]float64{7, 8, 9}, m.Row(2)) -} - -func TestMatrixSwapRows(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9}, - }) - - m.SwapRows(0, 1) - - assert.Equal([]float64{4, 5, 6}, m.Row(0)) - assert.Equal([]float64{1, 2, 3}, m.Row(1)) - assert.Equal([]float64{7, 8, 9}, m.Row(2)) -} - -func TestMatrixCopy(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9}, - }) - - m2 := m.Copy() - assert.False(m == m2) - assert.True(m.Equals(m2)) -} - -func TestMatrixDiagonalVector(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 4, 7}, - {4, 2, 8}, - {7, 8, 3}, - }) - - diag := m.DiagonalVector() - assert.Equal([]float64{1, 2, 3}, diag) -} - -func TestMatrixDiagonalVectorLandscape(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 4, 7, 99}, - {4, 2, 8, 99}, - }) - - diag := m.DiagonalVector() - assert.Equal([]float64{1, 2}, diag) -} - -func TestMatrixDiagonalVectorPortrait(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 4}, - {4, 2}, - {99, 99}, - }) - - diag := m.DiagonalVector() - assert.Equal([]float64{1, 2}, diag) -} - -func TestMatrixDiagonal(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 4, 7}, - {4, 2, 8}, - {7, 8, 3}, - }) - - m2 := NewFromArrays([][]float64{ - {1, 0, 0}, - {0, 2, 0}, - {0, 0, 3}, - }) - - assert.True(m.Diagonal().Equals(m2)) -} - -func TestMatrixEquals(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 4, 7}, - {4, 2, 8}, - {7, 8, 3}, - }) - - assert.False(m.Equals(nil)) - var nilMatrix *Matrix - assert.True(nilMatrix.Equals(nil)) - assert.False(m.Equals(New(1, 1))) - assert.False(m.Equals(New(3, 3))) - assert.True(m.Equals(New(3, 3, 1, 4, 7, 4, 2, 8, 7, 8, 3))) -} - -func TestMatrixL(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9}, - }) - - l := m.L() - assert.True(l.Equals(New(3, 3, 1, 2, 3, 0, 5, 6, 0, 0, 9))) -} - -func TestMatrixU(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9}, - }) - - u := m.U() - assert.True(u.Equals(New(3, 3, 0, 0, 0, 4, 0, 0, 7, 8, 0))) -} - -func TestMatrixString(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9}, - }) - - assert.Equal("1 2 3 \n4 5 6 \n7 8 9 \n", m.String()) -} - -func TestMatrixLU(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 3, 5}, - {2, 4, 7}, - {1, 1, 0}, - }) - - l, u, p := m.LU() - assert.NotNil(l) - assert.NotNil(u) - assert.NotNil(p) -} - -func TestMatrixQR(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {12, -51, 4}, - {6, 167, -68}, - {-4, 24, -41}, - }) - - q, r := m.QR() - assert.NotNil(q) - assert.NotNil(r) -} - -func TestMatrixTranspose(t *testing.T) { - assert := assert.New(t) - - m := NewFromArrays([][]float64{ - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9}, - {10, 11, 12}, - }) - - m2 := m.Transpose() - - rows, cols := m2.Size() - assert.Equal(3, rows) - assert.Equal(4, cols) - - assert.Equal(1, m2.Get(0, 0)) - assert.Equal(10, m2.Get(0, 3)) - assert.Equal(3, m2.Get(2, 0)) -} diff --git a/matrix/regression_test.go b/matrix/regression_test.go deleted file mode 100644 index 5bd282b..0000000 --- a/matrix/regression_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package matrix - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" -) - -func TestPoly(t *testing.T) { - assert := assert.New(t) - var xGiven = []float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - var yGiven = []float64{1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321} - var degree = 2 - - c, err := Poly(xGiven, yGiven, degree) - assert.Nil(err) - assert.Len(c, 3) - - assert.InDelta(c[0], 0.999999999, DefaultEpsilon) - assert.InDelta(c[1], 2, DefaultEpsilon) - assert.InDelta(c[2], 3, DefaultEpsilon) -} diff --git a/pie_chart_test.go b/pie_chart_test.go deleted file mode 100644 index 960941e..0000000 --- a/pie_chart_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package chart - -import ( - "bytes" - "testing" - - assert "github.com/blend/go-sdk/assert" -) - -func TestPieChart(t *testing.T) { - assert := assert.New(t) - - pie := PieChart{ - Canvas: Style{ - FillColor: ColorLightGray, - }, - Values: []Value{ - {Value: 10, Label: "Blue"}, - {Value: 9, Label: "Green"}, - {Value: 8, Label: "Gray"}, - {Value: 7, Label: "Orange"}, - {Value: 6, Label: "HEANG"}, - {Value: 5, Label: "??"}, - {Value: 2, Label: "!!"}, - }, - } - - b := bytes.NewBuffer([]byte{}) - pie.Render(PNG, b) - assert.NotZero(b.Len()) -} - -func TestPieChartDropsZeroValues(t *testing.T) { - assert := assert.New(t) - - pie := PieChart{ - Canvas: Style{ - FillColor: ColorLightGray, - }, - Values: []Value{ - {Value: 5, Label: "Blue"}, - {Value: 5, Label: "Green"}, - {Value: 0, Label: "Gray"}, - }, - } - - b := bytes.NewBuffer([]byte{}) - err := pie.Render(PNG, b) - assert.Nil(err) -} - -func TestPieChartAllZeroValues(t *testing.T) { - assert := assert.New(t) - - pie := PieChart{ - Canvas: Style{ - FillColor: ColorLightGray, - }, - Values: []Value{ - {Value: 0, Label: "Blue"}, - {Value: 0, Label: "Green"}, - {Value: 0, Label: "Gray"}, - }, - } - - b := bytes.NewBuffer([]byte{}) - err := pie.Render(PNG, b) - assert.NotNil(err) -} diff --git a/polynomial_regression_test.go b/polynomial_regression_test.go deleted file mode 100644 index fbd3436..0000000 --- a/polynomial_regression_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package chart - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" - "git.gutmet.org/go-chart.git/matrix" -) - -func TestPolynomialRegression(t *testing.T) { - assert := assert.New(t) - - var xv []float64 - var yv []float64 - - for i := 0; i < 100; i++ { - xv = append(xv, float64(i)) - yv = append(yv, float64(i*i)) - } - - values := ContinuousSeries{ - XValues: xv, - YValues: yv, - } - - poly := &PolynomialRegressionSeries{ - InnerSeries: values, - Degree: 2, - } - - for i := 0; i < 100; i++ { - _, y := poly.GetValues(i) - assert.InDelta(float64(i*i), y, matrix.DefaultEpsilon) - } -} diff --git a/seq/buffer_test.go b/seq/buffer_test.go deleted file mode 100644 index fb177d2..0000000 --- a/seq/buffer_test.go +++ /dev/null @@ -1,192 +0,0 @@ -package seq - -import ( - "testing" - - "github.com/blend/go-sdk/assert" -) - -func TestBuffer(t *testing.T) { - assert := assert.New(t) - - buffer := NewBuffer() - - buffer.Enqueue(1) - assert.Equal(1, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(1, buffer.PeekBack()) - - buffer.Enqueue(2) - assert.Equal(2, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(2, buffer.PeekBack()) - - buffer.Enqueue(3) - assert.Equal(3, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(3, buffer.PeekBack()) - - buffer.Enqueue(4) - assert.Equal(4, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(4, buffer.PeekBack()) - - buffer.Enqueue(5) - assert.Equal(5, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(5, buffer.PeekBack()) - - buffer.Enqueue(6) - assert.Equal(6, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(6, buffer.PeekBack()) - - buffer.Enqueue(7) - assert.Equal(7, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(7, buffer.PeekBack()) - - buffer.Enqueue(8) - assert.Equal(8, buffer.Len()) - assert.Equal(1, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) - - value := buffer.Dequeue() - assert.Equal(1, value) - assert.Equal(7, buffer.Len()) - assert.Equal(2, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) - - value = buffer.Dequeue() - assert.Equal(2, value) - assert.Equal(6, buffer.Len()) - assert.Equal(3, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) - - value = buffer.Dequeue() - assert.Equal(3, value) - assert.Equal(5, buffer.Len()) - assert.Equal(4, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) - - value = buffer.Dequeue() - assert.Equal(4, value) - assert.Equal(4, buffer.Len()) - assert.Equal(5, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) - - value = buffer.Dequeue() - assert.Equal(5, value) - assert.Equal(3, buffer.Len()) - assert.Equal(6, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) - - value = buffer.Dequeue() - assert.Equal(6, value) - assert.Equal(2, buffer.Len()) - assert.Equal(7, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) - - value = buffer.Dequeue() - assert.Equal(7, value) - assert.Equal(1, buffer.Len()) - assert.Equal(8, buffer.Peek()) - assert.Equal(8, buffer.PeekBack()) - - value = buffer.Dequeue() - assert.Equal(8, value) - assert.Equal(0, buffer.Len()) - assert.Zero(buffer.Peek()) - assert.Zero(buffer.PeekBack()) -} - -func TestBufferClear(t *testing.T) { - assert := assert.New(t) - - buffer := NewBuffer() - buffer.Enqueue(1) - buffer.Enqueue(1) - buffer.Enqueue(1) - buffer.Enqueue(1) - buffer.Enqueue(1) - buffer.Enqueue(1) - buffer.Enqueue(1) - buffer.Enqueue(1) - - assert.Equal(8, buffer.Len()) - - buffer.Clear() - assert.Equal(0, buffer.Len()) - assert.Zero(buffer.Peek()) - assert.Zero(buffer.PeekBack()) -} - -func TestBufferArray(t *testing.T) { - assert := assert.New(t) - - buffer := NewBuffer() - buffer.Enqueue(1) - buffer.Enqueue(2) - buffer.Enqueue(3) - buffer.Enqueue(4) - buffer.Enqueue(5) - - contents := buffer.Array() - assert.Len(contents, 5) - assert.Equal(1, contents[0]) - assert.Equal(2, contents[1]) - assert.Equal(3, contents[2]) - assert.Equal(4, contents[3]) - assert.Equal(5, contents[4]) -} - -func TestBufferEach(t *testing.T) { - assert := assert.New(t) - - buffer := NewBuffer() - - for x := 1; x < 17; x++ { - buffer.Enqueue(float64(x)) - } - - called := 0 - buffer.Each(func(_ int, v float64) { - if v == float64(called+1) { - called++ - } - }) - - assert.Equal(16, called) -} - -func TestNewBuffer(t *testing.T) { - assert := assert.New(t) - - empty := NewBuffer() - assert.NotNil(empty) - assert.Zero(empty.Len()) - assert.Equal(bufferDefaultCapacity, empty.Capacity()) - assert.Zero(empty.Peek()) - assert.Zero(empty.PeekBack()) -} - -func TestNewBufferWithValues(t *testing.T) { - assert := assert.New(t) - - values := NewBuffer(1, 2, 3, 4, 5) - assert.NotNil(values) - assert.Equal(5, values.Len()) - assert.Equal(1, values.Peek()) - assert.Equal(5, values.PeekBack()) -} - -func TestBufferGrowth(t *testing.T) { - assert := assert.New(t) - - values := NewBuffer(1, 2, 3, 4, 5) - for i := 0; i < 1<<10; i++ { - values.Enqueue(float64(i)) - } - - assert.Equal(1<<10-1, values.PeekBack()) -} diff --git a/seq/linear_test.go b/seq/linear_test.go deleted file mode 100644 index f90b179..0000000 --- a/seq/linear_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package seq - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" -) - -func TestRange(t *testing.T) { - assert := assert.New(t) - - values := Range(1, 100) - assert.Len(values, 100) - assert.Equal(1, values[0]) - assert.Equal(100, values[99]) -} - -func TestRangeWithStep(t *testing.T) { - assert := assert.New(t) - - values := RangeWithStep(0, 100, 5) - assert.Equal(100, values[20]) - assert.Len(values, 21) -} - -func TestRangeReversed(t *testing.T) { - assert := assert.New(t) - - values := Range(10.0, 1.0) - assert.Equal(10, len(values)) - assert.Equal(10.0, values[0]) - assert.Equal(1.0, values[9]) -} - -func TestValuesRegression(t *testing.T) { - assert := assert.New(t) - - // note; this assumes a 1.0 step is implicitly set in the constructor. - linearProvider := NewLinear().WithStart(1.0).WithEnd(100.0) - assert.Equal(1, linearProvider.Start()) - assert.Equal(100, linearProvider.End()) - assert.Equal(100, linearProvider.Len()) - - values := Seq{Provider: linearProvider}.Array() - assert.Len(values, 100) - assert.Equal(1.0, values[0]) - assert.Equal(100, values[99]) -} diff --git a/seq/random_test.go b/seq/random_test.go deleted file mode 100644 index 8fd8602..0000000 --- a/seq/random_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package seq - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" -) - -func TestRandomRegression(t *testing.T) { - assert := assert.New(t) - - randomProvider := NewRandom().WithLen(4096).WithMax(256) - assert.Equal(4096, randomProvider.Len()) - assert.Equal(256, *randomProvider.Max()) - - randomSequence := New(randomProvider) - randomValues := randomSequence.Array() - assert.Len(randomValues, 4096) - assert.InDelta(128, randomSequence.Average(), 10.0) -} diff --git a/seq/seq_test.go b/seq/seq_test.go deleted file mode 100644 index a1b8dd6..0000000 --- a/seq/seq_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package seq - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" -) - -func TestSequenceEach(t *testing.T) { - assert := assert.New(t) - - values := Seq{NewArray(1, 2, 3, 4)} - values.Each(func(i int, v float64) { - assert.Equal(i, v-1) - }) -} - -func TestSequenceMap(t *testing.T) { - assert := assert.New(t) - - values := Seq{NewArray(1, 2, 3, 4)} - mapped := values.Map(func(i int, v float64) float64 { - assert.Equal(i, v-1) - return v * 2 - }) - assert.Equal(4, mapped.Len()) -} - -func TestSequenceFoldLeft(t *testing.T) { - assert := assert.New(t) - - values := Seq{NewArray(1, 2, 3, 4)} - ten := values.FoldLeft(func(_ int, vp, v float64) float64 { - return vp + v - }) - assert.Equal(10, ten) - - orderTest := Seq{NewArray(10, 3, 2, 1)} - four := orderTest.FoldLeft(func(_ int, vp, v float64) float64 { - return vp - v - }) - assert.Equal(4, four) -} - -func TestSequenceFoldRight(t *testing.T) { - assert := assert.New(t) - - values := Seq{NewArray(1, 2, 3, 4)} - ten := values.FoldRight(func(_ int, vp, v float64) float64 { - return vp + v - }) - assert.Equal(10, ten) - - orderTest := Seq{NewArray(10, 3, 2, 1)} - notFour := orderTest.FoldRight(func(_ int, vp, v float64) float64 { - return vp - v - }) - assert.Equal(-14, notFour) -} - -func TestSequenceSum(t *testing.T) { - assert := assert.New(t) - - values := Seq{NewArray(1, 2, 3, 4)} - assert.Equal(10, values.Sum()) -} - -func TestSequenceAverage(t *testing.T) { - assert := assert.New(t) - - values := Seq{NewArray(1, 2, 3, 4)} - assert.Equal(2.5, values.Average()) - - valuesOdd := Seq{NewArray(1, 2, 3, 4, 5)} - assert.Equal(3, valuesOdd.Average()) -} - -func TestSequenceVariance(t *testing.T) { - assert := assert.New(t) - - values := Seq{NewArray(1, 2, 3, 4, 5)} - assert.Equal(2, values.Variance()) -} - -func TestSequenceNormalize(t *testing.T) { - assert := assert.New(t) - - normalized := Values(1, 2, 3, 4, 5).Normalize().Array() - - assert.NotEmpty(normalized) - assert.Len(normalized, 5) - assert.Equal(0, normalized[0]) - assert.Equal(0.25, normalized[1]) - assert.Equal(1, normalized[4]) -} diff --git a/seq/time_test.go b/seq/time_test.go deleted file mode 100644 index 089853a..0000000 --- a/seq/time_test.go +++ /dev/null @@ -1,85 +0,0 @@ -package seq - -import ( - "testing" - "time" - - assert "github.com/blend/go-sdk/assert" - "git.gutmet.org/go-chart.git/util" -) - -func TestTimeHours(t *testing.T) { - assert := assert.New(t) - - today := time.Date(2016, 07, 01, 12, 0, 0, 0, time.UTC) - seq := Time.Hours(today, 24) - - end := util.Time.End(seq...) - assert.Len(seq, 24) - assert.Equal(2016, end.Year()) - assert.Equal(07, int(end.Month())) - assert.Equal(02, end.Day()) - assert.Equal(11, end.Hour()) -} - -func TestSequenceHoursFill(t *testing.T) { - assert := assert.New(t) - - xdata := []time.Time{ - time.Date(2016, 07, 01, 12, 0, 0, 0, time.UTC), - time.Date(2016, 07, 01, 13, 0, 0, 0, time.UTC), - time.Date(2016, 07, 01, 14, 0, 0, 0, time.UTC), - time.Date(2016, 07, 02, 4, 0, 0, 0, time.UTC), - time.Date(2016, 07, 02, 5, 0, 0, 0, time.UTC), - time.Date(2016, 07, 03, 12, 0, 0, 0, time.UTC), - time.Date(2016, 07, 03, 14, 0, 0, 0, time.UTC), - } - - ydata := []float64{ - 1.1, - 1.2, - 1.4, - 0.8, - 2.1, - 0.4, - 0.6, - } - - filledTimes, filledValues := Time.HoursFilled(xdata, ydata) - expected := util.Time.DiffHours(util.Time.Start(xdata...), util.Time.End(xdata...)) + 1 - assert.Len(filledTimes, expected) - assert.Equal(len(filledValues), len(filledTimes)) - - assert.NotZero(filledValues[0]) - assert.NotZero(filledValues[len(filledValues)-1]) - - assert.NotZero(filledValues[16]) -} - -func TestTimeStart(t *testing.T) { - assert := assert.New(t) - - times := []time.Time{ - time.Now().AddDate(0, 0, -4), - time.Now().AddDate(0, 0, -2), - time.Now().AddDate(0, 0, -1), - time.Now().AddDate(0, 0, -3), - time.Now().AddDate(0, 0, -5), - } - - assert.InTimeDelta(util.Time.Start(times...), times[4], time.Millisecond) -} - -func TestTimeEnd(t *testing.T) { - assert := assert.New(t) - - times := []time.Time{ - time.Now().AddDate(0, 0, -4), - time.Now().AddDate(0, 0, -2), - time.Now().AddDate(0, 0, -1), - time.Now().AddDate(0, 0, -3), - time.Now().AddDate(0, 0, -5), - } - - assert.InTimeDelta(util.Time.End(times...), times[2], time.Millisecond) -} diff --git a/sma_series_test.go b/sma_series_test.go deleted file mode 100644 index 0ee2290..0000000 --- a/sma_series_test.go +++ /dev/null @@ -1,113 +0,0 @@ -package chart - -import ( - "testing" - - "github.com/blend/go-sdk/assert" - "git.gutmet.org/go-chart.git/seq" - "git.gutmet.org/go-chart.git/util" -) - -type mockValuesProvider struct { - X []float64 - Y []float64 -} - -func (m mockValuesProvider) Len() int { - return util.Math.MinInt(len(m.X), len(m.Y)) -} - -func (m mockValuesProvider) GetValues(index int) (x, y float64) { - if index < 0 { - panic("negative index at GetValue()") - } - if index >= util.Math.MinInt(len(m.X), len(m.Y)) { - panic("index is outside the length of m.X or m.Y") - } - x = m.X[index] - y = m.Y[index] - return -} - -func TestSMASeriesGetValue(t *testing.T) { - assert := assert.New(t) - - mockSeries := mockValuesProvider{ - seq.Range(1.0, 10.0), - seq.Range(10, 1.0), - } - assert.Equal(10, mockSeries.Len()) - - mas := &SMASeries{ - InnerSeries: mockSeries, - Period: 10, - } - - var yvalues []float64 - for x := 0; x < mas.Len(); x++ { - _, y := mas.GetValues(x) - yvalues = append(yvalues, y) - } - - assert.Equal(10.0, yvalues[0]) - assert.Equal(9.5, yvalues[1]) - assert.Equal(9.0, yvalues[2]) - assert.Equal(8.5, yvalues[3]) - assert.Equal(8.0, yvalues[4]) - assert.Equal(7.5, yvalues[5]) - assert.Equal(7.0, yvalues[6]) - assert.Equal(6.5, yvalues[7]) - assert.Equal(6.0, yvalues[8]) -} - -func TestSMASeriesGetLastValueWindowOverlap(t *testing.T) { - assert := assert.New(t) - - mockSeries := mockValuesProvider{ - seq.Range(1.0, 10.0), - seq.Range(10, 1.0), - } - assert.Equal(10, mockSeries.Len()) - - mas := &SMASeries{ - InnerSeries: mockSeries, - Period: 15, - } - - var yvalues []float64 - for x := 0; x < mas.Len(); x++ { - _, y := mas.GetValues(x) - yvalues = append(yvalues, y) - } - - lx, ly := mas.GetLastValues() - assert.Equal(10.0, lx) - assert.Equal(5.5, ly) - assert.Equal(yvalues[len(yvalues)-1], ly) -} - -func TestSMASeriesGetLastValue(t *testing.T) { - assert := assert.New(t) - - mockSeries := mockValuesProvider{ - seq.Range(1.0, 100.0), - seq.Range(100, 1.0), - } - assert.Equal(100, mockSeries.Len()) - - mas := &SMASeries{ - InnerSeries: mockSeries, - Period: 10, - } - - var yvalues []float64 - for x := 0; x < mas.Len(); x++ { - _, y := mas.GetValues(x) - yvalues = append(yvalues, y) - } - - lx, ly := mas.GetLastValues() - assert.Equal(100.0, lx) - assert.Equal(6, ly) - assert.Equal(yvalues[len(yvalues)-1], ly) -} diff --git a/style_test.go b/style_test.go deleted file mode 100644 index 5abb0a5..0000000 --- a/style_test.go +++ /dev/null @@ -1,214 +0,0 @@ -package chart - -import ( - "testing" - - "github.com/blend/go-sdk/assert" - "git.gutmet.org/golang-freetype.git/truetype" - "git.gutmet.org/go-chart.git/drawing" -) - -func TestStyleIsZero(t *testing.T) { - assert := assert.New(t) - zero := Style{} - assert.True(zero.IsZero()) - - strokeColor := Style{StrokeColor: drawing.ColorWhite} - assert.False(strokeColor.IsZero()) - - fillColor := Style{FillColor: drawing.ColorWhite} - assert.False(fillColor.IsZero()) - - strokeWidth := Style{StrokeWidth: 5.0} - assert.False(strokeWidth.IsZero()) - - fontSize := Style{FontSize: 12.0} - assert.False(fontSize.IsZero()) - - fontColor := Style{FontColor: drawing.ColorWhite} - assert.False(fontColor.IsZero()) - - font := Style{Font: &truetype.Font{}} - assert.False(font.IsZero()) -} - -func TestStyleGetStrokeColor(t *testing.T) { - assert := assert.New(t) - - unset := Style{} - assert.Equal(drawing.ColorTransparent, unset.GetStrokeColor()) - assert.Equal(drawing.ColorWhite, unset.GetStrokeColor(drawing.ColorWhite)) - - set := Style{StrokeColor: drawing.ColorWhite} - assert.Equal(drawing.ColorWhite, set.GetStrokeColor()) - assert.Equal(drawing.ColorWhite, set.GetStrokeColor(drawing.ColorBlack)) -} - -func TestStyleGetFillColor(t *testing.T) { - assert := assert.New(t) - - unset := Style{} - assert.Equal(drawing.ColorTransparent, unset.GetFillColor()) - assert.Equal(drawing.ColorWhite, unset.GetFillColor(drawing.ColorWhite)) - - set := Style{FillColor: drawing.ColorWhite} - assert.Equal(drawing.ColorWhite, set.GetFillColor()) - assert.Equal(drawing.ColorWhite, set.GetFillColor(drawing.ColorBlack)) -} - -func TestStyleGetStrokeWidth(t *testing.T) { - assert := assert.New(t) - - unset := Style{} - assert.Equal(DefaultStrokeWidth, unset.GetStrokeWidth()) - assert.Equal(DefaultStrokeWidth+1, unset.GetStrokeWidth(DefaultStrokeWidth+1)) - - set := Style{StrokeWidth: DefaultStrokeWidth + 2} - assert.Equal(DefaultStrokeWidth+2, set.GetStrokeWidth()) - assert.Equal(DefaultStrokeWidth+2, set.GetStrokeWidth(DefaultStrokeWidth+1)) -} - -func TestStyleGetFontSize(t *testing.T) { - assert := assert.New(t) - - unset := Style{} - assert.Equal(DefaultFontSize, unset.GetFontSize()) - assert.Equal(DefaultFontSize+1, unset.GetFontSize(DefaultFontSize+1)) - - set := Style{FontSize: DefaultFontSize + 2} - assert.Equal(DefaultFontSize+2, set.GetFontSize()) - assert.Equal(DefaultFontSize+2, set.GetFontSize(DefaultFontSize+1)) -} - -func TestStyleGetFontColor(t *testing.T) { - assert := assert.New(t) - - unset := Style{} - assert.Equal(drawing.ColorTransparent, unset.GetFontColor()) - assert.Equal(drawing.ColorWhite, unset.GetFontColor(drawing.ColorWhite)) - - set := Style{FontColor: drawing.ColorWhite} - assert.Equal(drawing.ColorWhite, set.GetFontColor()) - assert.Equal(drawing.ColorWhite, set.GetFontColor(drawing.ColorBlack)) -} - -func TestStyleGetFont(t *testing.T) { - assert := assert.New(t) - - f, err := GetDefaultFont() - assert.Nil(err) - - unset := Style{} - assert.Nil(unset.GetFont()) - assert.Equal(f, unset.GetFont(f)) - - set := Style{Font: f} - assert.NotNil(set.GetFont()) -} - -func TestStyleGetPadding(t *testing.T) { - assert := assert.New(t) - - unset := Style{} - assert.True(unset.GetPadding().IsZero()) - assert.False(unset.GetPadding(DefaultBackgroundPadding).IsZero()) - assert.Equal(DefaultBackgroundPadding, unset.GetPadding(DefaultBackgroundPadding)) - - set := Style{Padding: DefaultBackgroundPadding} - assert.False(set.GetPadding().IsZero()) - assert.Equal(DefaultBackgroundPadding, set.GetPadding()) - assert.Equal(DefaultBackgroundPadding, set.GetPadding(Box{ - Top: DefaultBackgroundPadding.Top + 1, - Left: DefaultBackgroundPadding.Left + 1, - Right: DefaultBackgroundPadding.Right + 1, - Bottom: DefaultBackgroundPadding.Bottom + 1, - })) -} - -func TestStyleWithDefaultsFrom(t *testing.T) { - assert := assert.New(t) - - f, err := GetDefaultFont() - assert.Nil(err) - - unset := Style{} - set := Style{ - StrokeColor: drawing.ColorWhite, - StrokeWidth: 5.0, - FillColor: drawing.ColorWhite, - FontColor: drawing.ColorWhite, - Font: f, - Padding: DefaultBackgroundPadding, - } - - coalesced := unset.InheritFrom(set) - assert.Equal(set, coalesced) -} - -func TestStyleGetStrokeOptions(t *testing.T) { - assert := assert.New(t) - - set := Style{ - StrokeColor: drawing.ColorWhite, - StrokeWidth: 5.0, - FillColor: drawing.ColorWhite, - FontColor: drawing.ColorWhite, - Padding: DefaultBackgroundPadding, - } - svgStroke := set.GetStrokeOptions() - assert.False(svgStroke.StrokeColor.IsZero()) - assert.NotZero(svgStroke.StrokeWidth) - assert.True(svgStroke.FillColor.IsZero()) - assert.True(svgStroke.FontColor.IsZero()) -} - -func TestStyleGetFillOptions(t *testing.T) { - assert := assert.New(t) - - set := Style{ - StrokeColor: drawing.ColorWhite, - StrokeWidth: 5.0, - FillColor: drawing.ColorWhite, - FontColor: drawing.ColorWhite, - Padding: DefaultBackgroundPadding, - } - svgFill := set.GetFillOptions() - assert.False(svgFill.FillColor.IsZero()) - assert.Zero(svgFill.StrokeWidth) - assert.True(svgFill.StrokeColor.IsZero()) - assert.True(svgFill.FontColor.IsZero()) -} - -func TestStyleGetFillAndStrokeOptions(t *testing.T) { - assert := assert.New(t) - - set := Style{ - StrokeColor: drawing.ColorWhite, - StrokeWidth: 5.0, - FillColor: drawing.ColorWhite, - FontColor: drawing.ColorWhite, - Padding: DefaultBackgroundPadding, - } - svgFillAndStroke := set.GetFillAndStrokeOptions() - assert.False(svgFillAndStroke.FillColor.IsZero()) - assert.NotZero(svgFillAndStroke.StrokeWidth) - assert.False(svgFillAndStroke.StrokeColor.IsZero()) - assert.True(svgFillAndStroke.FontColor.IsZero()) -} - -func TestStyleGetTextOptions(t *testing.T) { - assert := assert.New(t) - - set := Style{ - StrokeColor: drawing.ColorWhite, - StrokeWidth: 5.0, - FillColor: drawing.ColorWhite, - FontColor: drawing.ColorWhite, - Padding: DefaultBackgroundPadding, - } - svgStroke := set.GetTextOptions() - assert.True(svgStroke.StrokeColor.IsZero()) - assert.Zero(svgStroke.StrokeWidth) - assert.True(svgStroke.FillColor.IsZero()) - assert.False(svgStroke.FontColor.IsZero()) -} diff --git a/text_test.go b/text_test.go deleted file mode 100644 index 41034c4..0000000 --- a/text_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package chart - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" -) - -func TestTextWrapWord(t *testing.T) { - assert := assert.New(t) - - r, err := PNG(1024, 1024) - assert.Nil(err) - f, err := GetDefaultFont() - assert.Nil(err) - - basicTextStyle := Style{Font: f, FontSize: 24} - - output := Text.WrapFitWord(r, "this is a test string", 100, basicTextStyle) - assert.NotEmpty(output) - assert.Len(output, 3) - - for _, line := range output { - basicTextStyle.WriteToRenderer(r) - lineBox := r.MeasureText(line) - assert.True(lineBox.Width() < 100, line+": "+lineBox.String()) - } - assert.Equal("this is", output[0]) - assert.Equal("a test", output[1]) - assert.Equal("string", output[2]) - - output = Text.WrapFitWord(r, "foo", 100, basicTextStyle) - assert.Len(output, 1) - assert.Equal("foo", output[0]) - - // test that it handles newlines. - output = Text.WrapFitWord(r, "this\nis\na\ntest\nstring", 100, basicTextStyle) - assert.Len(output, 5) - - // test that it handles newlines and long lines. - output = Text.WrapFitWord(r, "this\nis\na\ntest\nstring that is very long", 100, basicTextStyle) - assert.Len(output, 8) -} - -func TestTextWrapRune(t *testing.T) { - assert := assert.New(t) - - r, err := PNG(1024, 1024) - assert.Nil(err) - f, err := GetDefaultFont() - assert.Nil(err) - - basicTextStyle := Style{Font: f, FontSize: 24} - - output := Text.WrapFitRune(r, "this is a test string", 150, basicTextStyle) - assert.NotEmpty(output) - assert.Len(output, 2) - assert.Equal("this is a t", output[0]) - assert.Equal("est string", output[1]) -} diff --git a/tick_test.go b/tick_test.go deleted file mode 100644 index 9802150..0000000 --- a/tick_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package chart - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" -) - -func TestGenerateContinuousTicks(t *testing.T) { - assert := assert.New(t) - - f, err := GetDefaultFont() - assert.Nil(err) - - r, err := PNG(1024, 1024) - assert.Nil(err) - r.SetFont(f) - - ra := &ContinuousRange{ - Min: 0.0, - Max: 10.0, - Domain: 256, - } - - vf := FloatValueFormatter - - ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf) - assert.NotEmpty(ticks) - assert.Len(ticks, 11) - assert.Equal(0.0, ticks[0].Value) - assert.Equal(10, ticks[len(ticks)-1].Value) -} - -func TestGenerateContinuousTicksDescending(t *testing.T) { - assert := assert.New(t) - - f, err := GetDefaultFont() - assert.Nil(err) - - r, err := PNG(1024, 1024) - assert.Nil(err) - r.SetFont(f) - - ra := &ContinuousRange{ - Min: 0.0, - Max: 10.0, - Domain: 256, - Descending: true, - } - - vf := FloatValueFormatter - - ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf) - assert.NotEmpty(ticks) - assert.Len(ticks, 11) - assert.Equal(10.0, ticks[0].Value) - assert.Equal(9.0, ticks[1].Value) - assert.Equal(1.0, ticks[len(ticks)-2].Value) - assert.Equal(0.0, ticks[len(ticks)-1].Value) -} diff --git a/time_series_test.go b/time_series_test.go deleted file mode 100644 index 55cec72..0000000 --- a/time_series_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package chart - -import ( - "testing" - "time" - - "github.com/blend/go-sdk/assert" -) - -func TestTimeSeriesGetValue(t *testing.T) { - assert := assert.New(t) - - ts := TimeSeries{ - Name: "Test", - XValues: []time.Time{ - time.Now().AddDate(0, 0, -5), - time.Now().AddDate(0, 0, -4), - time.Now().AddDate(0, 0, -3), - time.Now().AddDate(0, 0, -2), - time.Now().AddDate(0, 0, -1), - }, - YValues: []float64{ - 1.0, 2.0, 3.0, 4.0, 5.0, - }, - } - - x0, y0 := ts.GetValues(0) - assert.NotZero(x0) - assert.Equal(1.0, y0) -} - -func TestTimeSeriesValidate(t *testing.T) { - assert := assert.New(t) - - cs := TimeSeries{ - Name: "Test Series", - XValues: []time.Time{ - time.Now().AddDate(0, 0, -5), - time.Now().AddDate(0, 0, -4), - time.Now().AddDate(0, 0, -3), - time.Now().AddDate(0, 0, -2), - time.Now().AddDate(0, 0, -1), - }, - YValues: []float64{ - 1.0, 2.0, 3.0, 4.0, 5.0, - }, - } - assert.Nil(cs.Validate()) - - cs = TimeSeries{ - Name: "Test Series", - XValues: []time.Time{ - time.Now().AddDate(0, 0, -5), - time.Now().AddDate(0, 0, -4), - time.Now().AddDate(0, 0, -3), - time.Now().AddDate(0, 0, -2), - time.Now().AddDate(0, 0, -1), - }, - } - assert.NotNil(cs.Validate()) - - cs = TimeSeries{ - Name: "Test Series", - YValues: []float64{ - 1.0, 2.0, 3.0, 4.0, 5.0, - }, - } - assert.NotNil(cs.Validate()) -} diff --git a/util/date_test.go b/util/date_test.go deleted file mode 100644 index e4deee6..0000000 --- a/util/date_test.go +++ /dev/null @@ -1,148 +0,0 @@ -package util - -import ( - "testing" - "time" - - assert "github.com/blend/go-sdk/assert" -) - -func parse(v string) time.Time { - ts, _ := time.Parse("2006-01-02", v) - return ts -} - -func TestDateEastern(t *testing.T) { - assert := assert.New(t) - eastern, err := Date.Eastern() - assert.Nil(err) - assert.NotNil(eastern) -} - -func TestDateTime(t *testing.T) { - assert := assert.New(t) - - ts := Date.Time(5, 6, 7, 8, time.UTC) - assert.Equal(05, ts.Hour()) - assert.Equal(06, ts.Minute()) - assert.Equal(07, ts.Second()) - assert.Equal(8, ts.Nanosecond()) - assert.Equal(time.UTC, ts.Location()) -} - -func TestDateDate(t *testing.T) { - assert := assert.New(t) - - ts := Date.Date(2015, 5, 6, time.UTC) - assert.Equal(2015, ts.Year()) - assert.Equal(5, ts.Month()) - assert.Equal(6, ts.Day()) - assert.Equal(time.UTC, ts.Location()) -} - -func TestDateOnDate(t *testing.T) { - assert := assert.New(t) - - eastern := Date.MustEastern() - assert.NotNil(eastern) - - ts := Date.OnDate(Date.Time(5, 4, 3, 2, time.UTC), Date.Date(2016, 6, 7, eastern)) - assert.Equal(2016, ts.Year()) - assert.Equal(6, ts.Month()) - assert.Equal(7, ts.Day()) - assert.Equal(5, ts.Hour()) - assert.Equal(4, ts.Minute()) - assert.Equal(3, ts.Second()) - assert.Equal(2, ts.Nanosecond()) - assert.Equal(time.UTC, ts.Location()) -} - -func TestDateNoonOnDate(t *testing.T) { - assert := assert.New(t) - noon := Date.NoonOnDate(time.Date(2016, 04, 03, 02, 01, 0, 0, time.UTC)) - - assert.Equal(2016, noon.Year()) - assert.Equal(4, noon.Month()) - assert.Equal(3, noon.Day()) - assert.Equal(12, noon.Hour()) - assert.Equal(0, noon.Minute()) - assert.Equal(time.UTC, noon.Location()) -} - -func TestDateBefore(t *testing.T) { - assert := assert.New(t) - - assert.True(Date.Before(parse("2015-07-02"), parse("2016-07-01"))) - assert.True(Date.Before(parse("2016-06-01"), parse("2016-07-01"))) - assert.True(Date.Before(parse("2016-07-01"), parse("2016-07-02"))) - - assert.False(Date.Before(parse("2016-07-01"), parse("2016-07-01"))) - assert.False(Date.Before(parse("2016-07-03"), parse("2016-07-01"))) - assert.False(Date.Before(parse("2016-08-03"), parse("2016-07-01"))) - assert.False(Date.Before(parse("2017-08-03"), parse("2016-07-01"))) -} - -func TestDateBeforeHandlesTimezones(t *testing.T) { - assert := assert.New(t) - - tuesdayUTC := time.Date(2016, 8, 02, 22, 00, 0, 0, time.UTC) - mondayUTC := time.Date(2016, 8, 01, 1, 00, 0, 0, time.UTC) - sundayEST := time.Date(2016, 7, 31, 22, 00, 0, 0, Date.MustEastern()) - - assert.True(Date.Before(sundayEST, tuesdayUTC)) - assert.False(Date.Before(sundayEST, mondayUTC)) -} - -func TestDateNextHour(t *testing.T) { - assert := assert.New(t) - - start := time.Date(2015, 07, 01, 9, 30, 0, 0, Date.MustEastern()) - next := Date.NextHour(start) - assert.Equal(2015, next.Year()) - assert.Equal(07, next.Month()) - assert.Equal(01, next.Day()) - assert.Equal(10, next.Hour()) - assert.Equal(00, next.Minute()) - - next = Date.NextHour(next) - assert.Equal(11, next.Hour()) - - next = Date.NextHour(next) - assert.Equal(12, next.Hour()) - -} - -func TestDateNextDayOfWeek(t *testing.T) { - assert := assert.New(t) - - weds := Date.Date(2016, 8, 10, time.UTC) - fri := Date.Date(2016, 8, 12, time.UTC) - sun := Date.Date(2016, 8, 14, time.UTC) - mon := Date.Date(2016, 8, 15, time.UTC) - weds2 := Date.Date(2016, 8, 17, time.UTC) - - nextFri := Date.NextDayOfWeek(weds, time.Friday) - nextSunday := Date.NextDayOfWeek(weds, time.Sunday) - nextMonday := Date.NextDayOfWeek(weds, time.Monday) - nextWeds := Date.NextDayOfWeek(weds, time.Wednesday) - - assert.Equal(fri.Year(), nextFri.Year()) - assert.Equal(fri.Month(), nextFri.Month()) - assert.Equal(fri.Day(), nextFri.Day()) - - assert.Equal(sun.Year(), nextSunday.Year()) - assert.Equal(sun.Month(), nextSunday.Month()) - assert.Equal(sun.Day(), nextSunday.Day()) - - assert.Equal(mon.Year(), nextMonday.Year()) - assert.Equal(mon.Month(), nextMonday.Month()) - assert.Equal(mon.Day(), nextMonday.Day()) - - assert.Equal(weds2.Year(), nextWeds.Year()) - assert.Equal(weds2.Month(), nextWeds.Month()) - assert.Equal(weds2.Day(), nextWeds.Day()) - - assert.Equal(time.UTC, nextFri.Location()) - assert.Equal(time.UTC, nextSunday.Location()) - assert.Equal(time.UTC, nextMonday.Location()) -} diff --git a/util/math_test.go b/util/math_test.go deleted file mode 100644 index 12a450a..0000000 --- a/util/math_test.go +++ /dev/null @@ -1,151 +0,0 @@ -package util - -import ( - "testing" - - "github.com/blend/go-sdk/assert" -) - -func TestMinAndMax(t *testing.T) { - assert := assert.New(t) - values := []float64{1.0, 2.0, 3.0, 4.0} - min, max := Math.MinAndMax(values...) - assert.Equal(1.0, min) - assert.Equal(4.0, max) -} - -func TestMinAndMaxReversed(t *testing.T) { - assert := assert.New(t) - values := []float64{4.0, 2.0, 3.0, 1.0} - min, max := Math.MinAndMax(values...) - assert.Equal(1.0, min) - assert.Equal(4.0, max) -} - -func TestMinAndMaxEmpty(t *testing.T) { - assert := assert.New(t) - values := []float64{} - min, max := Math.MinAndMax(values...) - assert.Equal(0.0, min) - assert.Equal(0.0, max) -} - -func TestGetRoundToForDelta(t *testing.T) { - assert := assert.New(t) - - assert.Equal(100.0, Math.GetRoundToForDelta(1001.00)) - assert.Equal(10.0, Math.GetRoundToForDelta(101.00)) - assert.Equal(1.0, Math.GetRoundToForDelta(11.00)) -} - -func TestRoundUp(t *testing.T) { - assert := assert.New(t) - assert.Equal(0.5, Math.RoundUp(0.49, 0.1)) - assert.Equal(1.0, Math.RoundUp(0.51, 1.0)) - assert.Equal(0.4999, Math.RoundUp(0.49988, 0.0001)) - assert.Equal(0.123, Math.RoundUp(0.123, 0)) -} - -func TestRoundDown(t *testing.T) { - assert := assert.New(t) - assert.Equal(0.5, Math.RoundDown(0.51, 0.1)) - assert.Equal(1.0, Math.RoundDown(1.01, 1.0)) - assert.Equal(0.5001, Math.RoundDown(0.50011, 0.0001)) - assert.Equal(0.123, Math.RoundDown(0.123, 0)) -} - -func TestPercentDifference(t *testing.T) { - assert := assert.New(t) - - assert.Equal(0.5, Math.PercentDifference(1.0, 1.5)) - assert.Equal(-0.5, Math.PercentDifference(2.0, 1.0)) -} - -func TestNormalize(t *testing.T) { - assert := assert.New(t) - - values := []float64{10, 9, 8, 7, 6} - normalized := Math.Normalize(values...) - assert.Len(normalized, 5) - assert.Equal(0.25, normalized[0]) - assert.Equal(0.1499, normalized[4]) -} - -var ( - _degreesToRadians = map[float64]float64{ - 0: 0, // !_2pi b/c no irrational nums in floats. - 45: _pi4, - 90: _pi2, - 135: _3pi4, - 180: _pi, - 225: _5pi4, - 270: _3pi2, - 315: _7pi4, - } - - _compassToRadians = map[float64]float64{ - 0: _pi2, - 45: _pi4, - 90: 0, // !_2pi b/c no irrational nums in floats. - 135: _7pi4, - 180: _3pi2, - 225: _5pi4, - 270: _pi, - 315: _3pi4, - } -) - -func TestDegreesToRadians(t *testing.T) { - assert := assert.New(t) - - for d, r := range _degreesToRadians { - assert.Equal(r, Math.DegreesToRadians(d)) - } -} - -func TestPercentToRadians(t *testing.T) { - assert := assert.New(t) - - for d, r := range _degreesToRadians { - assert.Equal(r, Math.PercentToRadians(d/360.0)) - } -} - -func TestRadiansToDegrees(t *testing.T) { - assert := assert.New(t) - - for d, r := range _degreesToRadians { - assert.Equal(d, Math.RadiansToDegrees(r)) - } -} - -func TestRadianAdd(t *testing.T) { - assert := assert.New(t) - - assert.Equal(_pi, Math.RadianAdd(_pi2, _pi2)) - assert.Equal(_3pi2, Math.RadianAdd(_pi2, _pi)) - assert.Equal(_pi, Math.RadianAdd(_pi, _2pi)) - assert.Equal(_pi, Math.RadianAdd(_pi, -_2pi)) -} - -func TestRotateCoordinate90(t *testing.T) { - assert := assert.New(t) - - cx, cy := 10, 10 - x, y := 5, 10 - - rx, ry := Math.RotateCoordinate(cx, cy, x, y, Math.DegreesToRadians(90)) - assert.Equal(10, rx) - assert.Equal(5, ry) -} - -func TestRotateCoordinate45(t *testing.T) { - assert := assert.New(t) - - cx, cy := 10, 10 - x, y := 5, 10 - - rx, ry := Math.RotateCoordinate(cx, cy, x, y, Math.DegreesToRadians(45)) - assert.Equal(7, rx) - assert.Equal(7, ry) -} diff --git a/util/time_test.go b/util/time_test.go deleted file mode 100644 index beeec65..0000000 --- a/util/time_test.go +++ /dev/null @@ -1,64 +0,0 @@ -package util - -import ( - "testing" - "time" - - "github.com/blend/go-sdk/assert" -) - -func TestTimeDiffDays(t *testing.T) { - assert := assert.New(t) - - t1 := time.Date(2017, 02, 27, 12, 0, 0, 0, time.UTC) - t2 := time.Date(2017, 01, 10, 3, 0, 0, 0, time.UTC) - t3 := time.Date(2017, 02, 24, 16, 0, 0, 0, time.UTC) - - assert.Equal(48, Time.DiffDays(t2, t1)) - assert.Equal(2, Time.DiffDays(t3, t1)) // technically we should round down. -} - -func TestTimeDiffHours(t *testing.T) { - assert := assert.New(t) - - t1 := time.Date(2017, 02, 27, 12, 0, 0, 0, time.UTC) - t2 := time.Date(2017, 02, 24, 16, 0, 0, 0, time.UTC) - t3 := time.Date(2017, 02, 28, 12, 0, 0, 0, time.UTC) - - assert.Equal(68, Time.DiffHours(t2, t1)) - assert.Equal(24, Time.DiffHours(t1, t3)) -} - -func TestTimeStartAndEnd(t *testing.T) { - assert := assert.New(t) - values := []time.Time{ - time.Now().AddDate(0, 0, -1), - time.Now().AddDate(0, 0, -2), - time.Now().AddDate(0, 0, -3), - time.Now().AddDate(0, 0, -4), - } - min, max := Time.StartAndEnd(values...) - assert.Equal(values[3], min) - assert.Equal(values[0], max) -} - -func TestTimeStartAndEndReversed(t *testing.T) { - assert := assert.New(t) - values := []time.Time{ - time.Now().AddDate(0, 0, -4), - time.Now().AddDate(0, 0, -2), - time.Now().AddDate(0, 0, -3), - time.Now().AddDate(0, 0, -1), - } - min, max := Time.StartAndEnd(values...) - assert.Equal(values[0], min) - assert.Equal(values[3], max) -} - -func TestTimeStartAndEndEmpty(t *testing.T) { - assert := assert.New(t) - values := []time.Time{} - min, max := Time.StartAndEnd(values...) - assert.Equal(time.Time{}, min) - assert.Equal(time.Time{}, max) -} diff --git a/value_formatter_test.go b/value_formatter_test.go deleted file mode 100644 index f8cdf08..0000000 --- a/value_formatter_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package chart - -import ( - "testing" - "time" - - "github.com/blend/go-sdk/assert" - "git.gutmet.org/go-chart.git/util" -) - -func TestTimeValueFormatterWithFormat(t *testing.T) { - assert := assert.New(t) - - d := time.Now() - di := util.Time.ToFloat64(d) - df := float64(di) - - s := formatTime(d, DefaultDateFormat) - si := formatTime(di, DefaultDateFormat) - sf := formatTime(df, DefaultDateFormat) - assert.Equal(s, si) - assert.Equal(s, sf) - - sd := TimeValueFormatter(d) - sdi := TimeValueFormatter(di) - sdf := TimeValueFormatter(df) - assert.Equal(s, sd) - assert.Equal(s, sdi) - assert.Equal(s, sdf) -} - -func TestFloatValueFormatter(t *testing.T) { - assert := assert.New(t) - assert.Equal("1234.00", FloatValueFormatter(1234.00)) -} - -func TestFloatValueFormatterWithFloat32Input(t *testing.T) { - assert := assert.New(t) - assert.Equal("1234.00", FloatValueFormatter(float32(1234.00))) -} - -func TestFloatValueFormatterWithIntegerInput(t *testing.T) { - assert := assert.New(t) - assert.Equal("1234.00", FloatValueFormatter(1234)) -} - -func TestFloatValueFormatterWithInt64Input(t *testing.T) { - assert := assert.New(t) - assert.Equal("1234.00", FloatValueFormatter(int64(1234))) -} - -func TestFloatValueFormatterWithFormat(t *testing.T) { - assert := assert.New(t) - - v := 123.456 - sv := FloatValueFormatterWithFormat(v, "%.3f") - assert.Equal("123.456", sv) - assert.Equal("123.000", FloatValueFormatterWithFormat(123, "%.3f")) -} diff --git a/value_test.go b/value_test.go deleted file mode 100644 index ed7a96f..0000000 --- a/value_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package chart - -import ( - "testing" - - assert "github.com/blend/go-sdk/assert" -) - -func TestValuesValues(t *testing.T) { - assert := assert.New(t) - - vs := []Value{ - {Value: 10, Label: "Blue"}, - {Value: 9, Label: "Green"}, - {Value: 8, Label: "Gray"}, - {Value: 7, Label: "Orange"}, - {Value: 6, Label: "HEANG"}, - {Value: 5, Label: "??"}, - {Value: 2, Label: "!!"}, - } - - values := Values(vs).Values() - assert.Len(values, 7) - assert.Equal(10, values[0]) - assert.Equal(9, values[1]) - assert.Equal(8, values[2]) - assert.Equal(7, values[3]) - assert.Equal(6, values[4]) - assert.Equal(5, values[5]) - assert.Equal(2, values[6]) -} - -func TestValuesValuesNormalized(t *testing.T) { - assert := assert.New(t) - - vs := []Value{ - {Value: 10, Label: "Blue"}, - {Value: 9, Label: "Green"}, - {Value: 8, Label: "Gray"}, - {Value: 7, Label: "Orange"}, - {Value: 6, Label: "HEANG"}, - {Value: 5, Label: "??"}, - {Value: 2, Label: "!!"}, - } - - values := Values(vs).ValuesNormalized() - assert.Len(values, 7) - assert.Equal(0.2127, values[0]) - assert.Equal(0.0425, values[6]) -} - -func TestValuesNormalize(t *testing.T) { - assert := assert.New(t) - - vs := []Value{ - {Value: 10, Label: "Blue"}, - {Value: 9, Label: "Green"}, - {Value: 8, Label: "Gray"}, - {Value: 7, Label: "Orange"}, - {Value: 6, Label: "HEANG"}, - {Value: 5, Label: "??"}, - {Value: 2, Label: "!!"}, - } - - values := Values(vs).Normalize() - assert.Len(values, 7) - assert.Equal(0.2127, values[0].Value) - assert.Equal(0.0425, values[6].Value) -} diff --git a/vector_renderer_test.go b/vector_renderer_test.go deleted file mode 100644 index 36e6cd8..0000000 --- a/vector_renderer_test.go +++ /dev/null @@ -1,119 +0,0 @@ -package chart - -import ( - "bytes" - "fmt" - "strings" - "testing" - - "github.com/blend/go-sdk/assert" - "git.gutmet.org/go-chart.git/drawing" -) - -func TestVectorRendererPath(t *testing.T) { - assert := assert.New(t) - - vr, err := SVG(100, 100) - assert.Nil(err) - - typed, isTyped := vr.(*vectorRenderer) - assert.True(isTyped) - - typed.MoveTo(0, 0) - typed.LineTo(100, 100) - typed.LineTo(0, 100) - typed.Close() - typed.FillStroke() - - buffer := bytes.NewBuffer([]byte{}) - err = typed.Save(buffer) - assert.Nil(err) - - raw := string(buffer.Bytes()) - - assert.True(strings.HasPrefix(raw, "")) -} - -func TestVectorRendererMeasureText(t *testing.T) { - assert := assert.New(t) - - f, err := GetDefaultFont() - assert.Nil(err) - - vr, err := SVG(100, 100) - assert.Nil(err) - - vr.SetDPI(DefaultDPI) - vr.SetFont(f) - vr.SetFontSize(12.0) - - tb := vr.MeasureText("Ljp") - assert.Equal(21, tb.Width()) - assert.Equal(15, tb.Height()) -} - -func TestCanvasStyleSVG(t *testing.T) { - assert := assert.New(t) - - f, err := GetDefaultFont() - assert.Nil(err) - - set := Style{ - StrokeColor: drawing.ColorWhite, - StrokeWidth: 5.0, - FillColor: drawing.ColorWhite, - FontColor: drawing.ColorWhite, - Font: f, - Padding: DefaultBackgroundPadding, - } - - canvas := &canvas{dpi: DefaultDPI} - - svgString := canvas.styleAsSVG(set) - assert.NotEmpty(svgString) - assert.True(strings.HasPrefix(svgString, "style=\"")) - assert.True(strings.Contains(svgString, "stroke:rgba(255,255,255,1.0)")) - assert.True(strings.Contains(svgString, "stroke-width:5")) - assert.True(strings.Contains(svgString, "fill:rgba(255,255,255,1.0)")) - assert.True(strings.HasSuffix(svgString, "\"")) -} - -func TestCanvasClassSVG(t *testing.T) { - as := assert.New(t) - - set := Style{ - ClassName: "test-class", - } - - canvas := &canvas{dpi: DefaultDPI} - - as.Equal("class=\"test-class\"", canvas.styleAsSVG(set)) -} - -func TestCanvasCustomInlineStylesheet(t *testing.T) { - b := strings.Builder{} - - canvas := &canvas{ - w: &b, - css: ".background { fill: red }", - } - - canvas.Start(200, 200) - - assert.New(t).Contains(b.String(), fmt.Sprintf(``, canvas.css)) -} - -func TestCanvasCustomInlineStylesheetWithNonce(t *testing.T) { - b := strings.Builder{} - - canvas := &canvas{ - w: &b, - css: ".background { fill: red }", - nonce: "RAND0MSTRING", - } - - canvas.Start(200, 200) - - assert.New(t).Contains(b.String(), fmt.Sprintf(``, canvas.nonce, canvas.css)) -} \ No newline at end of file diff --git a/xaxis_test.go b/xaxis_test.go deleted file mode 100644 index 516be73..0000000 --- a/xaxis_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package chart - -import ( - "testing" - - "github.com/blend/go-sdk/assert" -) - -func TestXAxisGetTicks(t *testing.T) { - assert := assert.New(t) - - r, err := PNG(1024, 1024) - assert.Nil(err) - - f, err := GetDefaultFont() - assert.Nil(err) - - xa := XAxis{} - xr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024} - styleDefaults := Style{ - Font: f, - FontSize: 10.0, - } - vf := FloatValueFormatter - ticks := xa.GetTicks(r, xr, styleDefaults, vf) - assert.Len(ticks, 16) -} - -func TestXAxisGetTicksWithUserDefaults(t *testing.T) { - assert := assert.New(t) - - r, err := PNG(1024, 1024) - assert.Nil(err) - - f, err := GetDefaultFont() - assert.Nil(err) - - xa := XAxis{ - Ticks: []Tick{{Value: 1.0, Label: "1.0"}}, - } - xr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024} - styleDefaults := Style{ - Font: f, - FontSize: 10.0, - } - vf := FloatValueFormatter - ticks := xa.GetTicks(r, xr, styleDefaults, vf) - assert.Len(ticks, 1) -} - -func TestXAxisMeasure(t *testing.T) { - assert := assert.New(t) - - f, err := GetDefaultFont() - assert.Nil(err) - style := Style{ - Font: f, - FontSize: 10.0, - } - r, err := PNG(100, 100) - assert.Nil(err) - ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}} - xa := XAxis{} - xab := xa.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks) - assert.Equal(122, xab.Width()) - assert.Equal(21, xab.Height()) -} diff --git a/yaxis_test.go b/yaxis_test.go deleted file mode 100644 index 9b903ba..0000000 --- a/yaxis_test.go +++ /dev/null @@ -1,85 +0,0 @@ -package chart - -import ( - "testing" - - "github.com/blend/go-sdk/assert" -) - -func TestYAxisGetTicks(t *testing.T) { - assert := assert.New(t) - - r, err := PNG(1024, 1024) - assert.Nil(err) - - f, err := GetDefaultFont() - assert.Nil(err) - - ya := YAxis{} - yr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024} - styleDefaults := Style{ - Font: f, - FontSize: 10.0, - } - vf := FloatValueFormatter - ticks := ya.GetTicks(r, yr, styleDefaults, vf) - assert.Len(ticks, 32) -} - -func TestYAxisGetTicksWithUserDefaults(t *testing.T) { - assert := assert.New(t) - - r, err := PNG(1024, 1024) - assert.Nil(err) - - f, err := GetDefaultFont() - assert.Nil(err) - - ya := YAxis{ - Ticks: []Tick{{Value: 1.0, Label: "1.0"}}, - } - yr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024} - styleDefaults := Style{ - Font: f, - FontSize: 10.0, - } - vf := FloatValueFormatter - ticks := ya.GetTicks(r, yr, styleDefaults, vf) - assert.Len(ticks, 1) -} - -func TestYAxisMeasure(t *testing.T) { - assert := assert.New(t) - - f, err := GetDefaultFont() - assert.Nil(err) - style := Style{ - Font: f, - FontSize: 10.0, - } - r, err := PNG(100, 100) - assert.Nil(err) - ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}} - ya := YAxis{} - yab := ya.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks) - assert.Equal(32, yab.Width()) - assert.Equal(110, yab.Height()) -} - -func TestYAxisSecondaryMeasure(t *testing.T) { - assert := assert.New(t) - - f, err := GetDefaultFont() - assert.Nil(err) - style := Style{ - Font: f, - FontSize: 10.0, - } - r, err := PNG(100, 100) - assert.Nil(err) - ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}} - ya := YAxis{AxisType: YAxisSecondary} - yab := ya.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks) - assert.Equal(32, yab.Width()) - assert.Equal(110, yab.Height()) -}