Test.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "test/Test.h"
  2. Core::Test::Test(const char* name_) : tests(0), successTests(0), name(name_) {
  3. }
  4. void Core::Test::finalize() {
  5. if(successTests == tests) {
  6. CORE_LOG_DEBUG("# Tests: # / # succeeded", name, successTests, tests);
  7. } else {
  8. CORE_LOG_ERROR("# Tests: # / # succeeded", name, successTests, tests);
  9. }
  10. tests = 0;
  11. successTests = 0;
  12. }
  13. void Core::Test::checkEqual(float wanted, float actual, const char* text) {
  14. checkFloat(wanted, actual, 0.0000001f, text);
  15. }
  16. void Core::Test::checkFloat(float wanted, float actual, float error,
  17. const char* text) {
  18. tests++;
  19. float diff = wanted - actual;
  20. diff = diff < 0.0f ? -diff : diff;
  21. if(diff < error) {
  22. successTests++;
  23. } else {
  24. (void)text;
  25. CORE_LOG_ERROR("# Test #: # - expected '#' got '#'", name, tests, text,
  26. wanted, actual)
  27. }
  28. }
  29. void Core::Test::checkTrue(bool actual, const char* text) {
  30. checkEqual(true, actual, text);
  31. }
  32. void Core::Test::checkFalse(bool actual, const char* text) {
  33. checkEqual(false, actual, text);
  34. }