-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpie_test.go
47 lines (37 loc) · 1.09 KB
/
pie_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
package gopie
import "testing"
func TestCalculateSlicesRadiusNoStroke(t *testing.T) {
r := rectangle{Left: 0, Top: 0, Width: 100, Height: 100}
chart := PieChart{StrokeWidth: 0}
radius := calculateSlicesRadius(chart, r)
expected := r.Width / 2
if radius != expected {
t.Fatalf("Expected %v but found %v", expected, radius)
}
}
func TestCalculateSlicesRadiusWithStroke(t *testing.T) {
strokeWidth := 10.0
r := rectangle{Left: 0, Top: 0, Width: 100, Height: 100}
chart := PieChart{StrokeWidth: strokeWidth}
radius := calculateSlicesRadius(chart, r)
expected := r.Width/2 - strokeWidth/2
if radius != expected {
t.Fatalf("Expected %v but found %v", expected, radius)
}
}
func TestCreateBackgroundCircle(t *testing.T) {
chart := PieChart{}
rect := rectangle{Left: 0, Top: 0, Width: 100, Height: 100}
actualCircle := createBackgroundCircle(chart, rect)
expectedCircle := circle{
CenterX: 50,
CenterY: 50,
Radius: 50,
Style: style{
Fill: defaultStrokeColor,
},
}
if *actualCircle != expectedCircle {
t.Fatalf("Expected %v but found %v", *actualCircle, expectedCircle)
}
}