Skip to content

Commit 3849865

Browse files
authored
Merge pull request #30 from matiii/feature/depth-dijkstra
Implementation of depth in Dijkstra
2 parents 9e17684 + e2207f0 commit 3849865

26 files changed

+83
-841
lines changed

src/Dijkstra.NET.Benchmark/BenchmarkIt.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,28 @@ namespace Dijkstra.NET.Benchmark
1111
[MemoryDiagnoser]
1212
public class BenchmarkIt
1313
{
14-
private readonly DijkstraBenchmarkBase _dijkstra;
15-
private readonly DijkstraBenchmarkBase _bfs;
16-
1714
public BenchmarkIt()
1815
{
19-
_dijkstra = new DijkstraBenchmark();
20-
_bfs = new BfsParallelBenchmark();
2116
}
2217

2318
[GlobalSetup]
2419
public void Initialise()
2520
{
2621
Console.WriteLine("--- Global Setup ---");
27-
28-
_dijkstra.Initialise();
2922
}
3023

3124
[IterationSetup]
3225
public void IterationSetup()
3326
{
3427
Console.WriteLine("--- Iteration Setup ---");
35-
36-
_dijkstra.Setup();
3728
}
3829

3930
[Benchmark(Baseline = true)]
40-
public int DijkstraBenchmark()
41-
{
42-
var result = _dijkstra.GetPath();
43-
44-
return result.GetPath().Count();
45-
}
46-
47-
[Benchmark]
4831
public int DijkstraExtensionBenchmark()
4932
{
5033
var result = DijkstraBenchmarkBase.Graph.Dijkstra(DijkstraBenchmarkBase.From, DijkstraBenchmarkBase.To);
5134

5235
return result.GetPath().Count();
5336
}
54-
55-
[Benchmark]
56-
public int BfsBenchmark()
57-
{
58-
var result = _bfs.GetPath();
59-
60-
return result.GetPath().Count();
61-
}
6237
}
6338
}

src/Dijkstra.NET.Benchmark/BfsParallelBenchmark.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Dijkstra.NET.Benchmark/Dijkstra.NET.Benchmark.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@
137137
</ItemGroup>
138138
<ItemGroup>
139139
<Compile Include="BenchmarkIt.cs" />
140-
<Compile Include="BfsParallelBenchmark.cs" />
141-
<Compile Include="DijkstraBenchmark.cs" />
142140
<Compile Include="DijkstraBenchmarkBase.cs" />
143141
<Compile Include="Program.cs" />
144142
<Compile Include="Properties\AssemblyInfo.cs" />

src/Dijkstra.NET.Benchmark/DijkstraBenchmark.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Dijkstra.NET.Benchmark/DijkstraBenchmarkBase.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,5 @@ public void Initialise()
4444
From = 0;
4545
To = Nodes - 1;
4646
}
47-
48-
public void Setup()
49-
{
50-
Graph.Reset();
51-
}
52-
53-
public abstract IShortestPathResult GetPath();
5447
}
5548
}

src/Dijkstra.NET.Tests/BfsParallelTest.cs

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/Dijkstra.NET.Tests/DijkstraTest.cs

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/Dijkstra.NET.Tests/Extensions/ShortestPathExtensionsTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ public void DijkstraGraphShould_Find_Path_With_One_Vertex_In_Graph()
8484
Assert.True(result.IsFounded);
8585
}
8686

87+
[Fact]
88+
public void DijkstraGraphShould_Find_Path_With_One_Vertex_In_Graph_And_Depth_Zero()
89+
{
90+
var graph = new Graph<int, string>();
91+
graph.AddNode(0);
92+
93+
var result = graph.Dijkstra(0, 0, 0);
94+
uint[] path = result.GetPath().ToArray();
95+
96+
Assert.Equal<uint>(0, path[0]);
97+
Assert.Equal(0, result.Distance);
98+
Assert.True(result.IsFounded);
99+
}
100+
87101
[Fact]
88102
public void DijkstraGraphShould_Find_Path_With_One_Vertex_And_One_Edge_In_Graph()
89103
{
@@ -155,5 +169,31 @@ public void DijkstraGraphNot_Should_Find_Path_In_Graph()
155169

156170
Assert.False(result.IsFounded);
157171
}
172+
173+
[Fact]
174+
public void Dijkstra_Should_Concern_Depth_In_Graph()
175+
{
176+
var graph = new Graph<int, string>();
177+
178+
graph.AddNode(0);
179+
graph.AddNode(0);
180+
graph.AddNode(0);
181+
graph.AddNode(0);
182+
183+
graph.Connect(0, 1, 1, null);
184+
graph.Connect(0, 2, 1, null);
185+
graph.Connect(0, 3, 5, null);
186+
graph.Connect(2, 3, 2, null);
187+
188+
var result = graph.Dijkstra(0, 3, 1);
189+
190+
Assert.True(result.IsFounded);
191+
Assert.Equal(5, result.Distance);
192+
193+
uint[] path = result.GetPath().ToArray();
194+
195+
Assert.Equal((uint)0, path[0]);
196+
Assert.Equal((uint)3, path[1]);
197+
}
158198
}
159199
}

0 commit comments

Comments
 (0)