-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstructs_test.go
72 lines (53 loc) · 1.97 KB
/
structs_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
package gopie
import "testing"
func TestRectGetCenterAtZeroPoint(t *testing.T) {
r := rectangle{Left: 0, Top: 0, Width: 10, Height: 15}
cx, cy := r.getCenter()
expectedX := float64(5)
expectedY := float64(7.5)
if !(cx == expectedX && cy == expectedY) {
t.Fatalf("Expected rectangle center to be on (%v, %v) but found (%v, %v)", expectedX, expectedY, cx, cy)
}
}
func TestRectGetCenterShiftedFromZeroPoint(t *testing.T) {
r := rectangle{Left: 14, Top: 16, Width: 10, Height: 15}
cx, cy := r.getCenter()
expectedX := float64(19)
expectedY := float64(23.5)
if !(cx == expectedX && cy == expectedY) {
t.Fatalf("Expected rectangle center to be on (%v, %v) but found (%v, %v)", expectedX, expectedY, cx, cy)
}
}
func TestRectGetCenterShiftedToNegitive(t *testing.T) {
r := rectangle{Left: -14, Top: -16, Width: 10, Height: 15}
cx, cy := r.getCenter()
expectedX := float64(-9)
expectedY := float64(-8.5)
if !(cx == expectedX && cy == expectedY) {
t.Fatalf("Expected rectangle center to be on (%v, %v) but found (%v, %v)", expectedX, expectedY, cx, cy)
}
}
func TestCalculateIncircleRadiusEqualDimesions(t *testing.T) {
r := rectangle{Left: 0, Top: 0, Width: 10, Height: 10}
expectedRadius := float64(5)
radius := r.calculateIncircleRadius()
if !(radius == expectedRadius) {
t.Fatalf("Expected incirle radius be %v but found %v", expectedRadius, radius)
}
}
func TestCalculateIncircleRadiusHeightGreater(t *testing.T) {
r := rectangle{Left: 0, Top: 0, Width: 10, Height: 15}
expectedRadius := float64(5)
radius := r.calculateIncircleRadius()
if !(radius == expectedRadius) {
t.Fatalf("Expected incirle radius be %v but found %v", expectedRadius, radius)
}
}
func TestCalculateIncircleRadiusWidthGreater(t *testing.T) {
r := rectangle{Left: 0, Top: 0, Width: 15, Height: 10}
expectedRadius := float64(5)
radius := r.calculateIncircleRadius()
if !(radius == expectedRadius) {
t.Fatalf("Expected incirle radius be %v but found %v", expectedRadius, radius)
}
}