<commit_before>#include "stdafx.h"
#include "cut-detail/unit-test-manager.h"
#include "cut/testing/unit-test-group.h"
#include "cut/common.h"
#include "cut/string-format.h"

cut::IUnitTestManager* cut::IUnitTestManager::s_pInstance(nullptr);

cut::IUnitTestManager& cut::IUnitTestManager::instance()
{
	static DefaultUnitTestManager default;

	if (s_pInstance == nullptr)
	{
		s_pInstance = &default;
	}

	return *s_pInstance;
}

cut::DefaultUnitTestManager::DefaultUnitTestManager() :
	m_statistics()
{
}

cut::DefaultUnitTestManager::~DefaultUnitTestManager()
{
}

void cut::DefaultUnitTestManager::registerUnitTestGroup(IUnitTestGroup* testGroup)
{
	m_unitTestGroups.push_back(testGroup);
	++m_statistics.groups;
}

void cut::DefaultUnitTestManager::runAll()
{
	for(auto& unitTestGroup : m_unitTestGroups)
	{
		const char* unitTestGroupName = unitTestGroup->getName();
		std::size_t numberOfTests = unitTestGroup->numberOfUnitTests();

		m_statistics.tests += numberOfTests;

		logMessage(format(
			"\n"
			"Running unit test group %s with %d unit tests:\n",
			unitTestGroupName,
			numberOfTests));
		std::size_t failed = unitTestGroup->runAllTests();
		if (failed == 0)
		{
			logSuccess(format(
				"=== Unit test group passed ====================================================\n"
				"Group name: %s\n"
				"Successful unit tests: %d/%d\n"
				"===============================================================================\n",
				unitTestGroupName,
				numberOfTests - failed, numberOfTests));
		}
		else
		{
			++m_statistics.groupsFailed;
			m_statistics.testsFailed += failed;
			logFailure(format(
				"=== Unit test group failed ====================================================\n"
				"Group name: %s\n"
				"Successful unit tests: %d/%d\n"
				"===============================================================================\n",
				unitTestGroupName,
				numberOfTests - failed, numberOfTests));
		}
	}

	auto finalMessage = "\n"
		"=== Final Statistics ==========================================================\n"
		"Successful unit test groups:	 %d/%d\n"
		"Successful unit tests (total): %d/%d\n";

	if (m_statistics.testsFailed == 0)
	{
		logSuccess(format(finalMessage,
						  m_statistics.groups - m_statistics.groupsFailed, m_statistics.groups,
						  m_statistics.tests - m_statistics.testsFailed, m_statistics.tests));

		logSuccess(format("=== All Unit Tests Passed! ====================================================\n"));
	}
	else
	{
		logSuccess(format(finalMessage,
						  m_statistics.groups - m_statistics.groupsFailed, m_statistics.groups,
						  m_statistics.tests - m_statistics.testsFailed, m_statistics.tests));

		logSuccess(format("=== All or Some Unit Tests Failed! ============================================\n"));
	}
}

const cut::UnitTestStatistics& cut::DefaultUnitTestManager::statistics() const
{
	return m_statistics;
}

void cut::DefaultUnitTestManager::updateStatistics()
{<commit_msg>Fixed wrong logging mode for failure in final statistics.<commit_after>#include "stdafx.h"
#include "cut-detail/unit-test-manager.h"
#include "cut/testing/unit-test-group.h"
#include "cut/common.h"
#include "cut/string-format.h"

cut::IUnitTestManager* cut::IUnitTestManager::s_pInstance(nullptr);

cut::IUnitTestManager& cut::IUnitTestManager::instance()
{
	static DefaultUnitTestManager default;

	if (s_pInstance == nullptr)
	{
		s_pInstance = &default;
	}

	return *s_pInstance;
}

cut::DefaultUnitTestManager::DefaultUnitTestManager() :
	m_statistics()
{
}

cut::DefaultUnitTestManager::~DefaultUnitTestManager()
{
}

void cut::DefaultUnitTestManager::registerUnitTestGroup(IUnitTestGroup* testGroup)
{
	m_unitTestGroups.push_back(testGroup);
	++m_statistics.groups;
}

void cut::DefaultUnitTestManager::runAll()
{
	for(auto& unitTestGroup : m_unitTestGroups)
	{
		const char* unitTestGroupName = unitTestGroup->getName();
		std::size_t numberOfTests = unitTestGroup->numberOfUnitTests();

		m_statistics.tests += numberOfTests;

		logMessage(format(
			"\n"
			"Running unit test group %s with %d unit tests:\n",
			unitTestGroupName,
			numberOfTests));
		std::size_t failed = unitTestGroup->runAllTests();
		if (failed == 0)
		{
			logSuccess(format(
				"=== Unit test group passed ====================================================\n"
				"Group name: %s\n"
				"Successful unit tests: %d/%d\n"
				"===============================================================================\n",
				unitTestGroupName,
				numberOfTests - failed, numberOfTests));
		}
		else
		{
			++m_statistics.groupsFailed;
			m_statistics.testsFailed += failed;
			logFailure(format(
				"=== Unit test group failed ====================================================\n"
				"Group name: %s\n"
				"Successful unit tests: %d/%d\n"
				"===============================================================================\n",
				unitTestGroupName,
				numberOfTests - failed, numberOfTests));
		}
	}

	auto finalMessage = "\n"
		"=== Final Statistics ==========================================================\n"
		"Successful unit test groups:   %d/%d\n"
		"Successful unit tests (total): %d/%d\n";

	if (m_statistics.testsFailed == 0)
	{
		logSuccess(format(finalMessage,
						  m_statistics.groups - m_statistics.groupsFailed, m_statistics.groups,
						  m_statistics.tests - m_statistics.testsFailed, m_statistics.tests));

		logSuccess(format("=== All Unit Tests Passed! ====================================================\n"));
	}
	else
	{
		logFailure(format(finalMessage,
						  m_statistics.groups - m_statistics.groupsFailed, m_statistics.groups,
						  m_statistics.tests - m_statistics.testsFailed, m_statistics.tests));

		logFailure(format("=== All or Some Unit Tests Failed! ============================================\n"));
	}
}

const cut::UnitTestStatistics& cut::DefaultUnitTestManager::statistics() const
{
	return m_statistics;
}

void cut::DefaultUnitTestManager::updateStatistics()
{
{'fraction_non_alphanumeric': 0.2577770304355137, 'fraction_numerical': 0.0006726080376660501, 'mean_word_length': 5.572375690607735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6706725', 'n_tokens_mistral': 2021, 'n_tokens_neox': 1776, 'n_words': 330}