-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests_acceptance.cpp
More file actions
135 lines (113 loc) · 4.4 KB
/
tests_acceptance.cpp
File metadata and controls
135 lines (113 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#define BOOST_TEST_MODULE Acceptance
#include <boost/test/included/unit_test.hpp>
#include "Graph.h"
#include "config.h"
#include "GraphGenerator.h"
using namespace gis;
struct AcceptanceTestsFixture {
using StringVec = std::set<std::string>;
const std::string acceptanceTestsBasePath;
const std::string dagFile;
const std::string dgFile;
const std::string dg2File;
const std::string fullFile;
const std::string noEdgesFile;
const std::string parallelEdgesFile;
const std::string scgFile;
AcceptanceTestsFixture() : acceptanceTestsBasePath{acceptanceTestsResourcesDir()},
dagFile{"tinyDAG.txt"}, dgFile{"tinyDG.txt"}, dg2File{"tinyDG2.txt"},
fullFile{"tinyFull.txt"}, noEdgesFile{"tinyNoEdges.txt"},
parallelEdgesFile{"tinyParallelEdges.txt"}, scgFile{"tinySCG.txt"} { }
Graph readGraph(const std::string& fileName) {
std::ifstream file(fileName, std::ios::in);
auto g = generator::generateFromStream(file);
file.close();
return g;
}
bool equal(const Vertex::VerticesRefsVector& lhs, const StringVec& rhs) {
if (lhs.size() != rhs.size()) return false;
for (const gis::Vertex &v : lhs) {
if (rhs.end() == rhs.find(v.label)) {
return false;
}
}
return true;
}
bool equal(const std::vector<Vertex::VerticesRefsVector>& lhs, std::vector<StringVec>& rhs) {
if (lhs.size() != rhs.size()) return false;
for (const auto &comp : lhs) {
for (size_t j = 0; j < rhs.size(); ++j) {
if (equal(comp, rhs[j])) {
rhs.erase(rhs.begin() + j);
break;
}
}
}
return rhs.empty();
}
};
BOOST_FIXTURE_TEST_SUITE(AcceptanceTests, AcceptanceTestsFixture)
BOOST_AUTO_TEST_CASE(DAG_Graph)
{
std::vector<StringVec> expected = {
{"0"}, {"1"}, {"2"}, {"3"}, {"4"}, {"5"}, {"6"}, {"7"}, {"8"}, {"9"}, {"10"}, {"11"}, {"12"}
};
auto g = readGraph(acceptanceTestsBasePath + dagFile);
auto scc = g.findStronglyConntectedComponents();
BOOST_REQUIRE(equal(scc, expected));
}
BOOST_AUTO_TEST_CASE(DG_Graph)
{
std::vector<StringVec> expected = {
{"0", "2", "3", "4", "5"}, {"1"}, {"6"}, {"7", "8"}, {"9", "10", "11", "12"}
};
auto g = readGraph(acceptanceTestsBasePath + dgFile);
auto scc = g.findStronglyConntectedComponents();
BOOST_REQUIRE(equal(scc, expected));
}
BOOST_AUTO_TEST_CASE(DG2_Graph)
{
std::vector<StringVec> expected = {
{"0", "1"}, {"2", "3", "4"}, {"5"}, {"6"}, {"7"}
};
auto g = readGraph(acceptanceTestsBasePath + dg2File);
auto scc = g.findStronglyConntectedComponents();
BOOST_REQUIRE(equal(scc, expected));
}
BOOST_AUTO_TEST_CASE(Full_Graph)
{
std::vector<StringVec> expected = {
{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}
};
auto g = readGraph(acceptanceTestsBasePath + fullFile);
auto scc = g.findStronglyConntectedComponents();
BOOST_REQUIRE(equal(scc, expected));
}
BOOST_AUTO_TEST_CASE(NoEdges_Graph)
{
std::vector<StringVec> expected = {
{"0"}, {"1"}, {"2"}, {"3"}, {"4"}, {"5"}, {"6"}, {"7"}, {"8"}, {"9"}, {"10"}, {"11"}, {"12"}
};
auto g = readGraph(acceptanceTestsBasePath + noEdgesFile);
auto scc = g.findStronglyConntectedComponents();
BOOST_REQUIRE(equal(scc, expected));
}
BOOST_AUTO_TEST_CASE(ParallelEdges_Graph)
{
std::vector<StringVec> expected = {
{"0", "2", "3", "4", "5"}, {"1"}, {"6"}, {"7", "8"}, {"9", "10", "11", "12"}
};
auto g = readGraph(acceptanceTestsBasePath + parallelEdgesFile);
auto scc = g.findStronglyConntectedComponents();
BOOST_REQUIRE(equal(scc, expected));
}
BOOST_AUTO_TEST_CASE(SCG_Graph)
{
std::vector<StringVec> expected = {
{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}
};
auto g = readGraph(acceptanceTestsBasePath + scgFile);
auto scc = g.findStronglyConntectedComponents();
BOOST_REQUIRE(equal(scc, expected));
}
BOOST_AUTO_TEST_SUITE_END()