@@ -63,6 +63,38 @@ public void DijkstraGraphShould_Find_Path_In_Override_Node()
63
63
Assert . True ( result . IsFounded ) ;
64
64
}
65
65
66
+ [ Fact ]
67
+ public void DijkstraSimpleGraphShould_Find_Path_In_Override_Node ( )
68
+ {
69
+ var graph = new Graph . Simple . Graph ( ) ;
70
+
71
+ graph . AddNode ( ) ;
72
+ graph . AddNode ( ) ;
73
+ graph . AddNode ( ) ;
74
+ graph . AddNode ( ) ;
75
+ graph . AddNode ( ) ;
76
+ graph . AddNode ( ) ;
77
+
78
+ graph . Connect ( 1 , 2 , 2 ) ;
79
+ graph . Connect ( 1 , 3 , 6 ) ;
80
+ graph . Connect ( 2 , 3 , 2 ) ;
81
+ graph . Connect ( 3 , 4 , 1 ) ;
82
+ graph . Connect ( 4 , 5 , 1 ) ;
83
+ graph . Connect ( 1 , 6 , 5 ) ;
84
+
85
+ var result = graph . Dijkstra ( 1 , 5 ) ;
86
+ uint [ ] path = result . GetPath ( ) . ToArray ( ) ;
87
+
88
+ Assert . Equal < uint > ( 1 , path [ 0 ] ) ;
89
+ Assert . Equal < uint > ( 2 , path [ 1 ] ) ;
90
+ Assert . Equal < uint > ( 3 , path [ 2 ] ) ;
91
+ Assert . Equal < uint > ( 4 , path [ 3 ] ) ;
92
+ Assert . Equal < uint > ( 5 , path [ 4 ] ) ;
93
+
94
+ Assert . Equal ( 6 , result . Distance ) ;
95
+ Assert . True ( result . IsFounded ) ;
96
+ }
97
+
66
98
[ Fact ]
67
99
public void DijkstraGraphShould_Find_Path_With_One_Vertex_In_Graph ( )
68
100
{
@@ -140,6 +172,39 @@ public void DijkstraGraphShould_Find_Path_In_Multi_Edges_Graph()
140
172
Assert . True ( result . IsFounded ) ;
141
173
}
142
174
175
+ [ Fact ]
176
+ public void DijkstraGraphShould_Find_Path_In_Multi_Edges_SimpleGraph ( )
177
+ {
178
+ var graph = new Graph . Simple . Graph ( ) ;
179
+
180
+ graph . AddNode ( ) ;
181
+ graph . AddNode ( ) ;
182
+ graph . AddNode ( ) ;
183
+ graph . AddNode ( ) ;
184
+ graph . AddNode ( ) ;
185
+ graph . AddNode ( ) ;
186
+
187
+ graph . Connect ( 1 , 2 , 2 ) ;
188
+ graph . Connect ( 1 , 3 , 3 ) ;
189
+ graph . Connect ( 2 , 4 , 4 ) ;
190
+ graph . Connect ( 3 , 4 , 3 ) ;
191
+ graph . Connect ( 3 , 4 , 2 ) ;
192
+ graph . Connect ( 3 , 4 , 4 ) ;
193
+ graph . Connect ( 3 , 5 , 1 ) ;
194
+ graph . Connect ( 4 , 6 , 6 ) ;
195
+
196
+ var result = graph . Dijkstra ( 1 , 6 ) ;
197
+ uint [ ] path = result . GetPath ( ) . ToArray ( ) ;
198
+
199
+ Assert . Equal < uint > ( 1 , path [ 0 ] ) ;
200
+ Assert . Equal < uint > ( 3 , path [ 1 ] ) ;
201
+ Assert . Equal < uint > ( 4 , path [ 2 ] ) ;
202
+ Assert . Equal < uint > ( 6 , path [ 3 ] ) ;
203
+
204
+ Assert . Equal ( 11 , result . Distance ) ;
205
+ Assert . True ( result . IsFounded ) ;
206
+ }
207
+
143
208
[ Fact ]
144
209
public void DijkstraGraphNot_Should_Find_Path_In_Graph ( )
145
210
{
@@ -163,6 +228,29 @@ public void DijkstraGraphNot_Should_Find_Path_In_Graph()
163
228
Assert . False ( result . IsFounded ) ;
164
229
}
165
230
231
+ [ Fact ]
232
+ public void DijkstraGraphNot_Should_Find_Path_In_SimpleGraph ( )
233
+ {
234
+ var graph = new Graph . Simple . Graph ( ) ;
235
+
236
+ graph . AddNode ( ) ;
237
+ graph . AddNode ( ) ;
238
+ graph . AddNode ( ) ;
239
+ graph . AddNode ( ) ;
240
+ graph . AddNode ( ) ;
241
+ graph . AddNode ( ) ;
242
+
243
+ graph . Connect ( 1 , 2 , 2 ) ;
244
+ graph . Connect ( 1 , 3 , 3 ) ;
245
+ graph . Connect ( 2 , 4 , 4 ) ;
246
+ graph . Connect ( 3 , 4 , 2 ) ;
247
+ graph . Connect ( 3 , 5 , 1 ) ;
248
+
249
+ var result = graph . Dijkstra ( 1 , 6 ) ;
250
+
251
+ Assert . False ( result . IsFounded ) ;
252
+ }
253
+
166
254
[ Fact ]
167
255
public void Dijkstra_Should_Concern_Depth_In_Graph ( )
168
256
{
@@ -188,5 +276,31 @@ public void Dijkstra_Should_Concern_Depth_In_Graph()
188
276
Assert . Equal ( ( uint ) 1 , path [ 0 ] ) ;
189
277
Assert . Equal ( ( uint ) 4 , path [ 1 ] ) ;
190
278
}
279
+
280
+ [ Fact ]
281
+ public void Dijkstra_Should_Concern_Depth_In_SimpleGraph ( )
282
+ {
283
+ var graph = new Graph . Simple . Graph ( ) ;
284
+
285
+ graph . AddNode ( ) ;
286
+ graph . AddNode ( ) ;
287
+ graph . AddNode ( ) ;
288
+ graph . AddNode ( ) ;
289
+
290
+ graph . Connect ( 1 , 2 , 1 ) ;
291
+ graph . Connect ( 1 , 3 , 1 ) ;
292
+ graph . Connect ( 1 , 4 , 5 ) ;
293
+ graph . Connect ( 3 , 4 , 2 ) ;
294
+
295
+ var result = graph . Dijkstra ( 1 , 4 , 1 ) ;
296
+
297
+ Assert . True ( result . IsFounded ) ;
298
+ Assert . Equal ( 5 , result . Distance ) ;
299
+
300
+ uint [ ] path = result . GetPath ( ) . ToArray ( ) ;
301
+
302
+ Assert . Equal ( ( uint ) 1 , path [ 0 ] ) ;
303
+ Assert . Equal ( ( uint ) 4 , path [ 1 ] ) ;
304
+ }
191
305
}
192
306
}
0 commit comments