-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmytest.cpp
More file actions
138 lines (123 loc) · 3.77 KB
/
Copy pathmytest.cpp
File metadata and controls
138 lines (123 loc) · 3.77 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
136
137
138
//
// mytest.cpp
// Project 1
//
// Created by Amarjot Gill 9/28/2021
// test program for testing edge, error cases, and assignment opertator for graph class
#include "graph.h"
const string TESTFILE = "testdata.txt";
class Tester{ // Tester class to implement test functions
public:
bool testAssignment(Graph& rhs, Graph& cGraph);
};
int main(){
Tester testObj;
Graph aGraph(TESTFILE);
cout << "TESTING A NORMAL CASE" << endl;
try{
aGraph.findPath(1,15);
cout << "Finding the path from node 1 to node 15: " << endl;
aGraph.dump();
}catch(std::out_of_range const &e){
cout << e.what() << endl;
}
cout << endl;
cout << "TESTING A CASE WHERE START NODE DOES NOT EXIST" << endl;
try{
aGraph.findPath(20,15);
cout << "Finding the path from node 20 to node 15: " << endl;
aGraph.dump();
}catch(std::out_of_range const &e){
cout << e.what() << endl;
}
cout << endl;
cout << "TESTING A CASE END NODE DOES NOT EXIST" << endl;
try{
aGraph.findPath(1,20);
cout << "Finding the path from node 1 to node 15: " << endl;
aGraph.dump();
}catch(std::out_of_range const &e){
cout << e.what() << endl;
}
cout << endl;
cout << "TESTING A CASE FOR FINDING NODE TO ITSELF" << endl;
try{
aGraph.findPath(2,2);
cout << "Finding the path from node 2 to itself: " << endl;
aGraph.dump();
}catch(std::out_of_range const &e){
cout << e.what() << endl;
}
cout << endl;
cout << "TESTING CASE WHERE PATH DOES NOT EXIST" << endl;
try{
aGraph.findPath(3,0);
cout << "Finding the path from node 3 to node 0: " << endl;
aGraph.dump();
}catch(std::out_of_range const &e){
cout << e.what() << endl;
}
cout << endl;
Graph bGraph;
cout << "TESTING CASE OF TRYING TO FIND PATH IN EMPTY GRAPH" << endl;
cout << "Finding the path from node 0 to node 12 in an empty Graph object: " << endl;
try{
bGraph.findPath(1,14);
bGraph.dump();
}catch(std::out_of_range const &e){
cout << e.what() << endl;
}
cout << endl;
cout << "BUILDING EMPTY GRAPH USING BUILDGRAPH FUNCTION AND TRYING TO FIND PATH" << endl;
bGraph.buildGraph(TESTFILE);
try{
cout << "Finding the path from node 0 to node 12 in new Graph" << endl;
bGraph.findPath(0,12);
bGraph.dump();
}catch(std::out_of_range const &e){
cout << e.what() << endl;
}
cout << endl;
Graph cGraph;
cout << "TESTING ASSIGNMENT OPERATOR FUNCTION" << endl;
try{
if(testObj.testAssignment(bGraph,cGraph)){
cout << "Assignment passed deep copy made!" << endl;
}else{
cout << "Assignment failed!" << endl;
}
}catch(std::out_of_range const &e){
cout << e.what() << endl;
}
cout << endl;
cout << "TESTING SELF ASSIGNMENT IN ASSIGNMENT OPERATOR FUNCTION" << endl;
try{
if(testObj.testAssignment(cGraph,cGraph)){
cout << "Assignment passed deep copy made!" << endl;
}else{
cout << "Assignment failed!" << endl;
}
}catch(std::out_of_range const &e){
cout << e.what() << endl;
}
cout << endl;
cout << "FINDING PATH FROM 0 to 12 IN NEW ASSIGNED GRAPH" << endl;
try{
cout << "Finding the path from node 0 to node 12 in new Graph" << endl;
cGraph.findPath(0,12);
cGraph.dump();
}catch(std::out_of_range const &e){
cout << e.what() << endl;
}
cout << endl;
return 0;
}
bool Tester::testAssignment(Graph& rhs, Graph& cGraph){
cGraph = rhs;
rhs.clearGraph();
if(cGraph.empty()){
return false;
}else{
return true;
}
}