Skip to content

Commit

Permalink
Refactor: Simplify and add missing tests for IOFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed May 28, 2017
1 parent a3f3e62 commit 488b1c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 56 deletions.
36 changes: 16 additions & 20 deletions test/unit/tcframe/spec/core/BaseProblemSpecTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "tcframe/spec/core/BaseProblemSpec.hpp"

using ::testing::A;
using ::testing::AllOf;
using ::testing::ElementsAre;
using ::testing::Eq;
Expand All @@ -16,6 +15,9 @@ namespace tcframe {
class BaseProblemSpecTests : public Test {
protected:
class ProblemSpec : public BaseProblemSpec {
public:
int Z;

protected:
int T;
int A, B;
Expand All @@ -29,23 +31,17 @@ class BaseProblemSpecTests : public Test {
newLinesIOSegment()
.addVectorVariable(Vector::create(X, "X"))
.setSize([] {return 3;});
newGridIOSegment()
.addMatrixVariable(Matrix::create(M, "M"))
.setSize([] {return 2;}, [] {return 3;})
.build();
}

void BeforeOutputFormat() {
Z = 42;
}

void OutputFormat() {
newLinesIOSegment()
.addVectorVariable(Vector::create(X, "X"))
.setSize([] {return 3;});
newGridIOSegment()
.addMatrixVariable(Matrix::create(M, "M"))
.setSize([] {return 2;}, [] {return 3;})
.build();
newLineIOSegment()
.addScalarVariable(Scalar::create(A, "A"))
.addScalarVariable(Scalar::create(B, "B"));
}
};

Expand Down Expand Up @@ -128,15 +124,15 @@ TEST_F(BaseProblemSpecTests, GradingConfig) {
}

TEST_F(BaseProblemSpecTests, IOFormat) {
IOFormat ioFormat = ProblemSpec().buildIOFormat();
EXPECT_THAT(ioFormat.inputFormat(), ElementsAre(
A<LineIOSegment*>(),
A<LinesIOSegment*>(),
A<GridIOSegment*>()));
EXPECT_THAT(ioFormat.outputFormat(), ElementsAre(
A<LinesIOSegment*>(),
A<GridIOSegment*>(),
A<LineIOSegment*>()));
ProblemSpec problemSpec;
problemSpec.Z = 0;

IOFormat ioFormat = problemSpec.buildIOFormat();
EXPECT_THAT(ioFormat.inputFormat(), SizeIs(2));
EXPECT_THAT(ioFormat.outputFormat(), SizeIs(1));

ioFormat.beforeOutputFormat()();
EXPECT_THAT(problemSpec.Z, Eq(42));
}

TEST_F(BaseProblemSpecTests, Constraints) {
Expand Down
36 changes: 0 additions & 36 deletions test/unit/tcframe/spec/io/IOFormatBuilderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,6 @@ TEST_F(IOFormatBuilderTests, Building_Failed_LinesSegmentWithoutSizeNotLast) {
} catch (runtime_error& e) {
EXPECT_THAT(e.what(), StrEq("Lines segment without size can only be the last segment"));
}

try {
builder.prepareForOutputFormat();
builder
.newLineIOSegment()
.addScalarVariable(Scalar::create(X, "X"));
builder
.newLinesIOSegment()
.addVectorVariable(Vector::create(Y, "Y"));
builder
.newGridIOSegment()
.addMatrixVariable(Matrix::create(Z, "Z"))
.setSize([] {return 2;}, [] {return 3;});
builder.build();
FAIL();
} catch (runtime_error& e) {
EXPECT_THAT(e.what(), StrEq("Lines segment without size can only be the last segment"));
}
}


Expand All @@ -127,24 +109,6 @@ TEST_F(IOFormatBuilderTests, Building_Failed_RawLinesSegmentWithoutSizeNotLast)
} catch (runtime_error& e) {
EXPECT_THAT(e.what(), StrEq("Raw lines segment without size can only be the last segment"));
}

try {
builder.prepareForOutputFormat();
builder
.newLineIOSegment()
.addScalarVariable(Scalar::create(X, "X"));
builder
.newRawLinesIOSegment()
.addVectorVariable(Vector::createRaw(V, "V"));
builder
.newGridIOSegment()
.addMatrixVariable(Matrix::create(Z, "Z"))
.setSize([] {return 2;}, [] {return 3;});
builder.build();
FAIL();
} catch (runtime_error& e) {
EXPECT_THAT(e.what(), StrEq("Raw lines segment without size can only be the last segment"));
}
}

}

0 comments on commit 488b1c5

Please sign in to comment.