forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geometry_test.go
150 lines (113 loc) · 3 KB
/
geometry_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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package fyne
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPosition_Add(t *testing.T) {
pos1 := NewPos(10, 10)
pos2 := NewPos(25, 25)
pos3 := pos1.Add(pos2)
assert.Equal(t, float32(35), pos3.X)
assert.Equal(t, float32(35), pos3.Y)
}
func TestPosition_Add_Size(t *testing.T) {
pos1 := NewPos(10, 10)
s := NewSize(25, 25)
pos2 := pos1.Add(s)
assert.Equal(t, float32(35), pos2.X)
assert.Equal(t, float32(35), pos2.Y)
}
func TestPosition_Add_Vector(t *testing.T) {
pos1 := NewPos(10, 10)
v := NewDelta(25, 25)
pos2 := pos1.Add(v)
assert.Equal(t, float32(35), pos2.X)
assert.Equal(t, float32(35), pos2.Y)
}
func TestPosition_IsZero(t *testing.T) {
for name, tt := range map[string]struct {
p Position
want bool
}{
"zero value": {Position{}, true},
"0,0": {NewPos(0, 0), true},
"zero X": {NewPos(0, 42), false},
"zero Y": {NewPos(17, 0), false},
"non-zero X and Y": {NewPos(6, 9), false},
} {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.p.IsZero())
})
}
}
func TestPosition_Subtract(t *testing.T) {
pos1 := NewPos(25, 25)
pos2 := NewPos(10, 10)
pos3 := pos1.Subtract(pos2)
assert.Equal(t, float32(15), pos3.X)
assert.Equal(t, float32(15), pos3.Y)
}
func TestSize_Add(t *testing.T) {
size1 := NewSize(10, 10)
size2 := NewSize(25, 25)
size3 := size1.Add(size2)
assert.Equal(t, float32(35), size3.Width)
assert.Equal(t, float32(35), size3.Height)
}
func TestSize_Add_Position(t *testing.T) {
size1 := NewSize(10, 10)
p := NewSize(25, 25)
size2 := size1.Add(p)
assert.Equal(t, float32(35), size2.Width)
assert.Equal(t, float32(35), size2.Height)
}
func TestSize_Add_Vector(t *testing.T) {
size1 := NewSize(10, 10)
v := NewDelta(25, 25)
size2 := size1.Add(v)
assert.Equal(t, float32(35), size2.Width)
assert.Equal(t, float32(35), size2.Height)
}
func TestSize_IsZero(t *testing.T) {
for name, tt := range map[string]struct {
s Size
want bool
}{
"zero value": {Size{}, true},
"0x0": {NewSize(0, 0), true},
"zero width": {NewSize(0, 42), false},
"zero height": {NewSize(17, 0), false},
"non-zero area": {NewSize(6, 9), false},
} {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.s.IsZero())
})
}
}
func TestSize_Max(t *testing.T) {
size1 := NewSize(10, 100)
size2 := NewSize(100, 10)
size3 := size1.Max(size2)
assert.Equal(t, float32(100), size3.Width)
assert.Equal(t, float32(100), size3.Height)
}
func TestSize_Min(t *testing.T) {
size1 := NewSize(10, 100)
size2 := NewSize(100, 10)
size3 := size1.Min(size2)
assert.Equal(t, float32(10), size3.Width)
assert.Equal(t, float32(10), size3.Height)
}
func TestSize_Subtract(t *testing.T) {
size1 := NewSize(25, 25)
size2 := NewSize(10, 10)
size3 := size1.Subtract(size2)
assert.Equal(t, float32(15), size3.Width)
assert.Equal(t, float32(15), size3.Height)
}
func TestVector_IsZero(t *testing.T) {
v := NewDelta(0, 0)
assert.True(t, v.IsZero())
v.DX = 1
assert.False(t, v.IsZero())
}