ext_vector_ivec1.cpp 3.7 KB

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