-
Notifications
You must be signed in to change notification settings - Fork 0
/
margin_test.go
136 lines (111 loc) · 2.45 KB
/
margin_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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package geom
import "testing"
func TestMakeMargin(t *testing.T) {
if m := MakeMargin(0.5); m != (Margin{
Top: 0.5,
Bottom: 0.5,
Left: 0.5,
Right: 0.5,
}) {
t.Error("MakeMargin returned an invalid value:", m)
}
}
func TestMarginTopLeftZero(t *testing.T) {
m := Margin{}
p := m.TopLeft(Point{
X: 1,
Y: 2,
})
if p != (Point{X: 1, Y: 2}) {
t.Error("margin applied invalid transformation to top-left point:", m, p)
}
}
func TestMarginTopLeftNonZero(t *testing.T) {
m := MakeMargin(0.5)
p := m.TopLeft(Point{
X: 1,
Y: 2,
})
if p != (Point{X: 1.5, Y: 2.5}) {
t.Error("margin applied invalid transformation to top-left point:", m, p)
}
}
func TestMarginBottomRightZero(t *testing.T) {
m := Margin{}
p := m.BottomRight(Point{
X: 1,
Y: 2,
})
if p != (Point{X: 1, Y: 2}) {
t.Error("margin applied invalid transformation to bottom-right point:", m, p)
}
}
func TestMarginBottomRightNonZero(t *testing.T) {
m := MakeMargin(0.5)
p := m.BottomRight(Point{
X: 1,
Y: 2,
})
if p != (Point{X: 0.5, Y: 1.5}) {
t.Error("margin applied invalid transformation to bottom-right point:", m, p)
}
}
func TestMarginGrowRect(t *testing.T) {
m := MakeMargin(0.5)
r := m.GrowRect(Rect{W: 2, H: 2})
if r != (Rect{
X: -0.5,
Y: -0.5,
W: 3,
H: 3,
}) {
t.Error("margin growing rectangle produced an invalid value:", m, r)
}
}
func TestMarginShrinkRect(t *testing.T) {
m := MakeMargin(0.5)
r := m.ShrinkRect(Rect{W: 2, H: 2})
if r != (Rect{
X: 0.5,
Y: 0.5,
W: 1,
H: 1,
}) {
t.Error("margin shrinking rectangle produced an invalid value:", m, r)
}
}
func TestMarginShrinkRectEmpty(t *testing.T) {
m := MakeMargin(2)
r := m.ShrinkRect(Rect{W: 2, H: 2})
if r != (Rect{X: 1, Y: 1}) {
t.Error("margin shrinking rectangle produced an invalid value:", m, r)
}
}
func TestMarginWidth(t *testing.T) {
m := MakeMargin(0.25)
w := m.Width()
if w != 0.5 {
t.Error("invalid margin width:", m, w)
}
}
func TestMarginHeight(t *testing.T) {
m := MakeMargin(0.25)
h := m.Height()
if h != 0.5 {
t.Error("invalid margin height:", m, h)
}
}
func TestMarginSize(t *testing.T) {
m := MakeMargin(0.25)
s := m.Size()
if s != (Size{W: 0.5, H: 0.5}) {
t.Error("invalid margin size:", m, s)
}
}
func TestMarginString(t *testing.T) {
m := MakeMargin(0.25)
s := m.String()
if s != "margin { top = 0.25, bottom = 0.25, left = 0.25, right = 0.25 }" {
t.Errorf("invalid string representation of a margin value: %#v %s", m, s)
}
}