| 1 |
package chart |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/wcharczuk/go-chart/v2/testutil" |
| 8 |
) |
| 9 |
|
| 10 |
func TestPieChart(t *testing.T) { |
| 11 |
|
| 12 |
|
| 13 |
pie := PieChart{ |
| 14 |
Canvas: Style{ |
| 15 |
FillColor: ColorLightGray, |
| 16 |
}, |
| 17 |
Values: []Value{ |
| 18 |
{Value: 10, Label: "Blue"}, |
| 19 |
{Value: 9, Label: "Green"}, |
| 20 |
{Value: 8, Label: "Gray"}, |
| 21 |
{Value: 7, Label: "Orange"}, |
| 22 |
{Value: 6, Label: "HEANG"}, |
| 23 |
{Value: 5, Label: "??"}, |
| 24 |
{Value: 2, Label: "!!"}, |
| 25 |
}, |
| 26 |
} |
| 27 |
|
| 28 |
b := bytes.NewBuffer([]byte{}) |
| 29 |
pie.Render(PNG, b) |
| 30 |
testutil.AssertNotZero(t, b.Len()) |
| 31 |
} |
| 32 |
|
| 33 |
func TestPieChartDropsZeroValues(t *testing.T) { |
| 34 |
|
| 35 |
|
| 36 |
pie := PieChart{ |
| 37 |
Canvas: Style{ |
| 38 |
FillColor: ColorLightGray, |
| 39 |
}, |
| 40 |
Values: []Value{ |
| 41 |
{Value: 5, Label: "Blue"}, |
| 42 |
{Value: 5, Label: "Green"}, |
| 43 |
{Value: 0, Label: "Gray"}, |
| 44 |
}, |
| 45 |
} |
| 46 |
|
| 47 |
b := bytes.NewBuffer([]byte{}) |
| 48 |
err := pie.Render(PNG, b) |
| 49 |
testutil.AssertNil(t, err) |
| 50 |
} |
| 51 |
|
| 52 |
func TestPieChartAllZeroValues(t *testing.T) { |
| 53 |
|
| 54 |
|
| 55 |
pie := PieChart{ |
| 56 |
Canvas: Style{ |
| 57 |
FillColor: ColorLightGray, |
| 58 |
}, |
| 59 |
Values: []Value{ |
| 60 |
{Value: 0, Label: "Blue"}, |
| 61 |
{Value: 0, Label: "Green"}, |
| 62 |
{Value: 0, Label: "Gray"}, |
| 63 |
}, |
| 64 |
} |
| 65 |
|
| 66 |
b := bytes.NewBuffer([]byte{}) |
| 67 |
err := pie.Render(PNG, b) |
| 68 |
testutil.AssertNotNil(t, err) |
| 69 |
} |