Test.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef TEST_H
  2. #define TEST_H
  3. #include "utils/Logger.h"
  4. #include "utils/StringBuffer.h"
  5. class Test final {
  6. static constexpr const char* RED = "\033[0;31m";
  7. static constexpr const char* GREEN = "\033[0;32m";
  8. static constexpr const char* RESET = "\033[0m";
  9. int tests;
  10. int successTests;
  11. const char* name;
  12. public:
  13. Test(const char* name);
  14. void finalize();
  15. template<typename T>
  16. void checkEqual(const T& wanted, const T& actual, const char* text) {
  17. if(wanted == actual) {
  18. tests++;
  19. successTests++;
  20. } else {
  21. tests++;
  22. LOG_ERROR(StringBuffer<256>(name)
  23. .append(" Test ")
  24. .append(tests)
  25. .append(": ")
  26. .append(text)
  27. .append(" - expected '")
  28. .append(wanted)
  29. .append("' got '")
  30. .append(actual)
  31. .append("'"));
  32. }
  33. }
  34. void checkEqual(float wanted, float actual, const char* text) {
  35. checkFloat(wanted, actual, 0.0000001f, text);
  36. }
  37. void checkFloat(float wanted, float actual, float error, const char* text);
  38. void checkTrue(bool actual, const char* text);
  39. void checkFalse(bool actual, const char* text);
  40. void checkUnsigned8(uint8 wanted, uint8 actual, const char* text);
  41. void checkUnsigned16(uint16 wanted, uint16 actual, const char* text);
  42. void checkSigned8(int8 wanted, int8 actual, const char* text);
  43. void checkSigned16(int16 wanted, int16 actual, const char* text);
  44. };
  45. #endif