#include "Test.h"

Test::Test(const char* name) : tests(0), successTests(0), name(name) {
}

void Test::finalize() {
    if(successTests == tests) {
        LOG_DEBUG(StringBuffer<256>(name)
                      .append(" Tests: ")
                      .append(successTests)
                      .append(" / ")
                      .append(tests)
                      .append(" succeeded"));
    } else {
        LOG_ERROR(StringBuffer<256>(name)
                      .append(" Tests: ")
                      .append(successTests)
                      .append(" / ")
                      .append(tests)
                      .append(" succeeded"));
    }
    tests = 0;
    successTests = 0;
}

void Test::checkFloat(float wanted, float actual, float error,
                      const char* text) {
    float diff = wanted - actual;
    diff = diff < 0.0f ? -diff : diff;
    if(diff < error) {
        tests++;
        successTests++;
    } else {
        tests++;
        LOG_ERROR(StringBuffer<256>(name)
                      .append(" Test ")
                      .append(tests)
                      .append(": ")
                      .append(text)
                      .append(" - expected '")
                      .append(wanted)
                      .append("' got '")
                      .append(actual)
                      .append("'"));
    }
}