Skip to content

Commit

Permalink
Move multiple test cases config as separated config
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Nov 12, 2016
1 parent ee94f91 commit 09c17e0
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 121 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ set(SOURCES
include/tcframe/spec/core/DefaultValues.hpp
include/tcframe/spec/core/GradingConfig.hpp
include/tcframe/spec/core/Magic.hpp
include/tcframe/spec/core/ProblemConfig.hpp
include/tcframe/spec/core/MultipleTestCasesConfig.hpp
include/tcframe/spec/io.hpp
include/tcframe/spec/io/GridIOSegment.hpp
include/tcframe/spec/io/IOFormat.hpp
Expand Down
4 changes: 2 additions & 2 deletions ete-test/resources/multi/multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class ProblemSpec : public BaseProblemSpec {
LINE(res);
}

void Config() {
MultipleTestCasesCount(T);
void MultipleTestCasesConfig() {
Counter(T);
}

void MultipleTestCasesConstraints() {
Expand Down
14 changes: 7 additions & 7 deletions include/tcframe/generator/GeneratorConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ struct GeneratorConfig {
friend class GeneratorConfigBuilder;

private:
int* multipleTestCasesCount_;
int* multipleTestCasesCounter_;
unsigned seed_;
string slug_;
string solutionCommand_;
string outputDir_;

public:
int* multipleTestCasesCount() const {
return multipleTestCasesCount_;
return multipleTestCasesCounter_;
}

unsigned int seed() const {
Expand All @@ -45,8 +45,8 @@ struct GeneratorConfig {
}

bool operator==(const GeneratorConfig& o) const {
return tie(multipleTestCasesCount_, seed_, slug_, solutionCommand_, outputDir_) ==
tie(o.multipleTestCasesCount_, o.seed_, o.slug_, o.solutionCommand_, o.outputDir_);
return tie(multipleTestCasesCounter_, seed_, slug_, solutionCommand_, outputDir_) ==
tie(o.multipleTestCasesCounter_, o.seed_, o.slug_, o.solutionCommand_, o.outputDir_);
}
};

Expand All @@ -59,14 +59,14 @@ class GeneratorConfigBuilder {
: subject_(from) {}

GeneratorConfigBuilder() {
subject_.multipleTestCasesCount_ = nullptr;
subject_.multipleTestCasesCounter_ = nullptr;
subject_.seed_ = DefaultValues::seed();
subject_.solutionCommand_ = DefaultValues::solutionCommand();
subject_.outputDir_ = DefaultValues::outputDir();
}

GeneratorConfigBuilder& setMultipleTestCasesCount(int* var) {
subject_.multipleTestCasesCount_ = var;
GeneratorConfigBuilder& setMultipleTestCasesCounter(int* var) {
subject_.multipleTestCasesCounter_ = var;
return *this;
}

Expand Down
8 changes: 4 additions & 4 deletions include/tcframe/runner/Runner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ class Runner {
}

int generate(const string& slug, const Args& args, const Spec& spec) {
const ProblemConfig& problemConfig = spec.problemConfig();
const MultipleTestCasesConfig& multipleTestCasesConfig = spec.multipleTestCasesConfig();

GeneratorConfig generatorConfig = GeneratorConfigBuilder()
.setMultipleTestCasesCount(problemConfig.multipleTestCasesCount().value_or(nullptr))
.setMultipleTestCasesCounter(multipleTestCasesConfig.counter().value_or(nullptr))
.setSeed(args.seed().value_or(DefaultValues::seed()))
.setSlug(slug)
.setSolutionCommand(args.solution().value_or(DefaultValues::solutionCommand()))
Expand All @@ -115,11 +115,11 @@ class Runner {
}

int submit(const string& slug, const Args& args, const Spec& spec) {
const MultipleTestCasesConfig& multipleTestCasesConfig = spec.multipleTestCasesConfig();
const GradingConfig& gradingConfig = spec.gradingConfig();
const ProblemConfig& problemConfig = spec.problemConfig();

SubmitterConfigBuilder configBuilder = SubmitterConfigBuilder()
.setHasMultipleTestCasesCount(problemConfig.multipleTestCasesCount())
.setHasMultipleTestCases(multipleTestCasesConfig.counter())
.setSlug(slug)
.setSolutionCommand(args.solution().value_or(DefaultValues::solutionCommand()))
.setTestCasesDir(args.output().value_or(DefaultValues::outputDir()));
Expand Down
10 changes: 5 additions & 5 deletions include/tcframe/spec/Spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ namespace tcframe {

struct Spec {
private:
ProblemConfig problemConfig_;
MultipleTestCasesConfig multipleTestCasesConfig_;
GradingConfig gradingConfig_;
IOFormat ioFormat_;
ConstraintSuite constraintSuite_;
TestSuite testSuite_;

public:
Spec(
const ProblemConfig& problemConfig,
const MultipleTestCasesConfig& multipleTestCasesConfig,
const GradingConfig& gradingConfig,
const IOFormat& ioFormat,
const ConstraintSuite& constraintSuite,
const TestSuite& testSuite)
: problemConfig_(problemConfig)
: multipleTestCasesConfig_(multipleTestCasesConfig)
, gradingConfig_(gradingConfig)
, ioFormat_(ioFormat)
, constraintSuite_(constraintSuite)
, testSuite_(testSuite) {}

const ProblemConfig& problemConfig() const {
return problemConfig_;
const MultipleTestCasesConfig& multipleTestCasesConfig() const {
return multipleTestCasesConfig_;
}

const GradingConfig& gradingConfig() const {
Expand Down
2 changes: 1 addition & 1 deletion include/tcframe/spec/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
#include "tcframe/spec/core/DefaultValues.hpp"
#include "tcframe/spec/core/GradingConfig.hpp"
#include "tcframe/spec/core/Magic.hpp"
#include "tcframe/spec/core/ProblemConfig.hpp"
#include "tcframe/spec/core/MultipleTestCasesConfig.hpp"
12 changes: 6 additions & 6 deletions include/tcframe/spec/core/BaseProblemSpec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <vector>

#include "GradingConfig.hpp"
#include "ProblemConfig.hpp"
#include "MultipleTestCasesConfig.hpp"
#include "tcframe/spec/constraint.hpp"
#include "tcframe/spec/io.hpp"
#include "tcframe/util.hpp"
Expand All @@ -13,7 +13,7 @@ using std::vector;
namespace tcframe {

class BaseProblemSpec
: protected ProblemConfigBuilder,
: protected MultipleTestCasesConfigBuilder,
protected GradingConfigBuilder,
protected IOFormatBuilder,
protected ConstraintSuiteBuilder {
Expand Down Expand Up @@ -48,9 +48,9 @@ class BaseProblemSpec
public:
virtual ~BaseProblemSpec() {}

ProblemConfig buildProblemConfig() {
Config();
return ProblemConfigBuilder::build();
tcframe::MultipleTestCasesConfig buildMultipleTestCasesConfig() {
MultipleTestCasesConfig();
return MultipleTestCasesConfigBuilder::build();
}

tcframe::GradingConfig buildGradingConfig() {
Expand Down Expand Up @@ -86,7 +86,7 @@ class BaseProblemSpec
}

protected:
virtual void Config() {}
virtual void MultipleTestCasesConfig() {}
virtual void GradingConfig() {}
virtual void InputFormat() = 0;
virtual void OutputFormat() {}
Expand Down
4 changes: 2 additions & 2 deletions include/tcframe/spec/core/BaseTestSpec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ class BaseTestSpec : public TProblemSpec, protected TestSuiteBuilder {
}

virtual Spec buildSpec(const string& slug) {
ProblemConfig problemConfig = TProblemSpec::buildProblemConfig();
MultipleTestCasesConfig multipleTestCasesConfig = TProblemSpec::buildMultipleTestCasesConfig();
GradingConfig gradingConfig = TProblemSpec::buildGradingConfig();
IOFormat ioFormat = TProblemSpec::buildIOFormat();
ConstraintSuite constraintSuite = TProblemSpec::buildConstraintSuite();
TestSuite testSuite = buildTestSuite(slug);
return Spec(problemConfig, gradingConfig, ioFormat, constraintSuite, testSuite);
return Spec(multipleTestCasesConfig, gradingConfig, ioFormat, constraintSuite, testSuite);
}

protected:
Expand Down
46 changes: 46 additions & 0 deletions include/tcframe/spec/core/MultipleTestCasesConfig.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

#include <tuple>
#include <utility>

#include "tcframe/util.hpp"

using std::move;
using std::tie;

namespace tcframe {

struct MultipleTestCasesConfig {
friend class MultipleTestCasesConfigBuilder;

private:
optional<int*> counter_;

public:
const optional<int*>& counter() const {
return counter_;
}

bool operator==(const MultipleTestCasesConfig& o) const {
return tie(counter_) == tie(o.counter_);
}
};

class MultipleTestCasesConfigBuilder {
private:
MultipleTestCasesConfig subject_;

public:
virtual ~MultipleTestCasesConfigBuilder() {}

MultipleTestCasesConfigBuilder& Counter(int& var) {
subject_.counter_ = optional<int*>(&var);
return *this;
}

MultipleTestCasesConfig build() {
return move(subject_);
}
};

}
46 changes: 0 additions & 46 deletions include/tcframe/spec/core/ProblemConfig.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion include/tcframe/submitter/Submitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Submitter {

logger_->logTestGroupIntroduction(testGroup.id());

if (config.hasMultipleTestCasesCount()) {
if (config.hasMultipleTestCases()) {
TestCase testCase = TestCaseBuilder()
.setId(TestCaseIdCreator::createBaseId(config.slug(), testGroup.id()))
.setSubtaskIds(testGroup.testCases()[0].subtaskIds())
Expand Down
16 changes: 8 additions & 8 deletions include/tcframe/submitter/SubmitterConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ class SubmitterConfig {
friend class SubmitterConfigBuilder;

private:
bool hasMultipleTestCasesCount_;
bool hasMultipleTestCases_;
string slug_;
string solutionCommand_;
string testCasesDir_;
optional<int> timeLimit_;
optional<int> memoryLimit_;

public:
bool hasMultipleTestCasesCount() const {
return hasMultipleTestCasesCount_;
bool hasMultipleTestCases() const {
return hasMultipleTestCases_;
}

const string& slug() const {
Expand All @@ -48,8 +48,8 @@ class SubmitterConfig {
}

bool operator==(const SubmitterConfig& o) const {
return tie(hasMultipleTestCasesCount_, slug_, solutionCommand_, testCasesDir_, timeLimit_, memoryLimit_) ==
tie(o.hasMultipleTestCasesCount_,o.slug_, o.solutionCommand_, o.testCasesDir_, o.timeLimit_,
return tie(hasMultipleTestCases_, slug_, solutionCommand_, testCasesDir_, timeLimit_, memoryLimit_) ==
tie(o.hasMultipleTestCases_,o.slug_, o.solutionCommand_, o.testCasesDir_, o.timeLimit_,
o.memoryLimit_);
}
};
Expand All @@ -63,13 +63,13 @@ class SubmitterConfigBuilder {
: subject_(from) {}

SubmitterConfigBuilder() {
subject_.hasMultipleTestCasesCount_ = false;
subject_.hasMultipleTestCases_ = false;
subject_.solutionCommand_ = DefaultValues::solutionCommand();
subject_.testCasesDir_ = DefaultValues::outputDir();
}

SubmitterConfigBuilder& setHasMultipleTestCasesCount(bool hasMultipleTestCasesCount) {
subject_.hasMultipleTestCasesCount_ = hasMultipleTestCasesCount;
SubmitterConfigBuilder& setHasMultipleTestCases(bool hasMultipleTestCases) {
subject_.hasMultipleTestCases_ = hasMultipleTestCases;
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion test/tcframe/generator/GeneratorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GeneratorTests : public Test {
.build();

GeneratorConfig multipleTestCasesConfig = GeneratorConfigBuilder(config)
.setMultipleTestCasesCount(&T)
.setMultipleTestCasesCounter(&T)
.build();

Generator generator = Generator(&testCaseGenerator, &verifier, &os, &logger);
Expand Down

0 comments on commit 09c17e0

Please sign in to comment.