forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vectors_test.go
114 lines (99 loc) · 3.54 KB
/
Vectors_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
package imgui_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/inkyblackness/imgui-go/v4"
)
func TestVec2Addition(t *testing.T) {
tt := []struct {
first imgui.Vec2
second imgui.Vec2
expected imgui.Vec2
}{
{first: imgui.Vec2{X: 0, Y: 0}, second: imgui.Vec2{X: 10, Y: 10}, expected: imgui.Vec2{X: 10, Y: 10}},
{first: imgui.Vec2{X: 10, Y: 10}, second: imgui.Vec2{X: -20, Y: 100.5}, expected: imgui.Vec2{X: -10, Y: 110.5}},
{first: imgui.Vec2{X: 2, Y: 4}, second: imgui.Vec2{X: -2, Y: -4}, expected: imgui.Vec2{X: 0, Y: 0}},
}
for _, tc := range tt {
assert.Equal(t, tc.expected, tc.first.Plus(tc.second), "Failed for %v + %v", tc.first, tc.second)
}
}
func TestVec2Subtraction(t *testing.T) {
tt := []struct {
first imgui.Vec2
second imgui.Vec2
expected imgui.Vec2
}{
{first: imgui.Vec2{X: 0, Y: 0}, second: imgui.Vec2{X: 10, Y: 10}, expected: imgui.Vec2{X: -10, Y: -10}},
{first: imgui.Vec2{X: 10, Y: 10}, second: imgui.Vec2{X: -20, Y: 100.5}, expected: imgui.Vec2{X: 30, Y: -90.5}},
{first: imgui.Vec2{X: 2, Y: 4}, second: imgui.Vec2{X: -2, Y: -4}, expected: imgui.Vec2{X: 4, Y: 8}},
}
for _, tc := range tt {
assert.Equal(t, tc.expected, tc.first.Minus(tc.second), "Failed for %v - %v", tc.first, tc.second)
}
}
func TestVec2Scaling(t *testing.T) {
tt := []struct {
first imgui.Vec2
scale float32
expected imgui.Vec2
}{
{first: imgui.Vec2{X: 1, Y: 2}, scale: 1.0, expected: imgui.Vec2{X: 1, Y: 2}},
{first: imgui.Vec2{X: 10, Y: 10}, scale: 0.0, expected: imgui.Vec2{X: 0, Y: 0}},
{first: imgui.Vec2{X: 2, Y: 4}, scale: -2.0, expected: imgui.Vec2{X: -4, Y: -8}},
}
for _, tc := range tt {
assert.Equal(t, tc.expected, tc.first.Times(tc.scale), "Failed for %v * %v", tc.first, tc.scale)
}
}
func TestVec4Addition(t *testing.T) {
vec := func(x, y, z, w float32) imgui.Vec4 {
return imgui.Vec4{X: x, Y: y, Z: z, W: w}
}
tt := []struct {
first imgui.Vec4
second imgui.Vec4
expected imgui.Vec4
}{
{first: vec(0, 0, 0, 0), second: vec(10, 20, 30, 40), expected: vec(10, 20, 30, 40)},
{first: vec(10, 20, 30, 40), second: vec(-5, -5, -5, -5), expected: vec(5, 15, 25, 35)},
{first: vec(1, 2, 3, 4), second: vec(-10, -10, -10, -10), expected: vec(-9, -8, -7, -6)},
}
for _, tc := range tt {
assert.Equal(t, tc.expected, tc.first.Plus(tc.second), "Failed for %v + %v", tc.first, tc.second)
}
}
func TestVec4Subtraction(t *testing.T) {
vec := func(x, y, z, w float32) imgui.Vec4 {
return imgui.Vec4{X: x, Y: y, Z: z, W: w}
}
tt := []struct {
first imgui.Vec4
second imgui.Vec4
expected imgui.Vec4
}{
{first: vec(0, 0, 0, 0), second: vec(10, 20, 30, 40), expected: vec(-10, -20, -30, -40)},
{first: vec(10, 20, 30, 40), second: vec(-5, -5, -5, -5), expected: vec(15, 25, 35, 45)},
{first: vec(1, 2, 3, 4), second: vec(-10, -10, -10, -10), expected: vec(11, 12, 13, 14)},
}
for _, tc := range tt {
assert.Equal(t, tc.expected, tc.first.Minus(tc.second), "Failed for %v - %v", tc.first, tc.second)
}
}
func TestVec4Scaling(t *testing.T) {
vec := func(x, y, z, w float32) imgui.Vec4 {
return imgui.Vec4{X: x, Y: y, Z: z, W: w}
}
tt := []struct {
first imgui.Vec4
scale float32
expected imgui.Vec4
}{
{first: vec(10, 20, 30, 40), scale: 1.0, expected: vec(10, 20, 30, 40)},
{first: vec(10, 20, 30, 40), scale: -0.5, expected: vec(-5, -10, -15, -20)},
{first: vec(1, 2, 3, 4), scale: 2.0, expected: vec(2, 4, 6, 8)},
}
for _, tc := range tt {
assert.Equal(t, tc.expected, tc.first.Times(tc.scale), "Failed for %v * %v", tc.first, tc.scale)
}
}