MatrixStackTests.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "tests/MatrixStackTests.h"
  2. #include "math/MatrixStack.h"
  3. #include "test/Test.h"
  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() {
  23. Matrices stack;
  24. for(int i = 0; i < 4; i++) {
  25. CORE_TEST_ERROR(stack.push());
  26. }
  27. for(int i = 0; i < 1000000; 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::MatrixStackTests::test() {
  93. testInit();
  94. testPop();
  95. testPush();
  96. testClear();
  97. testToString1();
  98. testToString2();
  99. testToString3();
  100. }