Skip to content

Commit 3ce4443

Browse files
committed
Unit test for bellman fulkerson algorithm
1 parent 5370fec commit 3ce4443

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

AlgorithmsUnitTest/AlgorithmsUnitTest.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,4 @@
1919
<Name>Algorithms</Name>
2020
</ProjectReference>
2121
</ItemGroup>
22-
<ItemGroup>
23-
<Folder Include="Graphs\ShortestPath" />
24-
</ItemGroup>
2522
</Project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy