ext_vector_integer.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #include <glm/ext/vector_integer.hpp>
  2. #include <glm/ext/vector_int1.hpp>
  3. #include <glm/ext/vector_int2.hpp>
  4. #include <glm/ext/vector_int3.hpp>
  5. #include <glm/ext/vector_int4.hpp>
  6. #include <glm/ext/vector_uint1.hpp>
  7. #include <glm/ext/vector_uint2.hpp>
  8. #include <glm/ext/vector_uint3.hpp>
  9. #include <glm/ext/vector_uint4.hpp>
  10. #include <glm/vector_relational.hpp>
  11. template <typename genType>
  12. static int test_operators()
  13. {
  14. int Error = 0;
  15. {
  16. genType const A(1);
  17. genType const B(1);
  18. bool const R = A != B;
  19. bool const S = A == B;
  20. Error += (S && !R) ? 0 : 1;
  21. }
  22. {
  23. genType const A(1);
  24. genType const B(1);
  25. genType const C = A + B;
  26. Error += C == genType(2) ? 0 : 1;
  27. genType const D = A - B;
  28. Error += D == genType(0) ? 0 : 1;
  29. genType const E = A * B;
  30. Error += E == genType(1) ? 0 : 1;
  31. genType const F = A / B;
  32. Error += F == genType(1) ? 0 : 1;
  33. }
  34. {
  35. genType const A(3);
  36. genType const B(2);
  37. genType const C = A % B;
  38. Error += C == genType(1) ? 0 : 1;
  39. }
  40. {
  41. genType const A(1);
  42. genType const B(1);
  43. genType const C(0);
  44. genType const I = A & B;
  45. Error += I == genType(1) ? 0 : 1;
  46. genType const D = A & C;
  47. Error += D == genType(0) ? 0 : 1;
  48. genType const E = A | B;
  49. Error += E == genType(1) ? 0 : 1;
  50. genType const F = A | C;
  51. Error += F == genType(1) ? 0 : 1;
  52. genType const G = A ^ B;
  53. Error += G == genType(0) ? 0 : 1;
  54. genType const H = A ^ C;
  55. Error += H == genType(1) ? 0 : 1;
  56. }
  57. {
  58. genType const A(0);
  59. genType const B(1);
  60. genType const C(2);
  61. genType const D = B << B;
  62. Error += D == genType(2) ? 0 : 1;
  63. genType const E = C >> B;
  64. Error += E == genType(1) ? 0 : 1;
  65. }
  66. return Error;
  67. }
  68. template <typename genType>
  69. static int test_ctor()
  70. {
  71. typedef typename genType::value_type T;
  72. int Error = 0;
  73. genType const A = genType(1);
  74. genType const E(genType(1));
  75. Error += A == E ? 0 : 1;
  76. genType const F(E);
  77. Error += A == F ? 0 : 1;
  78. genType const B = genType(1);
  79. genType const G(glm::vec<2, T>(1));
  80. Error += B == G ? 0 : 1;
  81. genType const H(glm::vec<3, T>(1));
  82. Error += B == H ? 0 : 1;
  83. genType const I(glm::vec<4, T>(1));
  84. Error += B == I ? 0 : 1;
  85. return Error;
  86. }
  87. template <typename genType>
  88. static int test_size()
  89. {
  90. int Error = 0;
  91. Error += sizeof(typename genType::value_type) == sizeof(genType) ? 0 : 1;
  92. Error += genType().length() == 1 ? 0 : 1;
  93. Error += genType::length() == 1 ? 0 : 1;
  94. return Error;
  95. }
  96. template <typename genType>
  97. static int test_relational()
  98. {
  99. int Error = 0;
  100. genType const A(1);
  101. genType const B(1);
  102. genType const C(0);
  103. Error += A == B ? 0 : 1;
  104. Error += A != C ? 0 : 1;
  105. Error += all(equal(A, B)) ? 0 : 1;
  106. Error += any(notEqual(A, C)) ? 0 : 1;
  107. return Error;
  108. }
  109. template <typename genType>
  110. static int test_constexpr()
  111. {
  112. # if GLM_CONFIG_CONSTEXP == GLM_ENABLE
  113. static_assert(genType::length() == 1, "GLM: Failed constexpr");
  114. static_assert(genType(1)[0] == 1, "GLM: Failed constexpr");
  115. static_assert(genType(1) == genType(1), "GLM: Failed constexpr");
  116. static_assert(genType(1) != genType(0), "GLM: Failed constexpr");
  117. # endif
  118. return 0;
  119. }
  120. int main()
  121. {
  122. int Error = 0;
  123. Error += test_operators<glm::ivec1>();
  124. Error += test_operators<glm::lowp_ivec1>();
  125. Error += test_operators<glm::mediump_ivec1>();
  126. Error += test_operators<glm::highp_ivec1>();
  127. Error += test_ctor<glm::ivec1>();
  128. Error += test_ctor<glm::lowp_ivec1>();
  129. Error += test_ctor<glm::mediump_ivec1>();
  130. Error += test_ctor<glm::highp_ivec1>();
  131. Error += test_size<glm::ivec1>();
  132. Error += test_size<glm::lowp_ivec1>();
  133. Error += test_size<glm::mediump_ivec1>();
  134. Error += test_size<glm::highp_ivec1>();
  135. Error += test_relational<glm::ivec1>();
  136. Error += test_relational<glm::lowp_ivec1>();
  137. Error += test_relational<glm::mediump_ivec1>();
  138. Error += test_relational<glm::highp_ivec1>();
  139. Error += test_constexpr<glm::ivec1>();
  140. Error += test_constexpr<glm::lowp_ivec1>();
  141. Error += test_constexpr<glm::mediump_ivec1>();
  142. Error += test_constexpr<glm::highp_ivec1>();
  143. Error += test_operators<glm::uvec1>();
  144. Error += test_operators<glm::lowp_uvec1>();
  145. Error += test_operators<glm::mediump_uvec1>();
  146. Error += test_operators<glm::highp_uvec1>();
  147. Error += test_ctor<glm::uvec1>();
  148. Error += test_ctor<glm::lowp_uvec1>();
  149. Error += test_ctor<glm::mediump_uvec1>();
  150. Error += test_ctor<glm::highp_uvec1>();
  151. Error += test_size<glm::uvec1>();
  152. Error += test_size<glm::lowp_uvec1>();
  153. Error += test_size<glm::mediump_uvec1>();
  154. Error += test_size<glm::highp_uvec1>();
  155. Error += test_relational<glm::uvec1>();
  156. Error += test_relational<glm::lowp_uvec1>();
  157. Error += test_relational<glm::mediump_uvec1>();
  158. Error += test_relational<glm::highp_uvec1>();
  159. Error += test_constexpr<glm::uvec1>();
  160. Error += test_constexpr<glm::lowp_uvec1>();
  161. Error += test_constexpr<glm::mediump_uvec1>();
  162. Error += test_constexpr<glm::highp_uvec1>();
  163. return Error;
  164. }