Skip to content

Commit

Permalink
Rename test case id -> test case name (#129)
Browse files Browse the repository at this point in the history
We will be using "test case id" instead of "test case no", to be consistent
with "subtask id" and "test group id".
  • Loading branch information
fushar committed Apr 4, 2017
1 parent c5f08b6 commit 8467e80
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 108 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ set(INCLUDE
include/tcframe/spec/testcase/SampleTestCaseData.hpp
include/tcframe/spec/testcase/TestCase.hpp
include/tcframe/spec/testcase/TestCaseData.hpp
include/tcframe/spec/testcase/TestCaseIdCreator.hpp
include/tcframe/spec/testcase/TestCaseNameCreator.hpp
include/tcframe/spec/testcase/TestGroup.hpp
include/tcframe/spec/testcase/TestSuite.hpp
include/tcframe/spec/variable.hpp
Expand Down Expand Up @@ -186,7 +186,7 @@ set(TEST_UNIT
test/unit/tcframe/spec/io/RawLineIOSegmentBuilderTests.cpp
test/unit/tcframe/spec/io/RawLinesIOSegmentBuilderTests.cpp
test/unit/tcframe/spec/random/RandomTests.cpp
test/unit/tcframe/spec/testcase/TestCaseIdCreatorTests.cpp
test/unit/tcframe/spec/testcase/TestCaseNameCreatorTests.cpp
test/unit/tcframe/spec/testcase/TestSuiteBuilderTests.cpp
test/unit/tcframe/spec/variable/MatrixTests.cpp
test/unit/tcframe/spec/variable/ScalarTests.cpp
Expand Down
16 changes: 8 additions & 8 deletions include/tcframe/generator/Generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class Generator {
}

bool combineMultipleTestCases(const TestGroup& testGroup, const GeneratorConfig& config) {
string baseId = TestCaseIdCreator::createBaseId(config.slug(), testGroup.id());
logger_->logMultipleTestCasesCombinationIntroduction(baseId);
string baseName = TestCaseNameCreator::createBaseName(config.slug(), testGroup.id());
logger_->logMultipleTestCasesCombinationIntroduction(baseName);

*config.multipleTestCasesCounter() = (int) testGroup.testCases().size();

Expand Down Expand Up @@ -109,9 +109,9 @@ class Generator {
void combine(const TestGroup& testGroup, const GeneratorConfig& config) {
int testCaseCount = (int) testGroup.testCases().size();

string baseId = TestCaseIdCreator::createBaseId(config.slug(), testGroup.id());
string baseIn = config.outputDir() + "/" + baseId + ".in";
string baseOut = config.outputDir() + "/" + baseId + ".out";
string baseName = TestCaseNameCreator::createBaseName(config.slug(), testGroup.id());
string baseIn = config.outputDir() + "/" + baseName + ".in";
string baseOut = config.outputDir() + "/" + baseName + ".out";
bool needsOutput = config.needsOutput();

ostringstream sout;
Expand All @@ -125,9 +125,9 @@ class Generator {
os_->execute(ExecutionRequestBuilder().setCommand(sout.str()).build());

for (int i = 1; i <= testCaseCount; i++) {
string id = TestCaseIdCreator::create(config.slug(), testGroup.id(), i);
string in = config.outputDir() + "/" + id + ".in";
string out = config.outputDir() + "/" + id + ".out";
string name = TestCaseNameCreator::create(config.slug(), testGroup.id(), i);
string in = config.outputDir() + "/" + name + ".in";
string out = config.outputDir() + "/" + name + ".out";

ostringstream sout2;
sout2 << "tail -n +2 " << in << " >> " << baseIn;
Expand Down
4 changes: 2 additions & 2 deletions include/tcframe/generator/GeneratorLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class GeneratorLogger : public BaseLogger {
engine_->logParagraph(2, "Reasons:");
}

virtual void logMultipleTestCasesCombinationIntroduction(const string& testCaseBaseId) {
engine_->logHangingParagraph(1, "Combining test cases into a single file (" + testCaseBaseId + "): ");
virtual void logMultipleTestCasesCombinationIntroduction(const string& testCaseBaseName) {
engine_->logHangingParagraph(1, "Combining test cases into a single file (" + testCaseBaseName + "): ");
}

virtual void logMultipleTestCasesCombinationSuccessfulResult() {
Expand Down
10 changes: 5 additions & 5 deletions include/tcframe/generator/TestCaseGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class TestCaseGenerator {
, logger_(logger) {}

virtual bool generate(const TestCase& testCase, const GeneratorConfig& config) {
logger_->logTestCaseIntroduction(testCase.id());
logger_->logTestCaseIntroduction(testCase.name());

string inputFilename = config.outputDir() + "/" + testCase.id() + ".in";
string outputFilename = config.outputDir() + "/" + testCase.id() + ".out";
string inputFilename = config.outputDir() + "/" + testCase.name() + ".in";
string outputFilename = config.outputDir() + "/" + testCase.name() + ".out";

try {
applyInput(testCase);
Expand Down Expand Up @@ -153,8 +153,8 @@ class TestCaseGenerator {

void modifyInputForMultipleTestCases(ostream* input, const GeneratorConfig& config) {
if (config.multipleTestCasesCounter() != nullptr) {
int testCaseNo = 1;
*input << testCaseNo << endl;
int testCaseId = 1;
*input << testCaseId << endl;
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/tcframe/grader/Grader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Grader {

if (config.hasMultipleTestCases()) {
TestCase testCase = TestCaseBuilder()
.setId(TestCaseIdCreator::createBaseId(config.slug(), testGroup.id()))
.setName(TestCaseNameCreator::createBaseName(config.slug(), testGroup.id()))
.setSubtaskIds(testGroup.testCases()[0].subtaskIds())
.build();
gradeOnTestCase(testCase, config, subtaskVerdicts);
Expand Down
8 changes: 4 additions & 4 deletions include/tcframe/grader/TestCaseGrader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TestCaseGrader {
, logger_(logger) {}

virtual TestCaseGrade grade(const TestCase& testCase, const GraderConfig& config) {
logger_->logTestCaseIntroduction(testCase.id());
logger_->logTestCaseIntroduction(testCase.name());

TestCaseGradeCreator gradeCreator;

Expand All @@ -51,7 +51,7 @@ class TestCaseGrader {

private:
EvaluationResult evaluate(const TestCase& testCase, const GraderConfig& config) {
string inputFilename = config.outputDir() + "/" + testCase.id() + ".in";
string inputFilename = config.outputDir() + "/" + testCase.name() + ".in";
EvaluatorConfig evaluatorConfig = EvaluatorConfigBuilder()
.setSolutionCommand(config.solutionCommand())
.setTimeLimit(config.timeLimit())
Expand All @@ -62,8 +62,8 @@ class TestCaseGrader {
}

ScoringResult score(const TestCase& testCase, const GraderConfig& config) {
string inputFilename = config.outputDir() + "/" + testCase.id() + ".in";
string outputFilename = config.outputDir() + "/" + testCase.id() + ".out";
string inputFilename = config.outputDir() + "/" + testCase.name() + ".in";
string outputFilename = config.outputDir() + "/" + testCase.name() + ".out";

return scorer_->score(inputFilename, outputFilename, Evaluator::EVALUATION_FILENAME);
}
Expand Down
4 changes: 2 additions & 2 deletions include/tcframe/logger/BaseLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class BaseLogger {
}
}

virtual void logTestCaseIntroduction(string testCaseId) {
engine_->logHangingParagraph(1, testCaseId + ": ");
virtual void logTestCaseIntroduction(string testCaseName) {
engine_->logHangingParagraph(1, testCaseName + ": ");
}

virtual void logTestCaseGradeDetails(const TestCaseGrade& grade) {
Expand Down
2 changes: 1 addition & 1 deletion include/tcframe/spec/testcase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#include "tcframe/spec/testcase/SampleTestCaseData.hpp"
#include "tcframe/spec/testcase/TestCase.hpp"
#include "tcframe/spec/testcase/TestCaseData.hpp"
#include "tcframe/spec/testcase/TestCaseIdCreator.hpp"
#include "tcframe/spec/testcase/TestCaseNameCreator.hpp"
#include "tcframe/spec/testcase/TestGroup.hpp"
#include "tcframe/spec/testcase/TestSuite.hpp"
12 changes: 6 additions & 6 deletions include/tcframe/spec/testcase/TestCase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ struct TestCase {
friend class TestCaseBuilder;

private:
string id_;
string name_;
optional<string> description_;
set<int> subtaskIds_;
TestCaseData* data_;

public:
const string& id() const {
return id_;
const string& name() const {
return name_;
}

const optional<string>& description() const {
Expand All @@ -41,7 +41,7 @@ struct TestCase {
}

bool operator==(const TestCase& o) const {
if (tie(id_, description_, subtaskIds_) != tie(o.id_, o.description_, o.subtaskIds_)) {
if (tie(name_, description_, subtaskIds_) != tie(o.name_, o.description_, o.subtaskIds_)) {
return false;
}
if ((data_ == nullptr) != (o.data_ == nullptr)) {
Expand All @@ -56,8 +56,8 @@ class TestCaseBuilder {
TestCase subject_;

public:
TestCaseBuilder& setId(string id) {
subject_.id_ = id;
TestCaseBuilder& setName(string name) {
subject_.name_ = name;
return *this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ using std::string;

namespace tcframe {

class TestCaseIdCreator {
class TestCaseNameCreator {
public:
TestCaseIdCreator() = delete;
TestCaseNameCreator() = delete;

static string create(const string& slug, int testGroupId, int testCaseNo) {
return createBaseId(slug, testGroupId) + "_" + StringUtils::toString(testCaseNo);
static string create(const string& slug, int testGroupId, int testCaseId) {
return createBaseName(slug, testGroupId) + "_" + StringUtils::toString(testCaseId);
}

static string createBaseId(const string& slug, int testGroupId) {
static string createBaseName(const string& slug, int testGroupId) {
if (testGroupId == 0) {
return slug + "_sample";
}
Expand Down
15 changes: 9 additions & 6 deletions include/tcframe/spec/testcase/TestSuite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "OfficialTestCaseData.hpp"
#include "SampleTestCaseData.hpp"
#include "TestCase.hpp"
#include "TestCaseIdCreator.hpp"
#include "TestCaseNameCreator.hpp"
#include "TestGroup.hpp"
#include "tcframe/util.hpp"

Expand Down Expand Up @@ -117,7 +117,7 @@ class TestSuiteBuilder {

TestSuiteBuilder& newTestGroup() {
if (hasCurOfficialTestGroup_) {
addCurrentOfficialTestCase();
addCurrentOfficialTestGroup();
} else {
curOfficialTestGroupId_ = 0;
}
Expand Down Expand Up @@ -165,7 +165,10 @@ class TestSuiteBuilder {
// https://bugs.archlinux.org/task/35803

curOfficialTestCases_.push_back(TestCaseBuilder()
.setId(TestCaseIdCreator::create(slug_, curOfficialTestGroupId_, (int) curOfficialTestCases_.size() + 1))
.setName(TestCaseNameCreator::create(
slug_,
curOfficialTestGroupId_,
(int) curOfficialTestCases_.size() + 1))
.setSubtaskIds(curOfficialSubtaskIds_)
.setDescription(description)
.setData(new OfficialTestCaseData([=]{
Expand All @@ -182,7 +185,7 @@ class TestSuiteBuilder {
addCurrentSampleTestCase();
}
if (!curOfficialTestCases_.empty()) {
addCurrentOfficialTestCase();
addCurrentOfficialTestGroup();
}

vector<TestGroup> testGroups;
Expand Down Expand Up @@ -218,13 +221,13 @@ class TestSuiteBuilder {
}

curSampleTestCases_.push_back(TestCaseBuilder()
.setId(TestCaseIdCreator::create(slug_, 0, (int) curSampleTestCases_.size() + 1))
.setName(TestCaseNameCreator::create(slug_, 0, (int) curSampleTestCases_.size() + 1))
.setSubtaskIds(curSampleSubtaskIds_)
.setData(data)
.build());
}

void addCurrentOfficialTestCase() {
void addCurrentOfficialTestGroup() {
curOfficialTestGroups_.push_back(TestGroup(curOfficialTestGroupId_, curOfficialTestCases_));
}
};
Expand Down
8 changes: 4 additions & 4 deletions test/unit/tcframe/generator/TestCaseGeneratorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ class TestCaseGeneratorTests : public Test {
MOCK(GeneratorLogger) logger;

TestCase sampleTestCase = TestCaseBuilder()
.setId("foo_sample_1")
.setName("foo_sample_1")
.setSubtaskIds({1, 2})
.setData(new SampleTestCaseData("42\n"))
.build();
TestCase sampleTestCaseWithOutput = TestCaseBuilder()
.setId("foo_sample_1")
.setName("foo_sample_1")
.setSubtaskIds({1, 2})
.setData(new SampleTestCaseData("42\n", "yes\n"))
.build();
TestCase officialTestCase = TestCaseBuilder()
.setId("foo_1")
.setName("foo_1")
.setDescription("N = 42")
.setSubtaskIds({1, 2})
.setData(new OfficialTestCaseData([&]{N = 42;}))
.build();
TestCase officialTestCaseWithInvalidClosure = TestCaseBuilder()
.setId("foo_1")
.setName("foo_1")
.setDescription("N = 42")
.setSubtaskIds({1, 2})
.setData(new OfficialTestCaseData([&]{throw runtime_error("closure error");}))
Expand Down
6 changes: 3 additions & 3 deletions test/unit/tcframe/grader/GraderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class GraderTests : public Test {
void SetUp() {
ON_CALL(testCaseGrader, grade(_, _))
.WillByDefault(Return(TestCaseGradeBuilder().setVerdict(Verdict::ac()).build()));
ON_CALL(testCaseGrader, grade(Property(&TestCase::id, StartsWith("foo_2")), _))
ON_CALL(testCaseGrader, grade(Property(&TestCase::name, StartsWith("foo_2")), _))
.WillByDefault(Return(TestCaseGradeBuilder().setVerdict(Verdict::rte()).build()));
ON_CALL(testCaseGrader, grade(Property(&TestCase::id, StartsWith("foo_3")), _))
ON_CALL(testCaseGrader, grade(Property(&TestCase::name, StartsWith("foo_3")), _))
.WillByDefault(Return(TestCaseGradeBuilder().setVerdict(Verdict::wa()).build()));
ON_CALL(testCaseGrader, grade(Property(&TestCase::id, StartsWith("foo_4")), _))
ON_CALL(testCaseGrader, grade(Property(&TestCase::name, StartsWith("foo_4")), _))
.WillByDefault(Return(TestCaseGradeBuilder().setVerdict(Verdict::tle()).build()));
}
};
Expand Down
2 changes: 1 addition & 1 deletion test/unit/tcframe/grader/TestCaseGraderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestCaseGraderTests : public Test {
MOCK(Scorer) scorer;
MOCK(GraderLogger) logger;

TestCase testCase = TestCaseBuilder().setId("foo_1").build();
TestCase testCase = TestCaseBuilder().setName("foo_1").build();

GraderConfig config = GraderConfigBuilder("foo")
.setSolutionCommand("python Sol.py")
Expand Down
36 changes: 0 additions & 36 deletions test/unit/tcframe/spec/testcase/TestCaseIdCreatorTests.cpp

This file was deleted.

36 changes: 36 additions & 0 deletions test/unit/tcframe/spec/testcase/TestCaseNameCreatorTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "gmock/gmock.h"

#include "tcframe/spec/testcase/TestCaseNameCreator.hpp"

using ::testing::Eq;
using ::testing::Test;

namespace tcframe {

class TestCaseNameCreatorTests : public Test {};

TEST_F(TestCaseNameCreatorTests, Creation_Sample) {
EXPECT_THAT(TestCaseNameCreator::create("foo", 0, 42), Eq("foo_sample_42"));
}

TEST_F(TestCaseNameCreatorTests, Creation_Sample_Base) {
EXPECT_THAT(TestCaseNameCreator::createBaseName("foo", 0), Eq("foo_sample"));
}

TEST_F(TestCaseNameCreatorTests, Creation_Official) {
EXPECT_THAT(TestCaseNameCreator::create("foo", -1, 42), Eq("foo_42"));
}

TEST_F(TestCaseNameCreatorTests, Creation_Official_Base) {
EXPECT_THAT(TestCaseNameCreator::createBaseName("foo", -1), Eq("foo"));
}

TEST_F(TestCaseNameCreatorTests, Creation_Official_WithGroups) {
EXPECT_THAT(TestCaseNameCreator::create("foo", 7, 42), Eq("foo_7_42"));
}

TEST_F(TestCaseNameCreatorTests, Creation_Official_WithGroups_Base) {
EXPECT_THAT(TestCaseNameCreator::createBaseName("foo", 7), Eq("foo_7"));
}

}

0 comments on commit 8467e80

Please sign in to comment.