74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
#include "MatrixGraph.h"
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
using namespace Kylin;
|
|
|
|
class MatrixGraphTest {
|
|
public:
|
|
MatrixGraphTest() {
|
|
|
|
graph.setVertex(2, 2);
|
|
|
|
graph.setEdge(0, 1, 1);
|
|
graph.setEdge(1, 0, 1);
|
|
|
|
graph.setEdge(0, 2, 3);
|
|
graph.setEdge(2, 0, 3);
|
|
|
|
graph.setEdge(1, 2, 1);
|
|
graph.setEdge(2, 1, 1);
|
|
|
|
graph.setEdge(1, 3, 4);
|
|
graph.setEdge(3, 1, 4);
|
|
|
|
graph.setEdge(2, 3, 1);
|
|
graph.setEdge(3, 2, 1);
|
|
}
|
|
MatrixGraph<4, size_t, size_t> graph;
|
|
};
|
|
BOOST_AUTO_TEST_SUITE(MatrixGraphTestCase)
|
|
BOOST_FIXTURE_TEST_CASE(Vertex, MatrixGraphTest) { BOOST_CHECK_EQUAL(graph.vertex(2), 2); }
|
|
|
|
BOOST_FIXTURE_TEST_CASE(SetVertex, MatrixGraphTest) {
|
|
graph.setVertex(2, 250);
|
|
BOOST_CHECK_EQUAL(graph.vertex(2), 250);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(Adjacent, MatrixGraphTest) {
|
|
size_t adjacents[3]{0, 1, 3};
|
|
auto adjacent = graph.adjacent(2);
|
|
BOOST_CHECK_EQUAL(adjacent.size(), 3);
|
|
size_t i = 0;
|
|
for (auto adj : adjacent) {
|
|
BOOST_CHECK_EQUAL(adj, adjacents[i++]);
|
|
}
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(Edge1, MatrixGraphTest) {
|
|
auto edge = graph.edge(1, 3);
|
|
BOOST_CHECK_EQUAL(static_cast<bool>(edge), true);
|
|
BOOST_CHECK_EQUAL(*edge, 4);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(SetEdge, MatrixGraphTest) {
|
|
BOOST_CHECK_EQUAL(graph.setEdge(1, 3, 8), true);
|
|
BOOST_CHECK_EQUAL(*(graph.edge(1, 3)), 8);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(RemoveEdge, MatrixGraphTest) {
|
|
BOOST_CHECK_EQUAL(graph.removeEdge(1, 3), true);
|
|
BOOST_CHECK_EQUAL(graph.edgeCount(), 9);
|
|
BOOST_CHECK_EQUAL(static_cast<bool>(graph.edge(1, 3)), false);
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(VertexCount, MatrixGraphTest) { BOOST_CHECK_EQUAL(graph.vertexCount(), 4); }
|
|
|
|
BOOST_FIXTURE_TEST_CASE(EdgeCount, MatrixGraphTest) { BOOST_CHECK_EQUAL(graph.edgeCount(), 10); }
|
|
|
|
BOOST_FIXTURE_TEST_CASE(OutDegree, MatrixGraphTest) { BOOST_CHECK_EQUAL(graph.outDegree(2), 3); }
|
|
|
|
BOOST_FIXTURE_TEST_CASE(InDegree, MatrixGraphTest) { BOOST_CHECK_EQUAL(graph.inDegree(2), 3); }
|
|
|
|
BOOST_FIXTURE_TEST_CASE(Degree, MatrixGraphTest) { BOOST_CHECK_EQUAL(graph.degree(2), 6); }
|
|
BOOST_AUTO_TEST_SUITE_END()
|