#ifndef TEST_H #define TEST_H #include "utils/Logger.h" #include "utils/StringBuffer.h" class Test final { static constexpr const char* RED = "\033[0;31m"; static constexpr const char* GREEN = "\033[0;32m"; static constexpr const char* RESET = "\033[0m"; int tests; int successTests; const char* name; public: Test(const char* name); void finalize(); template void checkEqual(const T& wanted, const T& actual, const char* text) { if(wanted == actual) { tests++; successTests++; } else { tests++; LOG_ERROR(StringBuffer<256>(name) .append(" Test ") .append(tests) .append(": ") .append(text) .append(" - expected '") .append(wanted) .append("' got '") .append(actual) .append("'")); } } void checkEqual(float wanted, float actual, const char* text) { checkFloat(wanted, actual, 0.0000001f, text); } void checkFloat(float wanted, float actual, float error, const char* text); void checkTrue(bool actual, const char* text); void checkFalse(bool actual, const char* text); void checkUnsigned8(uint8 wanted, uint8 actual, const char* text); void checkUnsigned16(uint16 wanted, uint16 actual, const char* text); void checkSigned8(int8 wanted, int8 actual, const char* text); void checkSigned16(int16 wanted, int16 actual, const char* text); }; #endif