-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
95 lines (91 loc) · 2.35 KB
/
Copy pathTest.cpp
File metadata and controls
95 lines (91 loc) · 2.35 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
#include "doctest.h"
#include "Algorithms.hpp"
#include "Graph.hpp"
#include <iostream>
#include <sstream>
using namespace std;
TEST_CASE("Test graph addition")
{
ariel::Graph g1;
vector<vector<int>> graph = {
{0, 1, 0},
{1, 0, 1},
{0, 1, 0}};
g1.loadGraph(graph);
ariel::Graph g2;
vector<vector<int>> weightedGraph = {
{0, 1, 1},
{1, 0, 2},
{1, 2, 0}};
g2.loadGraph(weightedGraph);
ariel::Graph g3 = g1 + g2;
vector<vector<int>> expectedGraph = {
{0, 2, 1},
{2, 0, 3},
{1, 3, 0}};
std::ostringstream output;
std::streambuf *OldCoutbuffer = std::cout.rdbuf(output.rdbuf());
g3.printGraph();
CHECK(output.str() == "[0, 2, 1]\n[2, 0, 3]\n[1, 3, 0]");
std::cout.rdbuf(OldCoutbuffer);
}
TEST_CASE("Test graph multiplication")
{
ariel::Graph g1;
vector<vector<int>> graph = {
{0, 1, 0},
{1, 0, 1},
{0, 1, 0}};
g1.loadGraph(graph);
ariel::Graph g2;
vector<vector<int>> weightedGraph = {
{0, 1, 1},
{1, 0, 2},
{1, 2, 0}};
g2.loadGraph(weightedGraph);
ariel::Graph g4 = g1 * g2;
vector<vector<int>> expectedGraph = {
{0, 0, 2},
{1, 0, 1},
{1, 0, 0}};
std::ostringstream output;
std::streambuf *OldCoutbuffer = std::cout.rdbuf(output.rdbuf());
g4.printGraph();
CHECK(output.str() == "[0, 0, 2]\n[1, 0, 1]\n[1, 0, 0]");
std::cout.rdbuf(OldCoutbuffer);
}
TEST_CASE("Invalid operations")
{
ariel::Graph g1;
vector<vector<int>> graph = {
{0, 1, 0},
{1, 0, 1},
{0, 1, 0}};
g1.loadGraph(graph);
ariel::Graph g2;
vector<vector<int>> weightedGraph = {
{0, 1, 1, 1},
{1, 0, 2, 1},
{1, 2, 0, 1}};
g2.loadGraph(weightedGraph);
ariel::Graph g5;
vector<vector<int>> graph2 = {
{0, 1, 0, 0, 1},
{1, 0, 1, 0, 0},
{0, 1, 0, 1, 0},
{0, 0, 1, 0, 1},
{1, 0, 0, 1, 0}};
g5.loadGraph(graph2);
CHECK_THROWS(g5 * g1);
CHECK_THROWS(g1 * g2);
// Addition of two graphs with different dimensions
ariel::Graph g6;
vector<vector<int>> graph3 = {
{0, 1, 0, 0, 1},
{1, 0, 1, 0, 0},
{0, 1, 0, 1, 0},
{0, 0, 1, 0, 1},
{1, 0, 0, 1, 0}};
g6.loadGraph(graph3);
CHECK_THROWS(g1 + g6);
}