Test.cpp 752 B

123456789101112131415161718192021222324
  1. #include "Test.h"
  2. Test::Test(const char* name) : tests(0), successTests(0), name(name) {
  3. }
  4. void Test::finalize() {
  5. std::cout << ((successTests == tests) ? GREEN : RED);
  6. std::cout << name << " Tests: " << successTests << " / " << tests << " succeeded\n" << RESET;
  7. tests = 0;
  8. successTests = 0;
  9. }
  10. void Test::checkFloat(float wanted, float actual, float error, const char* text) {
  11. float diff = wanted - actual;
  12. diff = diff < 0.0f ? -diff : diff;
  13. if(diff < error) {
  14. tests++;
  15. successTests++;
  16. } else {
  17. tests++;
  18. std::cout << RED << name << " Test " << tests << ": " << text << " - " << RESET;
  19. std::cout << RED << "expected '" << wanted << "' got '" << actual << "'\n" << RESET;
  20. }
  21. }