|
|
@ -1,6 +1,7 @@ |
|
|
|
#include <cstddef> // size_t |
|
|
|
#include <cstddef> // size_t |
|
|
|
#include <cstdint> // uint32_t |
|
|
|
|
|
|
|
#include <cstdio> // fclose, fopen, printf, stdout |
|
|
|
#include <cstdio> // fclose, fopen, printf, stdout |
|
|
|
|
|
|
|
#include <string> |
|
|
|
|
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
|
|
#include "testsuite.h" |
|
|
|
#include "testsuite.h" |
|
|
|
#include "util/timer.h" |
|
|
|
#include "util/timer.h" |
|
|
@ -20,30 +21,55 @@ TestSuite::~TestSuite() |
|
|
|
|
|
|
|
|
|
|
|
void TestSuite::run() |
|
|
|
void TestSuite::run() |
|
|
|
{ |
|
|
|
{ |
|
|
|
printf("TestSuite: %d cases have been added!\n", (int)m_cases.size()); |
|
|
|
const char* escapePass = "\033[42;30;1m"; |
|
|
|
|
|
|
|
const char* escapeFail = "\033[41;1m"; |
|
|
|
|
|
|
|
const char* escapeGreen = "\033[32m"; |
|
|
|
|
|
|
|
const char* escapeGrey = "\033[37m"; |
|
|
|
|
|
|
|
const char* escapeRed = "\033[31m"; |
|
|
|
|
|
|
|
const char* escapeReset = "\033[0m"; |
|
|
|
|
|
|
|
|
|
|
|
size_t caseFailedCount = 0; |
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
printf("---- Running %zu Test Cases ----\n", m_cases.size()); |
|
|
|
|
|
|
|
|
|
|
|
Util::Timer totalTimer; |
|
|
|
Util::Timer totalTimer; |
|
|
|
|
|
|
|
|
|
|
|
for (auto& testCase : m_cases) { |
|
|
|
size_t caseFailedCount = 0; |
|
|
|
printf("Start %s\n", testCase.name()); |
|
|
|
for (std::vector<TestCase>::size_type i = 0; i < m_cases.size(); ++i) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf(" START %s (%zu/%zu)\n", m_cases.at(i).name(), i + 1, m_cases.size()); |
|
|
|
m_currentTestCasePassed = true; |
|
|
|
m_currentTestCasePassed = true; |
|
|
|
|
|
|
|
|
|
|
|
Util::Timer caseTimer; |
|
|
|
Util::Timer caseTimer; |
|
|
|
testCase.function()(); |
|
|
|
m_cases.at(i).function()(); |
|
|
|
printf(" %s, %luns\n", testCase.name(), caseTimer.elapsedNanoseconds()); |
|
|
|
double elapsed = caseTimer.elapsedNanoseconds(); |
|
|
|
|
|
|
|
|
|
|
|
if (!m_currentTestCasePassed) { |
|
|
|
std::string state; |
|
|
|
|
|
|
|
if (m_currentTestCasePassed) { |
|
|
|
|
|
|
|
state.append(escapePass); |
|
|
|
|
|
|
|
state.append(" PASS "); |
|
|
|
|
|
|
|
state.append(escapeReset); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
caseFailedCount++; |
|
|
|
caseFailedCount++; |
|
|
|
|
|
|
|
state.append(escapeFail); |
|
|
|
|
|
|
|
state.append(" FAIL "); |
|
|
|
|
|
|
|
state.append(escapeReset); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("%s %s %s(", state.c_str(), m_cases.at(i).name(), escapeGrey); |
|
|
|
|
|
|
|
Util::Timer::fancyPrint(elapsed); |
|
|
|
|
|
|
|
printf(")%s\n", escapeReset); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t percentagePassed = (1 - caseFailedCount / (float)m_cases.size()) * 100; |
|
|
|
printf("\n"); |
|
|
|
printf("Passed %d%% of tests\n", percentagePassed); |
|
|
|
printf("Tests: %s%zu failed%s, %s%zu passed%s, %zu total\n", |
|
|
|
|
|
|
|
escapeRed, caseFailedCount, escapeReset, |
|
|
|
|
|
|
|
escapeGreen, m_cases.size() - caseFailedCount, escapeReset, |
|
|
|
|
|
|
|
m_cases.size()); |
|
|
|
|
|
|
|
|
|
|
|
float elapsed = totalTimer.elapsedNanoseconds() / 1000000.0; |
|
|
|
printf("Time: "); |
|
|
|
printf("Elapsed: %.3f milliseconds\n", elapsed); |
|
|
|
Util::Timer::fancyPrint(totalTimer.elapsedNanoseconds()); |
|
|
|
|
|
|
|
printf("\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace Test
|
|
|
|
} // namespace Test
|
|
|
|