Browse Source

Test: Implement timer

master
Riyyi 3 years ago
parent
commit
422224bf1c
  1. 13
      test/testsuite.cpp

13
test/testsuite.cpp

@ -1,7 +1,9 @@
#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 "testsuite.h" #include "testsuite.h"
#include "util/timer.h"
namespace Test { namespace Test {
@ -22,19 +24,26 @@ void TestSuite::run()
size_t caseFailedCount = 0; size_t caseFailedCount = 0;
Util::Timer totalTimer;
for (auto& testCase : m_cases) { for (auto& testCase : m_cases) {
printf("%s\n", testCase.name()); printf("Start %s\n", testCase.name());
m_currentTestCasePassed = true; m_currentTestCasePassed = true;
Util::Timer caseTimer;
testCase.function()(); testCase.function()();
printf(" %s, %luns\n", testCase.name(), caseTimer.elapsedNanoseconds());
if (!m_currentTestCasePassed) { if (!m_currentTestCasePassed) {
caseFailedCount++; caseFailedCount++;
} }
} }
int percentagePassed = (1 - caseFailedCount / (float)m_cases.size()) * 100; uint32_t percentagePassed = (1 - caseFailedCount / (float)m_cases.size()) * 100;
printf("Passed %d%% of tests\n", percentagePassed); printf("Passed %d%% of tests\n", percentagePassed);
float elapsed = totalTimer.elapsedNanoseconds() / 1000000.0;
printf("Elapsed: %.3f milliseconds\n", elapsed);
} }
} // namespace Test } // namespace Test

Loading…
Cancel
Save