Skip to content

Commit 4c94e80

Browse files
authored
Merge pull request #18 from Debashis08/release
Release
2 parents 43601f7 + 8b314bc commit 4c94e80

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

Tests/0003_Graph/0002_DepthFirstSearchTest.cc

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,152 @@ namespace DepthFirstSearchTest
2525
string expectedResult = "u(1,8) v(2,7) w(9,12) x(4,5) y(3,6) z(10,11)";
2626
EXPECT_EQ(actualResult, expectedResult);
2727
}
28+
29+
TEST(DFSTesting, ShowDFSResultTest_SingleVertex)
30+
{
31+
DFSGraph graph;
32+
33+
graph.PushDirectedEdge('a', 'a');
34+
35+
graph.DFS();
36+
37+
string actualResult = unitTestHelperVectorOfPair.VerifyVectorOfPairOfTwo(graph.ShowDFSResult());
38+
string expectedResult = "a(1,2)";
39+
EXPECT_EQ(actualResult, expectedResult);
40+
}
41+
42+
TEST(DFSTesting, ShowDFSResultTest_DisconnectedGraph)
43+
{
44+
DFSGraph graph;
45+
46+
graph.PushDirectedEdge('a', 'b');
47+
graph.PushDirectedEdge('c', 'd');
48+
49+
graph.DFS();
50+
51+
string actualResult = unitTestHelperVectorOfPair.VerifyVectorOfPairOfTwo(graph.ShowDFSResult());
52+
string expectedResult = "a(1,4) b(2,3) c(5,8) d(6,7)";
53+
EXPECT_EQ(actualResult, expectedResult);
54+
}
55+
56+
TEST(DFSTesting, ShowDFSResultTest_CyclicGraph)
57+
{
58+
DFSGraph graph;
59+
60+
graph.PushDirectedEdge('a', 'b');
61+
graph.PushDirectedEdge('b', 'c');
62+
graph.PushDirectedEdge('c', 'a');
63+
64+
graph.DFS();
65+
66+
string actualResult = unitTestHelperVectorOfPair.VerifyVectorOfPairOfTwo(graph.ShowDFSResult());
67+
string expectedResult = "a(1,6) b(2,5) c(3,4)";
68+
EXPECT_EQ(actualResult, expectedResult);
69+
}
70+
71+
TEST(DFSTesting, ShowDFSResultTest_LargeGraph)
72+
{
73+
DFSGraph graph;
74+
75+
// Adding 15 nodes with several edges
76+
graph.PushDirectedEdge('a', 'b');
77+
graph.PushDirectedEdge('a', 'c');
78+
graph.PushDirectedEdge('b', 'd');
79+
graph.PushDirectedEdge('d', 'e');
80+
graph.PushDirectedEdge('e', 'f');
81+
graph.PushDirectedEdge('f', 'g');
82+
graph.PushDirectedEdge('g', 'h');
83+
graph.PushDirectedEdge('h', 'i');
84+
graph.PushDirectedEdge('i', 'j');
85+
graph.PushDirectedEdge('j', 'k');
86+
graph.PushDirectedEdge('k', 'l');
87+
graph.PushDirectedEdge('l', 'm');
88+
graph.PushDirectedEdge('m', 'n');
89+
graph.PushDirectedEdge('n', 'o');
90+
graph.PushDirectedEdge('o', 'p');
91+
92+
graph.DFS();
93+
94+
string actualResult = unitTestHelperVectorOfPair.VerifyVectorOfPairOfTwo(graph.ShowDFSResult());
95+
string expectedResult = "a(1,32) b(2,29) c(30,31) d(3,28) e(4,27) f(5,26) g(6,25) h(7,24) i(8,23) j(9,22) k(10,21) l(11,20) m(12,19) n(13,18) o(14,17) p(15,16)";
96+
EXPECT_EQ(actualResult, expectedResult);
97+
}
98+
99+
TEST(DFSTesting, ShowDFSResultTest_NoEdges)
100+
{
101+
DFSGraph graph;
102+
103+
// Adding isolated nodes
104+
graph.PushDirectedEdge('a', 'a');
105+
graph.PushDirectedEdge('b', 'b');
106+
graph.PushDirectedEdge('c', 'c');
107+
108+
graph.DFS();
109+
110+
string actualResult = unitTestHelperVectorOfPair.VerifyVectorOfPairOfTwo(graph.ShowDFSResult());
111+
string expectedResult = "a(1,2) b(3,4) c(5,6)";
112+
EXPECT_EQ(actualResult, expectedResult);
113+
}
114+
115+
TEST(DFSTesting, ShowDFSResultTest_CyclicGraphWithBackEdges)
116+
{
117+
DFSGraph graph;
118+
119+
// Creating a cycle with back edges
120+
graph.PushDirectedEdge('a', 'b');
121+
graph.PushDirectedEdge('b', 'c');
122+
graph.PushDirectedEdge('c', 'a'); // Cycle back to 'a'
123+
graph.PushDirectedEdge('b', 'd'); // Back edge
124+
125+
graph.DFS();
126+
127+
string actualResult = unitTestHelperVectorOfPair.VerifyVectorOfPairOfTwo(graph.ShowDFSResult());
128+
string expectedResult = "a(1,8) b(2,7) c(3,4) d(5,6)";
129+
EXPECT_EQ(actualResult, expectedResult);
130+
}
131+
132+
TEST(DFSTesting, ShowDFSResultTest_DenseGraph)
133+
{
134+
DFSGraph graph;
135+
136+
// Complete graph of 4 nodes
137+
graph.PushDirectedEdge('a', 'b');
138+
graph.PushDirectedEdge('a', 'c');
139+
graph.PushDirectedEdge('a', 'd');
140+
graph.PushDirectedEdge('b', 'a');
141+
graph.PushDirectedEdge('b', 'c');
142+
graph.PushDirectedEdge('b', 'd');
143+
graph.PushDirectedEdge('c', 'a');
144+
graph.PushDirectedEdge('c', 'b');
145+
graph.PushDirectedEdge('c', 'd');
146+
graph.PushDirectedEdge('d', 'a');
147+
graph.PushDirectedEdge('d', 'b');
148+
graph.PushDirectedEdge('d', 'c');
149+
150+
graph.DFS();
151+
152+
string actualResult = unitTestHelperVectorOfPair.VerifyVectorOfPairOfTwo(graph.ShowDFSResult());
153+
string expectedResult = "a(1,8) b(2,7) c(3,6) d(4,5)";
154+
EXPECT_EQ(actualResult, expectedResult);
155+
}
156+
157+
TEST(DFSTesting, ShowDFSResultTest_SelfLoopsAndParallelEdges)
158+
{
159+
DFSGraph graph;
160+
161+
// Adding self-loops and parallel edges
162+
graph.PushDirectedEdge('a', 'a');
163+
graph.PushDirectedEdge('a', 'b');
164+
graph.PushDirectedEdge('b', 'b');
165+
graph.PushDirectedEdge('b', 'c');
166+
graph.PushDirectedEdge('b', 'c'); // Parallel edge
167+
graph.PushDirectedEdge('c', 'c'); // Self-loop
168+
169+
graph.DFS();
170+
171+
string actualResult = unitTestHelperVectorOfPair.VerifyVectorOfPairOfTwo(graph.ShowDFSResult());
172+
string expectedResult = "a(1,6) b(2,5) c(3,4)";
173+
EXPECT_EQ(actualResult, expectedResult);
174+
}
175+
28176
}

0 commit comments

Comments
 (0)