MatrixStackTests.cpp 3.1 KB

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