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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/**************************************************************************/
/* test_vector3i.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_VECTOR3I_H
#define TEST_VECTOR3I_H
#include "core/math/vector3i.h"
#include "tests/test_macros.h"
namespace TestVector3i {
TEST_CASE("[Vector3i] Constructor methods") {
const Vector3i vector_empty = Vector3i();
const Vector3i vector_zero = Vector3i(0, 0, 0);
CHECK_MESSAGE(
vector_empty == vector_zero,
"Vector3i Constructor with no inputs should return a zero Vector3i.");
}
TEST_CASE("[Vector3i] Axis methods") {
Vector3i vector = Vector3i(1, 2, 3);
CHECK_MESSAGE(
vector.max_axis_index() == Vector3i::Axis::AXIS_Z,
"Vector3i max_axis_index should work as expected.");
CHECK_MESSAGE(
vector.min_axis_index() == Vector3i::Axis::AXIS_X,
"Vector3i min_axis_index should work as expected.");
CHECK_MESSAGE(
vector[vector.max_axis_index()] == 3,
"Vector3i array operator should work as expected.");
CHECK_MESSAGE(
vector[vector.min_axis_index()] == 1,
"Vector3i array operator should work as expected.");
vector[Vector3i::Axis::AXIS_Y] = 5;
CHECK_MESSAGE(
vector[Vector3i::Axis::AXIS_Y] == 5,
"Vector3i array operator setter should work as expected.");
}
TEST_CASE("[Vector3i] Clamp method") {
const Vector3i vector = Vector3i(10, 10, 10);
CHECK_MESSAGE(
Vector3i(-5, 5, 15).clamp(Vector3i(), vector) == Vector3i(0, 5, 10),
"Vector3i clamp should work as expected.");
CHECK_MESSAGE(
vector.clamp(Vector3i(0, 10, 15), Vector3i(5, 10, 20)) == Vector3i(5, 10, 15),
"Vector3i clamp should work as expected.");
}
TEST_CASE("[Vector3i] Length methods") {
const Vector3i vector1 = Vector3i(10, 10, 10);
const Vector3i vector2 = Vector3i(20, 30, 40);
CHECK_MESSAGE(
vector1.length_squared() == 300,
"Vector3i length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
vector1.length() == doctest::Approx(10 * Math_SQRT3),
"Vector3i length should work as expected.");
CHECK_MESSAGE(
vector2.length_squared() == 2900,
"Vector3i length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
vector2.length() == doctest::Approx(53.8516480713450403125),
"Vector3i length should work as expected.");
}
TEST_CASE("[Vector3i] Operators") {
const Vector3i vector1 = Vector3i(4, 5, 9);
const Vector3i vector2 = Vector3i(1, 2, 3);
CHECK_MESSAGE(
(vector1 + vector2) == Vector3i(5, 7, 12),
"Vector3i addition with integers should give exact results.");
CHECK_MESSAGE(
(vector1 - vector2) == Vector3i(3, 3, 6),
"Vector3i subtraction with integers should give exact results.");
CHECK_MESSAGE(
(vector1 * vector2) == Vector3i(4, 10, 27),
"Vector3i multiplication with integers should give exact results.");
CHECK_MESSAGE(
(vector1 / vector2) == Vector3i(4, 2, 3),
"Vector3i division with integers should give exact results.");
CHECK_MESSAGE(
(vector1 * 2) == Vector3i(8, 10, 18),
"Vector3i multiplication with integers should give exact results.");
CHECK_MESSAGE(
(vector1 / 2) == Vector3i(2, 2, 4),
"Vector3i division with integers should give exact results.");
CHECK_MESSAGE(
((Vector3)vector1) == Vector3(4, 5, 9),
"Vector3i cast to Vector3 should work as expected.");
CHECK_MESSAGE(
((Vector3)vector2) == Vector3(1, 2, 3),
"Vector3i cast to Vector3 should work as expected.");
CHECK_MESSAGE(
Vector3i(Vector3(1.1, 2.9, 3.9)) == Vector3i(1, 2, 3),
"Vector3i constructed from Vector3 should work as expected.");
}
TEST_CASE("[Vector3i] Other methods") {
const Vector3i vector = Vector3i(1, 3, -7);
CHECK_MESSAGE(
vector.min(Vector3i(3, 2, 5)) == Vector3i(1, 2, -7),
"Vector3i min should return expected value.");
CHECK_MESSAGE(
vector.max(Vector3i(5, 2, 4)) == Vector3i(5, 3, 4),
"Vector3i max should return expected value.");
CHECK_MESSAGE(
vector.snapped(Vector3i(4, 2, 5)) == Vector3i(0, 4, -5),
"Vector3i snapped should work as expected.");
}
TEST_CASE("[Vector3i] Abs and sign methods") {
const Vector3i vector1 = Vector3i(1, 3, 5);
const Vector3i vector2 = Vector3i(1, -3, -5);
CHECK_MESSAGE(
vector1.abs() == vector1,
"Vector3i abs should work as expected.");
CHECK_MESSAGE(
vector2.abs() == vector1,
"Vector3i abs should work as expected.");
CHECK_MESSAGE(
vector1.sign() == Vector3i(1, 1, 1),
"Vector3i sign should work as expected.");
CHECK_MESSAGE(
vector2.sign() == Vector3i(1, -1, -1),
"Vector3i sign should work as expected.");
}
} // namespace TestVector3i
#endif // TEST_VECTOR3I_H
|