Skip to content

Commit

Permalink
Refactor runner: Merge io_manipulator into io/
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Jul 22, 2017
1 parent 810c07f commit 89fc25c
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 124 deletions.
27 changes: 13 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,18 @@ set(INCLUDE
include/tcframe/spec/core/StyleConfig.hpp
include/tcframe/spec/io.hpp
include/tcframe/spec/io/GridIOSegment.hpp
include/tcframe/spec/io/GridIOSegmentManipulator.hpp
include/tcframe/spec/io/IOFormat.hpp
include/tcframe/spec/io/IOManipulator.hpp
include/tcframe/spec/io/IOSegment.hpp
include/tcframe/spec/io/LineIOSegment.hpp
include/tcframe/spec/io/LineIOSegmentManipulator.hpp
include/tcframe/spec/io/LinesIOSegment.hpp
include/tcframe/spec/io/LinesIOSegmentManipulator.hpp
include/tcframe/spec/io/RawLineIOSegment.hpp
include/tcframe/spec/io/RawLineIOSegmentManipulator.hpp
include/tcframe/spec/io/RawLinesIOSegment.hpp
include/tcframe/spec/io_manipulator.hpp
include/tcframe/spec/io_manipulator/GridIOSegmentManipulator.hpp
include/tcframe/spec/io_manipulator/IOManipulator.hpp
include/tcframe/spec/io_manipulator/LineIOSegmentManipulator.hpp
include/tcframe/spec/io_manipulator/LinesIOSegmentManipulator.hpp
include/tcframe/spec/io_manipulator/RawLineIOSegmentManipulator.hpp
include/tcframe/spec/io_manipulator/RawLinesIOSegmentManipulator.hpp
include/tcframe/spec/io/RawLinesIOSegmentManipulator.hpp
include/tcframe/spec/random.hpp
include/tcframe/spec/random/Random.hpp
include/tcframe/spec/testcase.hpp
Expand Down Expand Up @@ -202,18 +201,18 @@ set(TEST_UNIT
test/unit/tcframe/spec/core/MagicTests.cpp
test/unit/tcframe/spec/core/MockSeedSetter.hpp
test/unit/tcframe/spec/io/GridIOSegmentBuilderTests.cpp
test/unit/tcframe/spec/io/GridIOSegmentManipulatorTests.cpp
test/unit/tcframe/spec/io/IOFormatBuilderTests.cpp
test/unit/tcframe/spec/io/IOManipulatorTests.cpp
test/unit/tcframe/spec/io/LineIOSegmentBuilderTests.cpp
test/unit/tcframe/spec/io/LineIOSegmentManipulatorTests.cpp
test/unit/tcframe/spec/io/LinesIOSegmentBuilderTests.cpp
test/unit/tcframe/spec/io/LinesIOSegmentManipulatorTests.cpp
test/unit/tcframe/spec/io/MockIOManipulator.hpp
test/unit/tcframe/spec/io/RawLineIOSegmentBuilderTests.cpp
test/unit/tcframe/spec/io/RawLineIOSegmentManipulatorTests.cpp
test/unit/tcframe/spec/io/RawLinesIOSegmentBuilderTests.cpp
test/unit/tcframe/spec/io_manipulator/GridIOSegmentManipulatorTests.cpp
test/unit/tcframe/spec/io_manipulator/IOManipulatorTests.cpp
test/unit/tcframe/spec/io_manipulator/LineIOSegmentManipulatorTests.cpp
test/unit/tcframe/spec/io_manipulator/LinesIOSegmentManipulatorTests.cpp
test/unit/tcframe/spec/io_manipulator/MockIOManipulator.hpp
test/unit/tcframe/spec/io_manipulator/RawLineIOSegmentManipulatorTests.cpp
test/unit/tcframe/spec/io_manipulator/RawLinesIOSegmentManipulatorTests.cpp
test/unit/tcframe/spec/io/RawLinesIOSegmentManipulatorTests.cpp
test/unit/tcframe/spec/random/RandomTests.cpp
test/unit/tcframe/spec/testcase/TestCaseTests.cpp
test/unit/tcframe/spec/testcase/TestGroupTests.cpp
Expand Down
1 change: 0 additions & 1 deletion include/tcframe/spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "tcframe/spec/constraint.hpp"
#include "tcframe/spec/core.hpp"
#include "tcframe/spec/io.hpp"
#include "tcframe/spec/io_manipulator.hpp"
#include "tcframe/spec/random.hpp"
#include "tcframe/spec/testcase.hpp"
#include "tcframe/spec/variable.hpp"
Expand Down
6 changes: 6 additions & 0 deletions include/tcframe/spec/io.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#pragma once

#include "tcframe/spec/io/GridIOSegment.hpp"
#include "tcframe/spec/io/GridIOSegmentManipulator.hpp"
#include "tcframe/spec/io/IOFormat.hpp"
#include "tcframe/spec/io/IOManipulator.hpp"
#include "tcframe/spec/io/IOSegment.hpp"
#include "tcframe/spec/io/LineIOSegment.hpp"
#include "tcframe/spec/io/LineIOSegmentManipulator.hpp"
#include "tcframe/spec/io/LinesIOSegment.hpp"
#include "tcframe/spec/io/LinesIOSegmentManipulator.hpp"
#include "tcframe/spec/io/RawLineIOSegment.hpp"
#include "tcframe/spec/io/RawLineIOSegmentManipulator.hpp"
#include "tcframe/spec/io/RawLinesIOSegment.hpp"
#include "tcframe/spec/io/RawLinesIOSegmentManipulator.hpp"
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <iostream>
#include <stdexcept>

#include "tcframe/spec/io.hpp"
#include "GridIOSegment.hpp"
#include "tcframe/spec/variable.hpp"
#include "tcframe/util.hpp"

Expand All @@ -16,9 +16,7 @@ namespace tcframe {

class GridIOSegmentManipulator {
public:
GridIOSegmentManipulator() = delete;

static string parse(GridIOSegment* segment, istream* in) {
string parse(GridIOSegment* segment, istream* in) {
Matrix* variable = segment->variable();
variable->clear();
variable->parseFrom(in, segment->rows()(), segment->columns()());
Expand All @@ -29,7 +27,7 @@ class GridIOSegmentManipulator {
variable->columns(variable->rows() - 1) - 1);
}

static void print(GridIOSegment* segment, ostream* out) {
void print(GridIOSegment* segment, ostream* out) {
checkMatrixSize(segment);

Matrix* variable = segment->variable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class IOManipulator {
private:
IOFormat ioFormat_;

GridIOSegmentManipulator gridIOSegmentManipulator;
LineIOSegmentManipulator lineIOSegmentManipulator;
LinesIOSegmentManipulator linesIOSegmentManipulator;
RawLineIOSegmentManipulator rawLineIOSegmentManipulator;
RawLinesIOSegmentManipulator rawLinesIOSegmentManipulator;

public:
virtual ~IOManipulator() {}

Expand Down Expand Up @@ -72,15 +78,15 @@ class IOManipulator {
void print(const IOSegments& segments, ostream* out) {
for (IOSegment* segment : segments) {
if (segment->type() == IOSegmentType::GRID) {
GridIOSegmentManipulator::print((GridIOSegment*) segment, out);
gridIOSegmentManipulator.print((GridIOSegment*) segment, out);
} else if (segment->type() == IOSegmentType::LINE) {
LineIOSegmentManipulator::print((LineIOSegment*) segment, out);
lineIOSegmentManipulator.print((LineIOSegment*) segment, out);
} else if (segment->type() == IOSegmentType::LINES) {
LinesIOSegmentManipulator::print((LinesIOSegment*) segment, out);
linesIOSegmentManipulator.print((LinesIOSegment*) segment, out);
} else if (segment->type() == IOSegmentType::RAW_LINE) {
RawLineIOSegmentManipulator::print((RawLineIOSegment*) segment, out);
rawLineIOSegmentManipulator.print((RawLineIOSegment*) segment, out);
} else if (segment->type() == IOSegmentType::RAW_LINES) {
RawLinesIOSegmentManipulator::print((RawLinesIOSegment*) segment, out);
rawLinesIOSegmentManipulator.print((RawLinesIOSegment*) segment, out);
}
}
}
Expand All @@ -89,15 +95,15 @@ class IOManipulator {
string lastVariableName;
for (IOSegment* segment : segments) {
if (segment->type() == IOSegmentType::GRID) {
lastVariableName = GridIOSegmentManipulator::parse((GridIOSegment*) segment, in);
lastVariableName = gridIOSegmentManipulator.parse((GridIOSegment*) segment, in);
} else if (segment->type() == IOSegmentType::LINE) {
lastVariableName = LineIOSegmentManipulator::parse((LineIOSegment*) segment, in);
lastVariableName = lineIOSegmentManipulator.parse((LineIOSegment*) segment, in);
} else if (segment->type() == IOSegmentType::LINES) {
lastVariableName = LinesIOSegmentManipulator::parse((LinesIOSegment*) segment, in);
lastVariableName = linesIOSegmentManipulator.parse((LinesIOSegment*) segment, in);
} else if (segment->type() == IOSegmentType::RAW_LINE) {
lastVariableName = RawLineIOSegmentManipulator::parse((RawLineIOSegment*) segment, in);
lastVariableName = rawLineIOSegmentManipulator.parse((RawLineIOSegment*) segment, in);
} else if (segment->type() == IOSegmentType::RAW_LINES) {
lastVariableName = RawLinesIOSegmentManipulator::parse((RawLinesIOSegment*) segment, in);
lastVariableName = rawLinesIOSegmentManipulator.parse((RawLinesIOSegment*) segment, in);
}
}
if (!lastVariableName.empty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <iostream>
#include <stdexcept>

#include "tcframe/spec/io.hpp"
#include "LineIOSegment.hpp"
#include "tcframe/spec/variable.hpp"
#include "tcframe/util.hpp"

Expand All @@ -16,9 +16,7 @@ namespace tcframe {

class LineIOSegmentManipulator {
public:
LineIOSegmentManipulator() = delete;

static string parse(LineIOSegment* segment, istream* in) {
string parse(LineIOSegment* segment, istream* in) {
string lastVariableName;
for (const LineIOSegmentVariable& segmentVariable : segment->variables()) {
if (!lastVariableName.empty()) {
Expand All @@ -42,7 +40,7 @@ class LineIOSegmentManipulator {
return lastVariableName;
}

static void print(LineIOSegment* segment, ostream* out) {
void print(LineIOSegment* segment, ostream* out) {
bool first = true;
for (const LineIOSegmentVariable& segmentVariable : segment->variables()) {
if (!first) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <iostream>
#include <stdexcept>

#include "tcframe/spec/io.hpp"
#include "LinesIOSegment.hpp"
#include "tcframe/spec/variable.hpp"
#include "tcframe/util.hpp"

Expand All @@ -16,9 +16,7 @@ namespace tcframe {

class LinesIOSegmentManipulator {
public:
LinesIOSegmentManipulator() = delete;

static string parse(LinesIOSegment* segment, istream* in) {
string parse(LinesIOSegment* segment, istream* in) {
for (Variable* variable : segment->variables()) {
if (variable->type() == VariableType::VECTOR) {
((Vector*) variable)->clear();
Expand Down Expand Up @@ -62,7 +60,7 @@ class LinesIOSegmentManipulator {
return lastVariableName;
}

static void print(LinesIOSegment* segment, ostream* out) {
void print(LinesIOSegment* segment, ostream* out) {
checkVectorSizes(segment);

int size = getSize(segment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <iostream>

#include "tcframe/spec/io.hpp"
#include "RawLineIOSegment.hpp"
#include "tcframe/spec/variable.hpp"
#include "tcframe/util.hpp"

Expand All @@ -14,17 +14,15 @@ namespace tcframe {

class RawLineIOSegmentManipulator {
public:
RawLineIOSegmentManipulator() = delete;

static string parse(RawLineIOSegment* segment, istream* in) {
string parse(RawLineIOSegment* segment, istream* in) {
string lastVariableName = TokenFormatter::formatVariable(segment->variable()->name());
segment->variable()->parseFrom(in);
WhitespaceManipulator::parseNewline(in, lastVariableName);

return lastVariableName;
}

static void print(RawLineIOSegment* segment, ostream* out) {
void print(RawLineIOSegment* segment, ostream* out) {
segment->variable()->printTo(out);
*out << endl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <iostream>
#include <stdexcept>

#include "tcframe/spec/io.hpp"
#include "RawLinesIOSegment.hpp"
#include "tcframe/spec/variable.hpp"
#include "tcframe/util.hpp"

Expand All @@ -16,9 +16,7 @@ namespace tcframe {

class RawLinesIOSegmentManipulator {
public:
RawLinesIOSegmentManipulator() = delete;

static string parse(RawLinesIOSegment* segment, istream* in) {
string parse(RawLinesIOSegment* segment, istream* in) {
string lastVariableName;

Vector* variable = segment->variable();
Expand All @@ -37,7 +35,7 @@ class RawLinesIOSegmentManipulator {
return lastVariableName;
}

static void print(RawLinesIOSegment* segment, ostream* out) {
void print(RawLinesIOSegment* segment, ostream* out) {
checkVectorSize(segment);
Vector* variable = segment->variable();
for (int j = 0; j < variable->size(); j++) {
Expand Down
8 changes: 0 additions & 8 deletions include/tcframe/spec/io_manipulator.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/tcframe/generator/TestCaseGeneratorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "../evaluator/MockEvaluator.hpp"
#include "../os/MockOperatingSystem.hpp"
#include "../spec/io_manipulator/MockIOManipulator.hpp"
#include "../spec/io/MockIOManipulator.hpp"
#include "../spec/verifier/MockVerifier.hpp"
#include "MockGeneratorLogger.hpp"
#include "tcframe/generator/TestCaseGenerator.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <sstream>

#include "tcframe/spec/io_manipulator/GridIOSegmentManipulator.hpp"
#include "tcframe/spec/io/GridIOSegmentManipulator.hpp"

using ::testing::Eq;
using ::testing::StrEq;
Expand All @@ -23,27 +23,29 @@ class GridIOSegmentManipulatorTests : public Test {
.addMatrixVariable(Matrix::create(M, "M"))
.setSize(rows, columns)
.build();

GridIOSegmentManipulator manipulator;
};

TEST_F(GridIOSegmentManipulatorTests, Parsing_Successful) {
istringstream in("1 2 3\n4 5 6\n");

GridIOSegmentManipulator::parse(segment, &in);
manipulator.parse(segment, &in);
EXPECT_THAT(M, Eq(vector<vector<int>>{{1, 2, 3}, {4, 5, 6}}));
}

TEST_F(GridIOSegmentManipulatorTests, Parsing_Successful_CheckLastVariable) {
istringstream in("1 2 3\n4 5 6\n");

EXPECT_THAT(GridIOSegmentManipulator::parse(segment, &in), Eq("'M[1][2]'"));
EXPECT_THAT(manipulator.parse(segment, &in), Eq("'M[1][2]'"));
}

TEST_F(GridIOSegmentManipulatorTests, Printing_Successful) {
ostringstream out;

M = {{1, 2, 3}, {4, 5, 6}};

GridIOSegmentManipulator::print(segment, &out);
manipulator.print(segment, &out);
EXPECT_THAT(out.str(), Eq("1 2 3\n4 5 6\n"));
}

Expand All @@ -53,7 +55,7 @@ TEST_F(GridIOSegmentManipulatorTests, Printing_Failed_RowsMismatch) {
M = {{1, 2, 3}};

try {
GridIOSegmentManipulator::print(segment, &out);
manipulator.print(segment, &out);
FAIL();
} catch (runtime_error& e) {
EXPECT_THAT(e.what(), StrEq("Number of rows of matrix 'M' unsatisfied. Expected: 2, actual: 1"));
Expand All @@ -66,7 +68,7 @@ TEST_F(GridIOSegmentManipulatorTests, Printing_Failed_ColumnsMismatch) {
M = {{1, 2, 3}, {4, 5}};

try {
GridIOSegmentManipulator::print(segment, &out);
manipulator.print(segment, &out);
FAIL();
} catch (runtime_error& e) {
EXPECT_THAT(e.what(), StrEq("Number of columns of row 1 of matrix 'M' unsatisfied. Expected: 3, actual: 2"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <sstream>

#include "tcframe/spec/io_manipulator/IOManipulator.hpp"
#include "tcframe/spec/io/IOManipulator.hpp"

using ::testing::Eq;
using ::testing::StrEq;
Expand Down

0 comments on commit 89fc25c

Please sign in to comment.