MatrixStackTests.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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() {
  22. Matrices stack;
  23. for(int i = 0; i < 4; i++) {
  24. CORE_TEST_ERROR(stack.push());
  25. }
  26. for(int i = 0; i < 1000000; i++) {
  27. CORE_TEST_EQUAL(Core::Error::CAPACITY_REACHED, stack.push());
  28. }
  29. }
  30. static void testClear() {
  31. Matrices stack;
  32. stack.peek().scale(2.0f);
  33. CORE_TEST_ERROR(stack.push());
  34. stack.peek().scale(2.0f);
  35. stack.clear();
  36. Core::Matrix m;
  37. for(int i = 0; i < 16; i++) {
  38. CORE_TEST_FLOAT(m.getValues()[i], stack.peek().getValues()[i], 0.0f);
  39. }
  40. }
  41. static void testToString1() {
  42. Matrices stack;
  43. stack.peek().scale(2.0f);
  44. CORE_TEST_ERROR(stack.push());
  45. stack.peek().scale(3.0f);
  46. CORE_TEST_ERROR(stack.push());
  47. stack.peek().scale(4.0f);
  48. CORE_TEST_STRING("["
  49. "[[2.00, 0.00, 0.00, 0.00], "
  50. "[0.00, 2.00, 0.00, 0.00], "
  51. "[0.00, 0.00, 2.00, 0.00], "
  52. "[0.00, 0.00, 0.00, 1.00]], "
  53. "[[6.00, 0.00, 0.00, 0.00], "
  54. "[0.00, 6.00, 0.00, 0.00], "
  55. "[0.00, 0.00, 6.00, 0.00], "
  56. "[0.00, 0.00, 0.00, 1.00]], "
  57. "[[24.00, 0.00, 0.00, 0.00], "
  58. "[0.00, 24.00, 0.00, 0.00], "
  59. "[0.00, 0.00, 24.00, 0.00], "
  60. "[0.00, 0.00, 0.00, 1.00]]"
  61. "]",
  62. stack);
  63. }
  64. static void testToString2() {
  65. Matrices stack;
  66. stack.peek().scale(2.0f);
  67. CORE_TEST_ERROR(stack.push());
  68. stack.peek().scale(3.0f);
  69. CORE_TEST_STRING("["
  70. "[[2.00, 0.00, 0.00, 0.00], "
  71. "[0.00, 2.00, 0.00, 0.00], "
  72. "[0.00, 0.00, 2.00, 0.00], "
  73. "[0.00, 0.00, 0.00, 1.00]], "
  74. "[[6.00, 0.00, 0.00, 0.00], "
  75. "[0.00, 6.00, 0.00, 0.00], "
  76. "[0.00, 0.00, 6.00, 0.00], "
  77. "[0.00, 0.00, 0.00, 1.00]]"
  78. "]",
  79. stack);
  80. }
  81. static void testToString3() {
  82. Matrices stack;
  83. CORE_TEST_STRING("["
  84. "[[1.00, 0.00, 0.00, 0.00], "
  85. "[0.00, 1.00, 0.00, 0.00], "
  86. "[0.00, 0.00, 1.00, 0.00], "
  87. "[0.00, 0.00, 0.00, 1.00]]"
  88. "]",
  89. stack);
  90. }
  91. void Core::testMatrixStack() {
  92. testInit();
  93. testPop();
  94. testPush();
  95. testClear();
  96. testToString1();
  97. testToString2();
  98. testToString3();
  99. }