Test.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "Test.h"
  2. Test::Test(const char* name) : tests(0), successTests(0), name(name) {
  3. }
  4. void Test::finalize() {
  5. if(successTests == tests) {
  6. LOG_DEBUG(StringBuffer<256>(name)
  7. .append(" Tests: ")
  8. .append(successTests)
  9. .append(" / ")
  10. .append(tests)
  11. .append(" succeeded"));
  12. } else {
  13. LOG_ERROR(StringBuffer<256>(name)
  14. .append(" Tests: ")
  15. .append(successTests)
  16. .append(" / ")
  17. .append(tests)
  18. .append(" succeeded"));
  19. }
  20. tests = 0;
  21. successTests = 0;
  22. }
  23. void Test::checkFloat(float wanted, float actual, float error,
  24. const char* text) {
  25. float diff = wanted - actual;
  26. diff = diff < 0.0f ? -diff : diff;
  27. if(diff < error) {
  28. tests++;
  29. successTests++;
  30. } else {
  31. tests++;
  32. LOG_ERROR(StringBuffer<256>(name)
  33. .append(" Test ")
  34. .append(tests)
  35. .append(": ")
  36. .append(text)
  37. .append(" - expected '")
  38. .append(wanted)
  39. .append("' got '")
  40. .append(actual)
  41. .append("'"));
  42. }
  43. }
  44. void Test::checkTrue(bool actual, const char* text) {
  45. checkEqual(true, actual, text);
  46. }
  47. void Test::checkFalse(bool actual, const char* text) {
  48. checkEqual(false, actual, text);
  49. }
  50. void Test::checkUnsigned8(uint8 wanted, uint8 actual, const char* text) {
  51. checkEqual(wanted, actual, text);
  52. }
  53. void Test::checkUnsigned16(uint16 wanted, uint16 actual, const char* text) {
  54. checkEqual(wanted, actual, text);
  55. }
  56. void Test::checkSigned8(int8 wanted, int8 actual, const char* text) {
  57. checkEqual(wanted, actual, text);
  58. }
  59. void Test::checkSigned16(int16 wanted, int16 actual, const char* text) {
  60. checkEqual(wanted, actual, text);
  61. }