Test.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 checkFloat(float wanted, float actual, float error, const char* text);
  35. void checkTrue(bool actual, const char* text);
  36. void checkFalse(bool actual, const char* text);
  37. void checkUnsigned8(uint8 wanted, uint8 actual, const char* text);
  38. void checkUnsigned16(uint16 wanted, uint16 actual, const char* text);
  39. void checkSigned8(int8 wanted, int8 actual, const char* text);
  40. void checkSigned16(int16 wanted, int16 actual, const char* text);
  41. };
  42. #endif