/
thomas-king
/
Scanner
Обзор
Документация
Войти
/
thomas-king
/
Scanner
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
lib/UnitTests/TestSuit.cpp
74 строки
2 KB
Ace Rodstin
Replace GoogleTest with UnitTest.
02 ноя 2023, 18:07
02 ноя 2023, 18:07
8350eca
Код
Авторство
О чём код?
// // TestSuit.cpp // UnitTests // // Created by Ace Rodstin on 11/1/23. // Updated by Ace Rodstin on 11/2/23. // // Copyright © 2023 Ace Rodstin. All rights reserved. // #include "UnitTests/TestSuit.h" using namespace unit_tests; TestSuit::TestSuit(Id id, vector<TestCase> tests): id { id }, tests { tests } {} void TestSuit::run() { cout << "------- " << "Running " << id << " -------" << endl; int successes = 0; int failures = 0; int total = 0; for (auto test : tests) { setup(); test.run(); string resultMark; if (TestCase::isSuccess) { successes++; resultMark = "[V]"; } else { failures++; resultMark = "[X]"; } total++; cout << id << "." << test.getId() << " " << resultMark << endl; tearDown(); } cout << "Success: " << successes << "/" << total << " tests." << endl; cout << "Failures: " << failures << "/" << total << " tests." << endl; } void TestSuit::setup() { TestCase::isSuccess = true; } void TestSuit::tearDown() { TestCase::isSuccess = false; } void TestSuit::assertEqual(long double& lhs, long double& rhs, int precision) { int multiplier = pow(10, precision); auto _lhs = round(lhs * multiplier); auto _rhs = round(rhs * multiplier); bool isEqual = _lhs == _rhs; if (!isEqual) { cout << "Assertion failure: " << _lhs << " is not equal to " << _rhs << "." << endl; } TestCase::isSuccess &= isEqual; }