-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Extract interfaces from *Logger
- Loading branch information
Showing
17 changed files
with
282 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "GeneratorLogger.hpp" | ||
#include "tcframe/logger.hpp" | ||
#include "tcframe/spec/constraint.hpp" | ||
#include "tcframe/util.hpp" | ||
#include "tcframe/verifier.hpp" | ||
|
||
using std::string; | ||
using std::vector; | ||
|
||
namespace tcframe { | ||
|
||
class DefaultGeneratorLogger : public GeneratorLogger, public DefaultBaseLogger { | ||
public: | ||
virtual ~DefaultGeneratorLogger() {} | ||
|
||
DefaultGeneratorLogger(LoggerEngine* engine) | ||
: DefaultBaseLogger(engine) {} | ||
|
||
virtual void logIntroduction() { | ||
engine_->logParagraph(0, "Generating test cases..."); | ||
} | ||
|
||
virtual void logSuccessfulResult() { | ||
engine_->logParagraph(0, ""); | ||
engine_->logParagraph(0, "Generation finished. All test cases OK."); | ||
} | ||
|
||
virtual void logFailedResult() { | ||
engine_->logParagraph(0, ""); | ||
engine_->logParagraph(0, "Generation finished. Some test cases FAILED."); | ||
} | ||
|
||
virtual void logTestCaseSuccessfulResult() { | ||
engine_->logParagraph(0, "OK"); | ||
} | ||
|
||
virtual void logTestCaseFailedResult(const optional<string>& testCaseDescription) { | ||
engine_->logParagraph(0, "FAILED"); | ||
if (testCaseDescription) { | ||
engine_->logParagraph(2, "Description: " + testCaseDescription.value()); | ||
} | ||
engine_->logParagraph(2, "Reasons:"); | ||
} | ||
|
||
virtual void logMultipleTestCasesCombinationIntroduction(const string& testGroupName) { | ||
engine_->logHangingParagraph(1, "Combining test cases into a single file (" + testGroupName + "): "); | ||
} | ||
|
||
virtual void logMultipleTestCasesCombinationSuccessfulResult() { | ||
engine_->logParagraph(0, "OK"); | ||
} | ||
|
||
virtual void logMultipleTestCasesCombinationFailedResult() { | ||
engine_->logParagraph(0, "FAILED"); | ||
engine_->logParagraph(2, "Reasons:"); | ||
} | ||
|
||
virtual void logConstraintsVerificationFailure(const ConstraintsVerificationResult& result) { | ||
for (const auto& entry : result.unsatisfiedConstraintDescriptionsBySubtaskId()) { | ||
int subtaskId = entry.first; | ||
const vector<string>& unsatisfiedConstraintDescriptions = entry.second; | ||
|
||
if (subtaskId == Subtask::MAIN_ID) { | ||
engine_->logListItem1(2, "Does not satisfy constraints, on:"); | ||
} else { | ||
engine_->logListItem1(2, "Does not satisfy subtask " + StringUtils::toString(subtaskId) + ", on constraints:"); | ||
} | ||
|
||
for (const string& unsatisfiedConstraintDescription : unsatisfiedConstraintDescriptions) { | ||
engine_->logListItem2(3, unsatisfiedConstraintDescription); | ||
} | ||
} | ||
for (int subtaskId : result.satisfiedButNotAssignedSubtaskIds()) { | ||
engine_->logListItem1(2, "Satisfies subtask " + StringUtils::toString(subtaskId) + " but is not assigned to it"); | ||
} | ||
} | ||
|
||
virtual void logMultipleTestCasesConstraintsVerificationFailure( | ||
const MultipleTestCasesConstraintsVerificationResult& result) { | ||
|
||
engine_->logListItem1(2, "Does not satisfy constraints, on:"); | ||
|
||
for (const string& unsatisfiedConstraintDescription : result.unsatisfiedConstraintDescriptions()) { | ||
engine_->logListItem2(3, unsatisfiedConstraintDescription); | ||
} | ||
} | ||
|
||
virtual void logSampleTestCaseCheckFailure() { | ||
engine_->logListItem1(2, "Sample test case output does not match with actual output produced by the solution"); | ||
} | ||
|
||
virtual void logSampleTestCaseNoOutputNeededFailure() { | ||
engine_->logListItem1(2, "Problem does not need test case outputs, but this sample test case has output"); | ||
} | ||
|
||
virtual void logSimpleFailure(const string& message) { | ||
engine_->logListItem1(2, message); | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,34 @@ | ||
#pragma once | ||
|
||
#include <cstring> | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "tcframe/logger.hpp" | ||
#include "tcframe/spec/constraint.hpp" | ||
#include "tcframe/util.hpp" | ||
#include "tcframe/verifier.hpp" | ||
|
||
using std::string; | ||
using std::vector; | ||
|
||
namespace tcframe { | ||
|
||
class GeneratorLogger : public BaseLogger { | ||
class GeneratorLogger : public virtual BaseLogger { | ||
public: | ||
virtual ~GeneratorLogger() {} | ||
|
||
GeneratorLogger(LoggerEngine* engine) | ||
: BaseLogger(engine) {} | ||
|
||
virtual void logIntroduction() { | ||
engine_->logParagraph(0, "Generating test cases..."); | ||
} | ||
|
||
virtual void logSuccessfulResult() { | ||
engine_->logParagraph(0, ""); | ||
engine_->logParagraph(0, "Generation finished. All test cases OK."); | ||
} | ||
|
||
virtual void logFailedResult() { | ||
engine_->logParagraph(0, ""); | ||
engine_->logParagraph(0, "Generation finished. Some test cases FAILED."); | ||
} | ||
|
||
virtual void logTestCaseSuccessfulResult() { | ||
engine_->logParagraph(0, "OK"); | ||
} | ||
|
||
virtual void logTestCaseFailedResult(const optional<string>& testCaseDescription) { | ||
engine_->logParagraph(0, "FAILED"); | ||
if (testCaseDescription) { | ||
engine_->logParagraph(2, "Description: " + testCaseDescription.value()); | ||
} | ||
engine_->logParagraph(2, "Reasons:"); | ||
} | ||
|
||
virtual void logMultipleTestCasesCombinationIntroduction(const string& testGroupName) { | ||
engine_->logHangingParagraph(1, "Combining test cases into a single file (" + testGroupName + "): "); | ||
} | ||
|
||
virtual void logMultipleTestCasesCombinationSuccessfulResult() { | ||
engine_->logParagraph(0, "OK"); | ||
} | ||
|
||
virtual void logMultipleTestCasesCombinationFailedResult() { | ||
engine_->logParagraph(0, "FAILED"); | ||
engine_->logParagraph(2, "Reasons:"); | ||
} | ||
|
||
virtual void logConstraintsVerificationFailure(const ConstraintsVerificationResult& result) { | ||
for (const auto& entry : result.unsatisfiedConstraintDescriptionsBySubtaskId()) { | ||
int subtaskId = entry.first; | ||
const vector<string>& unsatisfiedConstraintDescriptions = entry.second; | ||
|
||
if (subtaskId == Subtask::MAIN_ID) { | ||
engine_->logListItem1(2, "Does not satisfy constraints, on:"); | ||
} else { | ||
engine_->logListItem1(2, "Does not satisfy subtask " + StringUtils::toString(subtaskId) + ", on constraints:"); | ||
} | ||
|
||
for (const string& unsatisfiedConstraintDescription : unsatisfiedConstraintDescriptions) { | ||
engine_->logListItem2(3, unsatisfiedConstraintDescription); | ||
} | ||
} | ||
for (int subtaskId : result.satisfiedButNotAssignedSubtaskIds()) { | ||
engine_->logListItem1(2, "Satisfies subtask " + StringUtils::toString(subtaskId) + " but is not assigned to it"); | ||
} | ||
} | ||
|
||
virtual void logIntroduction() = 0; | ||
virtual void logSuccessfulResult() = 0; | ||
virtual void logFailedResult() = 0; | ||
virtual void logTestCaseSuccessfulResult() = 0; | ||
virtual void logTestCaseFailedResult(const optional<string>& testCaseDescription) = 0; | ||
virtual void logMultipleTestCasesCombinationIntroduction(const string& testGroupName) = 0; | ||
virtual void logMultipleTestCasesCombinationSuccessfulResult() = 0; | ||
virtual void logMultipleTestCasesCombinationFailedResult() = 0; | ||
virtual void logConstraintsVerificationFailure(const ConstraintsVerificationResult& result) = 0; | ||
virtual void logMultipleTestCasesConstraintsVerificationFailure( | ||
const MultipleTestCasesConstraintsVerificationResult& result) { | ||
|
||
engine_->logListItem1(2, "Does not satisfy constraints, on:"); | ||
|
||
for (const string& unsatisfiedConstraintDescription : result.unsatisfiedConstraintDescriptions()) { | ||
engine_->logListItem2(3, unsatisfiedConstraintDescription); | ||
} | ||
} | ||
|
||
virtual void logSampleTestCaseCheckFailure() { | ||
engine_->logListItem1(2, "Sample test case output does not match with actual output produced by the solution"); | ||
} | ||
|
||
virtual void logSampleTestCaseNoOutputNeededFailure() { | ||
engine_->logListItem1(2, "Problem does not need test case outputs, but this sample test case has output"); | ||
} | ||
|
||
virtual void logSimpleFailure(const string& message) { | ||
engine_->logListItem1(2, message); | ||
} | ||
const MultipleTestCasesConstraintsVerificationResult& result) = 0; | ||
virtual void logSampleTestCaseCheckFailure() = 0; | ||
virtual void logSampleTestCaseNoOutputNeededFailure() = 0; | ||
virtual void logSimpleFailure(const string& message) = 0; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
|
||
#include "GraderLogger.hpp" | ||
#include "tcframe/logger.hpp" | ||
#include "tcframe/util.hpp" | ||
#include "tcframe/verdict.hpp" | ||
|
||
using std::map; | ||
|
||
namespace tcframe { | ||
|
||
class DefaultGraderLogger : public GraderLogger, public DefaultBaseLogger { | ||
public: | ||
virtual ~DefaultGraderLogger() {} | ||
|
||
DefaultGraderLogger(LoggerEngine* engine) | ||
: DefaultBaseLogger(engine) {} | ||
|
||
virtual void logIntroduction(const string& solutionCommand) { | ||
engine_->logParagraph(0, "Local grading with solution command: '" + solutionCommand + "'..."); | ||
} | ||
|
||
virtual void logTestCaseVerdict(const Verdict& verdict) { | ||
engine_->logParagraph(0, verdict.toString()); | ||
} | ||
|
||
virtual void logResult(const map<int, Verdict>& subtaskVerdicts, const Verdict& verdict) { | ||
if (subtaskVerdicts.size() > 1) { | ||
engine_->logHeading("SUBTASK VERDICTS"); | ||
for (auto entry : subtaskVerdicts) { | ||
engine_->logParagraph( | ||
1, | ||
"Subtask " + StringUtils::toString(entry.first) + ": " + entry.second.toString()); | ||
} | ||
} | ||
|
||
engine_->logHeading("VERDICT"); | ||
engine_->logParagraph(1, verdict.toString()); | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#pragma once | ||
|
||
#include "tcframe/logger/BaseLogger.hpp" | ||
#include "tcframe/logger/DefaultBaseLogger.hpp" | ||
#include "tcframe/logger/LoggerEngine.hpp" | ||
#include "tcframe/logger/SimpleLoggerEngine.hpp" |
Oops, something went wrong.