MatrixStackTests.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #include "../Tests.hpp"
  2. #include "core/math/MatrixStack.hpp"
  3. template class Core::MatrixStack<5>;
  4. using Matrices = Core::MatrixStack<5>;
  5. static void testInit() {
  6. Core::Matrix m;
  7. Matrices stack;
  8. for(int i = 0; i < 16; i++) {
  9. CORE_TEST_FLOAT(m.getValues()[i], stack.peek().getValues()[i], 0.0f);
  10. }
  11. }
  12. static void testPop() {
  13. Matrices stack;
  14. CORE_TEST_ERROR(stack.push());
  15. stack.peek().scale(2.0f);
  16. CORE_TEST_ERROR(stack.pop());
  17. Core::Matrix m;
  18. for(int i = 0; i < 16; i++) {
  19. CORE_TEST_FLOAT(m.getValues()[i], stack.peek().getValues()[i], 0.0f);
  20. }
  21. }
  22. static void testPush(bool light) {
  23. Matrices stack;
  24. for(int i = 0; i < 4; i++) {
  25. CORE_TEST_ERROR(stack.push());
  26. }
  27. int limit = light ? 10000 : 1000000;
  28. for(int i = 0; i < limit; i++) {
  29. CORE_TEST_EQUAL(Core::Error::CAPACITY_REACHED, stack.push());
  30. }
  31. }
  32. static void testClear() {
  33. Matrices stack;
  34. stack.peek().scale(2.0f);
  35. CORE_TEST_ERROR(stack.push());
  36. stack.peek().scale(2.0f);
  37. stack.clear();
  38. Core::Matrix m;
  39. for(int i = 0; i < 16; i++) {
  40. CORE_TEST_FLOAT(m.getValues()[i], stack.peek().getValues()[i], 0.0f);
  41. }
  42. }
  43. static void testToString1() {
  44. Matrices stack;
  45. stack.peek().scale(2.0f);
  46. CORE_TEST_ERROR(stack.push());
  47. stack.peek().scale(3.0f);
  48. CORE_TEST_ERROR(stack.push());
  49. stack.peek().scale(4.0f);
  50. CORE_TEST_STRING("["
  51. "[[2.00, 0.00, 0.00, 0.00], "
  52. "[0.00, 2.00, 0.00, 0.00], "
  53. "[0.00, 0.00, 2.00, 0.00], "
  54. "[0.00, 0.00, 0.00, 1.00]], "
  55. "[[6.00, 0.00, 0.00, 0.00], "
  56. "[0.00, 6.00, 0.00, 0.00], "
  57. "[0.00, 0.00, 6.00, 0.00], "
  58. "[0.00, 0.00, 0.00, 1.00]], "
  59. "[[24.00, 0.00, 0.00, 0.00], "
  60. "[0.00, 24.00, 0.00, 0.00], "
  61. "[0.00, 0.00, 24.00, 0.00], "
  62. "[0.00, 0.00, 0.00, 1.00]]"
  63. "]",
  64. stack);
  65. }
  66. static void testToString2() {
  67. Matrices stack;
  68. stack.peek().scale(2.0f);
  69. CORE_TEST_ERROR(stack.push());
  70. stack.peek().scale(3.0f);
  71. CORE_TEST_STRING("["
  72. "[[2.00, 0.00, 0.00, 0.00], "
  73. "[0.00, 2.00, 0.00, 0.00], "
  74. "[0.00, 0.00, 2.00, 0.00], "
  75. "[0.00, 0.00, 0.00, 1.00]], "
  76. "[[6.00, 0.00, 0.00, 0.00], "
  77. "[0.00, 6.00, 0.00, 0.00], "
  78. "[0.00, 0.00, 6.00, 0.00], "
  79. "[0.00, 0.00, 0.00, 1.00]]"
  80. "]",
  81. stack);
  82. }
  83. static void testToString3() {
  84. Matrices stack;
  85. CORE_TEST_STRING("["
  86. "[[1.00, 0.00, 0.00, 0.00], "
  87. "[0.00, 1.00, 0.00, 0.00], "
  88. "[0.00, 0.00, 1.00, 0.00], "
  89. "[0.00, 0.00, 0.00, 1.00]]"
  90. "]",
  91. stack);
  92. }
  93. static void testInvalidPop() {
  94. Matrices stack;
  95. CORE_TEST_EQUAL(Core::Error::INVALID_STATE, stack.pop());
  96. }
  97. static void testConstPeek() {
  98. const Matrices stack;
  99. CORE_TEST_STRING("[[1.00, 0.00, 0.00, 0.00], "
  100. "[0.00, 1.00, 0.00, 0.00], "
  101. "[0.00, 0.00, 1.00, 0.00], "
  102. "[0.00, 0.00, 0.00, 1.00]]",
  103. stack.peek());
  104. }
  105. void Core::testMatrixStack(bool light) {
  106. testInit();
  107. testPop();
  108. testPush(light);
  109. testClear();
  110. testToString1();
  111. testToString2();
  112. testToString3();
  113. testInvalidPop();
  114. testConstPeek();
  115. }