forked from AllenDang/cimgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector_helpers_test.go
144 lines (132 loc) · 4.01 KB
/
vector_helpers_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
package imgui
import (
"reflect"
"testing"
)
func TestVec2_Add(t *testing.T) {
tests := []struct {
name string
p Vec2
q Vec2
want Vec2
}{
{"Add nothing", Vec2{0, 0}, Vec2{0, 0}, Vec2{0, 0}},
{"Add 1, 5", Vec2{0, 0}, Vec2{1, 5}, Vec2{1, 5}},
{"(20, 4) + (8, 8)", Vec2{20, 4}, Vec2{8, 8}, Vec2{28, 12}},
{"positive + negative", Vec2{20, 4}, Vec2{-8, -8}, Vec2{12, -4}},
{"negative + negative", Vec2{-20, -4}, Vec2{-8, -8}, Vec2{-28, -12}},
{"float + float", Vec2{20.5, 4.5}, Vec2{8.5, 8.5}, Vec2{29, 13}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.p.Add(tt.q); !reflect.DeepEqual(got, tt.want) {
t.Errorf("%#v.Add(%#v) = %v, want %v", tt.p, tt.q, got, tt.want)
}
})
}
}
func TestVec2_Div(t *testing.T) {
tests := []struct {
name string
p Vec2
k float32
want Vec2
}{
{"Simplest", Vec2{0, 0}, 1, Vec2{0, 0}},
{"Divide by 2", Vec2{2, 2}, 2, Vec2{1, 1}},
{"divide by -2", Vec2{2, 2}, -2, Vec2{-1, -1}},
{"divide by float", Vec2{2.5, 2.5}, 2, Vec2{1.25, 1.25}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.p.Div(tt.k); !reflect.DeepEqual(got, tt.want) {
t.Errorf("%#v.Div(%#v) = %v, want %v", tt.p, tt.k, got, tt.want)
}
})
}
}
func TestVec2_Mul(t *testing.T) {
tests := []struct {
name string
p Vec2
k float32
want Vec2
}{
{"multiply by 1", Vec2{1, 1}, 1, Vec2{1, 1}},
{"multiply by -1", Vec2{1, 1}, -1, Vec2{-1, -1}},
{"multiply by 2", Vec2{1, 1}, 2, Vec2{2, 2}},
{"multiply by float", Vec2{1.5, 1.5}, 2, Vec2{3, 3}},
{"multiply by 0", Vec2{1, 1}, 0, Vec2{0, 0}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.p.Mul(tt.k); !reflect.DeepEqual(got, tt.want) {
t.Errorf("%#v.Mul(%#v) = %v, want %v", tt.p, tt.k, got, tt.want)
}
})
}
}
func TestVec2_Sub(t *testing.T) {
tests := []struct {
name string
p, q Vec2
want Vec2
}{
{"Simplest", Vec2{0, 0}, Vec2{0, 0}, Vec2{0, 0}},
{"positive - positive", Vec2{20, 4}, Vec2{8, 8}, Vec2{12, -4}},
{"positive - negative", Vec2{20, 4}, Vec2{-8, -8}, Vec2{28, 12}},
{"negative - positive", Vec2{-20, -4}, Vec2{8, 8}, Vec2{-28, -12}},
{"negative - negative", Vec2{-20, -4}, Vec2{-8, -8}, Vec2{-12, 4}},
{"float - float", Vec2{20.5, 4.5}, Vec2{8.5, 8.5}, Vec2{12, -4}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.p.Sub(tt.q); !reflect.DeepEqual(got, tt.want) {
t.Errorf("%#v.Sub(%#v) = %v, want %v", tt.p, tt.q, got, tt.want)
}
})
}
}
func TestVec4_Add(t *testing.T) {
tests := []struct {
name string
p Vec4
q Vec2
want Vec4
}{
{"Simplest", Vec4{0, 0, 0, 0}, Vec2{0, 0}, Vec4{0, 0, 0, 0}},
{"positive + positive", Vec4{20, 4, 0, 0}, Vec2{8, 8}, Vec4{28, 12, 8, 8}},
{"positive + negative", Vec4{20, 4, 0, 0}, Vec2{-8, -8}, Vec4{12, -4, -8, -8}},
{"negative + positive", Vec4{-20, -4, 0, 0}, Vec2{8, 8}, Vec4{-12, 4, 8, 8}},
{"negative + negative", Vec4{-20, -4, 0, 0}, Vec2{-8, -8}, Vec4{-28, -12, -8, -8}},
{"float + float", Vec4{20.5, 4.5, 0, 0}, Vec2{8.5, 8.5}, Vec4{29, 13, 8.5, 8.5}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.p.Add(tt.q); !reflect.DeepEqual(got, tt.want) {
t.Errorf("%#v.Add(%#v) = %v, want %v", tt.p, tt.q, got, tt.want)
}
})
}
}
func TestVec4_Sub(t *testing.T) {
tests := []struct {
name string
p Vec4
q Vec2
want Vec4
}{
{"Simplest", Vec4{0, 0, 0, 0}, Vec2{0, 0}, Vec4{0, 0, 0, 0}},
{"numbers; no change", Vec4{20, 4, 50, 6}, Vec2{0, 0}, Vec4{20, 4, 50, 6}},
{"numbers; change", Vec4{20, 4, 50, 6}, Vec2{10, 2}, Vec4{10, 2, 40, 4}},
{"floats; no change", Vec4{20.5, 4.5, 50.5, 6.5}, Vec2{0, 0}, Vec4{20.5, 4.5, 50.5, 6.5}},
{"floats; change", Vec4{20.5, 4.5, 50.5, 6.5}, Vec2{10.5, 2.5}, Vec4{10, 2, 40, 4}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.p.Sub(tt.q); !reflect.DeepEqual(got, tt.want) {
t.Errorf("%#v.Sub(%#v) = %v, want %v", tt.p, tt.q, got, tt.want)
}
})
}
}