2
0

test_vector3i.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**************************************************************************/
  2. /* test_vector3i.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef TEST_VECTOR3I_H
  31. #define TEST_VECTOR3I_H
  32. #include "core/math/vector3i.h"
  33. #include "tests/test_macros.h"
  34. namespace TestVector3i {
  35. TEST_CASE("[Vector3i] Constructor methods") {
  36. const Vector3i vector_empty = Vector3i();
  37. const Vector3i vector_zero = Vector3i(0, 0, 0);
  38. CHECK_MESSAGE(
  39. vector_empty == vector_zero,
  40. "Vector3i Constructor with no inputs should return a zero Vector3i.");
  41. }
  42. TEST_CASE("[Vector3i] Axis methods") {
  43. Vector3i vector = Vector3i(1, 2, 3);
  44. CHECK_MESSAGE(
  45. vector.max_axis_index() == Vector3i::Axis::AXIS_Z,
  46. "Vector3i max_axis_index should work as expected.");
  47. CHECK_MESSAGE(
  48. vector.min_axis_index() == Vector3i::Axis::AXIS_X,
  49. "Vector3i min_axis_index should work as expected.");
  50. CHECK_MESSAGE(
  51. vector[vector.max_axis_index()] == 3,
  52. "Vector3i array operator should work as expected.");
  53. CHECK_MESSAGE(
  54. vector[vector.min_axis_index()] == 1,
  55. "Vector3i array operator should work as expected.");
  56. vector[Vector3i::Axis::AXIS_Y] = 5;
  57. CHECK_MESSAGE(
  58. vector[Vector3i::Axis::AXIS_Y] == 5,
  59. "Vector3i array operator setter should work as expected.");
  60. }
  61. TEST_CASE("[Vector3i] Clamp method") {
  62. const Vector3i vector = Vector3i(10, 10, 10);
  63. CHECK_MESSAGE(
  64. Vector3i(-5, 5, 15).clamp(Vector3i(), vector) == Vector3i(0, 5, 10),
  65. "Vector3i clamp should work as expected.");
  66. CHECK_MESSAGE(
  67. vector.clamp(Vector3i(0, 10, 15), Vector3i(5, 10, 20)) == Vector3i(5, 10, 15),
  68. "Vector3i clamp should work as expected.");
  69. }
  70. TEST_CASE("[Vector3i] Length methods") {
  71. const Vector3i vector1 = Vector3i(10, 10, 10);
  72. const Vector3i vector2 = Vector3i(20, 30, 40);
  73. CHECK_MESSAGE(
  74. vector1.length_squared() == 300,
  75. "Vector3i length_squared should work as expected and return exact result.");
  76. CHECK_MESSAGE(
  77. vector1.length() == doctest::Approx(10 * Math_SQRT3),
  78. "Vector3i length should work as expected.");
  79. CHECK_MESSAGE(
  80. vector2.length_squared() == 2900,
  81. "Vector3i length_squared should work as expected and return exact result.");
  82. CHECK_MESSAGE(
  83. vector2.length() == doctest::Approx(53.8516480713450403125),
  84. "Vector3i length should work as expected.");
  85. }
  86. TEST_CASE("[Vector3i] Operators") {
  87. const Vector3i vector1 = Vector3i(4, 5, 9);
  88. const Vector3i vector2 = Vector3i(1, 2, 3);
  89. CHECK_MESSAGE(
  90. (vector1 + vector2) == Vector3i(5, 7, 12),
  91. "Vector3i addition with integers should give exact results.");
  92. CHECK_MESSAGE(
  93. (vector1 - vector2) == Vector3i(3, 3, 6),
  94. "Vector3i subtraction with integers should give exact results.");
  95. CHECK_MESSAGE(
  96. (vector1 * vector2) == Vector3i(4, 10, 27),
  97. "Vector3i multiplication with integers should give exact results.");
  98. CHECK_MESSAGE(
  99. (vector1 / vector2) == Vector3i(4, 2, 3),
  100. "Vector3i division with integers should give exact results.");
  101. CHECK_MESSAGE(
  102. (vector1 * 2) == Vector3i(8, 10, 18),
  103. "Vector3i multiplication with integers should give exact results.");
  104. CHECK_MESSAGE(
  105. (vector1 / 2) == Vector3i(2, 2, 4),
  106. "Vector3i division with integers should give exact results.");
  107. CHECK_MESSAGE(
  108. ((Vector3)vector1) == Vector3(4, 5, 9),
  109. "Vector3i cast to Vector3 should work as expected.");
  110. CHECK_MESSAGE(
  111. ((Vector3)vector2) == Vector3(1, 2, 3),
  112. "Vector3i cast to Vector3 should work as expected.");
  113. CHECK_MESSAGE(
  114. Vector3i(Vector3(1.1, 2.9, 3.9)) == Vector3i(1, 2, 3),
  115. "Vector3i constructed from Vector3 should work as expected.");
  116. }
  117. TEST_CASE("[Vector3i] Other methods") {
  118. const Vector3i vector = Vector3i(1, 3, -7);
  119. CHECK_MESSAGE(
  120. vector.min(Vector3i(3, 2, 5)) == Vector3i(1, 2, -7),
  121. "Vector3i min should return expected value.");
  122. CHECK_MESSAGE(
  123. vector.max(Vector3i(5, 2, 4)) == Vector3i(5, 3, 4),
  124. "Vector3i max should return expected value.");
  125. CHECK_MESSAGE(
  126. vector.snapped(Vector3i(4, 2, 5)) == Vector3i(0, 4, -5),
  127. "Vector3i snapped should work as expected.");
  128. }
  129. TEST_CASE("[Vector3i] Abs and sign methods") {
  130. const Vector3i vector1 = Vector3i(1, 3, 5);
  131. const Vector3i vector2 = Vector3i(1, -3, -5);
  132. CHECK_MESSAGE(
  133. vector1.abs() == vector1,
  134. "Vector3i abs should work as expected.");
  135. CHECK_MESSAGE(
  136. vector2.abs() == vector1,
  137. "Vector3i abs should work as expected.");
  138. CHECK_MESSAGE(
  139. vector1.sign() == Vector3i(1, 1, 1),
  140. "Vector3i sign should work as expected.");
  141. CHECK_MESSAGE(
  142. vector2.sign() == Vector3i(1, -1, -1),
  143. "Vector3i sign should work as expected.");
  144. }
  145. } // namespace TestVector3i
  146. #endif // TEST_VECTOR3I_H