File tree Expand file tree Collapse file tree 2 files changed +55
-3
lines changed Expand file tree Collapse file tree 2 files changed +55
-3
lines changed Original file line number Diff line number Diff line change 19
19
<Name >Algorithms</Name >
20
20
</ProjectReference >
21
21
</ItemGroup >
22
- <ItemGroup >
23
- <Folder Include =" Graphs\ShortestPath" />
24
- </ItemGroup >
25
22
</Project >
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Text ;
4
+ using Algorithms . DataStructures . Graphs ;
5
+ using Algorithms . Graphs . ShortestPaths ;
6
+ using Xunit ;
7
+ using Xunit . Abstractions ;
8
+
9
+ namespace AlgorithmsUnitTest . Graphs . ShortestPaths
10
+ {
11
+ public class BellmanFulkersonUnitTest
12
+ {
13
+ private ITestOutputHelper console ;
14
+
15
+ public BellmanFulkersonUnitTest ( ITestOutputHelper console )
16
+ {
17
+ this . console = console ;
18
+ }
19
+
20
+ [ Fact ]
21
+ public void Test ( )
22
+ {
23
+ WeightedDiGraph G = GraphGenerator . directedEdgeWeightedGraph ( ) ;
24
+ BellmanFulkerson BellmanFulkerson = new BellmanFulkerson ( G , 0 ) ;
25
+ for ( var v = 1 ; v < G . V ( ) ; ++ v )
26
+ {
27
+ if ( ! BellmanFulkerson . HasPathTo ( v ) )
28
+ {
29
+ Console . WriteLine ( "Path not found for {0}" , v ) ;
30
+ continue ;
31
+ }
32
+ IEnumerable < Edge > path = BellmanFulkerson . PathTo ( v ) ;
33
+
34
+ console . WriteLine ( ToString ( path ) ) ;
35
+ Console . WriteLine ( ToString ( path ) ) ;
36
+ }
37
+ }
38
+
39
+ private String ToString ( IEnumerable < Edge > path )
40
+ {
41
+ StringBuilder sb = new StringBuilder ( ) ;
42
+ bool first = true ;
43
+ foreach ( var e in path )
44
+ {
45
+ if ( first )
46
+ {
47
+ first = false ;
48
+ sb . Append ( e . from ( ) ) ;
49
+ }
50
+ sb . Append ( "=(" ) . Append ( e . Weight ) . Append ( ")=>" ) . Append ( e . to ( ) ) ;
51
+ }
52
+ return sb . ToString ( ) ;
53
+ }
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments