123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #include "../Tests.hpp"
- #include "core/math/MatrixStack.hpp"
- template class Core::MatrixStack<5>;
- using Matrices = Core::MatrixStack<5>;
- static void testInit() {
- Core::Matrix m;
- Matrices stack;
- for(int i = 0; i < 16; i++) {
- CORE_TEST_FLOAT(m.getValues()[i], stack.peek().getValues()[i], 0.0f);
- }
- }
- static void testPop() {
- Matrices stack;
- CORE_TEST_ERROR(stack.push());
- stack.peek().scale(2.0f);
- CORE_TEST_ERROR(stack.pop());
- Core::Matrix m;
- for(int i = 0; i < 16; i++) {
- CORE_TEST_FLOAT(m.getValues()[i], stack.peek().getValues()[i], 0.0f);
- }
- }
- static void testPush(bool light) {
- Matrices stack;
- for(int i = 0; i < 4; i++) {
- CORE_TEST_ERROR(stack.push());
- }
- int limit = light ? 10000 : 1000000;
- for(int i = 0; i < limit; i++) {
- CORE_TEST_EQUAL(Core::Error::CAPACITY_REACHED, stack.push());
- }
- }
- static void testClear() {
- Matrices stack;
- stack.peek().scale(2.0f);
- CORE_TEST_ERROR(stack.push());
- stack.peek().scale(2.0f);
- stack.clear();
- Core::Matrix m;
- for(int i = 0; i < 16; i++) {
- CORE_TEST_FLOAT(m.getValues()[i], stack.peek().getValues()[i], 0.0f);
- }
- }
- static void testToString1() {
- Matrices stack;
- stack.peek().scale(2.0f);
- CORE_TEST_ERROR(stack.push());
- stack.peek().scale(3.0f);
- CORE_TEST_ERROR(stack.push());
- stack.peek().scale(4.0f);
- CORE_TEST_STRING("["
- "[[2.00, 0.00, 0.00, 0.00], "
- "[0.00, 2.00, 0.00, 0.00], "
- "[0.00, 0.00, 2.00, 0.00], "
- "[0.00, 0.00, 0.00, 1.00]], "
- "[[6.00, 0.00, 0.00, 0.00], "
- "[0.00, 6.00, 0.00, 0.00], "
- "[0.00, 0.00, 6.00, 0.00], "
- "[0.00, 0.00, 0.00, 1.00]], "
- "[[24.00, 0.00, 0.00, 0.00], "
- "[0.00, 24.00, 0.00, 0.00], "
- "[0.00, 0.00, 24.00, 0.00], "
- "[0.00, 0.00, 0.00, 1.00]]"
- "]",
- stack);
- }
- static void testToString2() {
- Matrices stack;
- stack.peek().scale(2.0f);
- CORE_TEST_ERROR(stack.push());
- stack.peek().scale(3.0f);
- CORE_TEST_STRING("["
- "[[2.00, 0.00, 0.00, 0.00], "
- "[0.00, 2.00, 0.00, 0.00], "
- "[0.00, 0.00, 2.00, 0.00], "
- "[0.00, 0.00, 0.00, 1.00]], "
- "[[6.00, 0.00, 0.00, 0.00], "
- "[0.00, 6.00, 0.00, 0.00], "
- "[0.00, 0.00, 6.00, 0.00], "
- "[0.00, 0.00, 0.00, 1.00]]"
- "]",
- stack);
- }
- static void testToString3() {
- Matrices stack;
- CORE_TEST_STRING("["
- "[[1.00, 0.00, 0.00, 0.00], "
- "[0.00, 1.00, 0.00, 0.00], "
- "[0.00, 0.00, 1.00, 0.00], "
- "[0.00, 0.00, 0.00, 1.00]]"
- "]",
- stack);
- }
- static void testInvalidPop() {
- Matrices stack;
- CORE_TEST_EQUAL(Core::Error::INVALID_STATE, stack.pop());
- }
- static void testConstPeek() {
- const Matrices stack;
- CORE_TEST_STRING("[[1.00, 0.00, 0.00, 0.00], "
- "[0.00, 1.00, 0.00, 0.00], "
- "[0.00, 0.00, 1.00, 0.00], "
- "[0.00, 0.00, 0.00, 1.00]]",
- stack.peek());
- }
- void Core::testMatrixStack(bool light) {
- testInit();
- testPop();
- testPush(light);
- testClear();
- testToString1();
- testToString2();
- testToString3();
- testInvalidPop();
- testConstPeek();
- }
|