12345678910111213141516171819202122232425262728293031323334353637383940 |
- #include "test/Test.h"
- Core::Test::Test(const char* name_) : tests(0), successTests(0), name(name_) {
- }
- void Core::Test::finalize() {
- if(successTests == tests) {
- LOG_DEBUG("# Tests: # / # succeeded", name, successTests, tests);
- } else {
- LOG_ERROR("# Tests: # / # succeeded", name, successTests, tests);
- }
- tests = 0;
- successTests = 0;
- }
- void Core::Test::checkEqual(float wanted, float actual, const char* text) {
- checkFloat(wanted, actual, 0.0000001f, text);
- }
- void Core::Test::checkFloat(float wanted, float actual, float error,
- const char* text) {
- tests++;
- float diff = wanted - actual;
- diff = diff < 0.0f ? -diff : diff;
- if(diff < error) {
- successTests++;
- } else {
- (void)text;
- LOG_ERROR("# Test #: # - expected '#' got '#'", name, tests, text,
- wanted, actual)
- }
- }
- void Core::Test::checkTrue(bool actual, const char* text) {
- checkEqual(true, actual, text);
- }
- void Core::Test::checkFalse(bool actual, const char* text) {
- checkEqual(false, actual, text);
- }
|