-
Notifications
You must be signed in to change notification settings - Fork 13
/
gridder_test.go
109 lines (80 loc) · 2.44 KB
/
gridder_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package gridder
import (
"bytes"
"image/color"
"testing"
"github.com/golang/freetype/truetype"
"github.com/stretchr/testify/assert"
"golang.org/x/image/font/gofont/goregular"
)
func TestNew(t *testing.T) {
_, err := New(ImageConfig{}, GridConfig{Rows: 0})
assert.NotNil(t, err)
_, err = New(ImageConfig{}, GridConfig{Rows: 10, Columns: 0})
assert.NotNil(t, err)
_, err = New(ImageConfig{}, GridConfig{Rows: 10, Columns: 10})
assert.Nil(t, err)
}
func TestPaintCell(t *testing.T) {
gridder, err := New(ImageConfig{}, GridConfig{Rows: 1, Columns: 1})
assert.Nil(t, err)
err = gridder.PaintCell(-1, -1, color.Black)
assert.NotNil(t, err)
err = gridder.PaintCell(0, 0, color.Black)
assert.Nil(t, err)
}
func TestDrawCircle(t *testing.T) {
gridder, err := New(ImageConfig{}, GridConfig{Rows: 1, Columns: 1})
assert.Nil(t, err)
err = gridder.DrawCircle(-1, -1)
assert.NotNil(t, err)
err = gridder.DrawCircle(0, 0)
assert.Nil(t, err)
}
func TestDrawRectangle(t *testing.T) {
gridder, err := New(ImageConfig{}, GridConfig{Rows: 1, Columns: 1})
assert.Nil(t, err)
err = gridder.DrawRectangle(-1, -1)
assert.NotNil(t, err)
err = gridder.DrawRectangle(0, 0)
assert.Nil(t, err)
}
func TestDrawLine(t *testing.T) {
gridder, err := New(ImageConfig{}, GridConfig{Rows: 1, Columns: 1})
assert.Nil(t, err)
err = gridder.DrawLine(-1, -1)
assert.NotNil(t, err)
err = gridder.DrawLine(0, 0)
assert.Nil(t, err)
}
func TestDrawPath(t *testing.T) {
gridder, err := New(ImageConfig{}, GridConfig{Rows: 1, Columns: 1})
assert.Nil(t, err)
err = gridder.DrawPath(-1, -1, -1, -1)
assert.NotNil(t, err)
err = gridder.DrawPath(0, 0, 0, 0)
assert.Nil(t, err)
}
func TestDrawString(t *testing.T) {
gridder, err := New(ImageConfig{}, GridConfig{Rows: 1, Columns: 1})
assert.Nil(t, err)
font, _ := truetype.Parse(goregular.TTF)
fontFace := truetype.NewFace(font, &truetype.Options{Size: 24})
err = gridder.DrawString(-1, -1, "Test", fontFace)
assert.NotNil(t, err)
err = gridder.DrawString(0, 0, "Test", fontFace)
assert.Nil(t, err)
}
func TestSave(t *testing.T) {
gridder, err := New(ImageConfig{}, GridConfig{Rows: 1, Columns: 1})
assert.Nil(t, err)
err = gridder.SavePNG()
assert.NotNil(t, err)
}
func TestWriter(t *testing.T) {
gridder, err := New(ImageConfig{}, GridConfig{Rows: 2, Columns: 2, LineStrokeWidth: 2, BorderStrokeWidth: 10})
assert.Nil(t, err)
bImage := new(bytes.Buffer)
err = gridder.EncodePNG(bImage)
assert.Nil(t, err)
}