Skip to content

Commit 8946497

Browse files
committed
first commit
1 parent 2ed7a7b commit 8946497

File tree

4 files changed

+103
-15
lines changed

4 files changed

+103
-15
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="coverlet.collector" Version="6.0.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
15+
<PackageReference Include="NUnit" Version="3.14.0" />
16+
<PackageReference Include="Moq" Version="4.20.72" />
17+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
18+
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
19+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\Algorithms\Algorithms.csproj" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<Using Include="NUnit.Framework" />
28+
</ItemGroup>
29+
30+
</Project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using Algorithms.Graph.Dijkstra;
2+
using DataStructures.Graph;
3+
using FluentAssertions;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Algorithms.Dijktra.Tests
11+
{
12+
[TestFixture]
13+
public class DijkstraUTests
14+
{
15+
[Test]
16+
public void DijkstraTest1_BasicGraph()
17+
{
18+
var graph = new DirectedWeightedGraph<char>(4);
19+
var a = graph.AddVertex('A');
20+
var b = graph.AddVertex('B');
21+
var c = graph.AddVertex('C');
22+
var d = graph.AddVertex('D');
23+
24+
graph.AddEdge(a, b, 4);
25+
graph.AddEdge(a, c, 7);
26+
graph.AddEdge(b, c, 2);
27+
graph.AddEdge(b, d, 3);
28+
graph.AddEdge(c, d, 5);
29+
30+
31+
var shortestPathList = DijkstraAlgorithm.GenerateShortestPath(graph, a);
32+
shortestPathList.Length.Should().Be(4);
33+
34+
shortestPathList[0].PreviousVertex.Should().Be(a);
35+
shortestPathList[0].Vertex.Should().Be(a);
36+
shortestPathList[0].Distance.Should().Be(0);
37+
shortestPathList[0].ToString().Should()
38+
.Be($"From Previous Vertex: {a} to Vertex {a} is Distance: {0}");
39+
40+
shortestPathList[1].PreviousVertex.Should().Be(a);
41+
shortestPathList[1].Vertex.Should().Be(b);
42+
shortestPathList[1].Distance.Should().Be(4);
43+
shortestPathList[1].ToString().Should()
44+
.Be($"From Previous Vertex: {a} to Vertex {b} is Distance: {4}");
45+
46+
shortestPathList[2].PreviousVertex.Should().Be(b);
47+
shortestPathList[2].Vertex.Should().Be(c);
48+
shortestPathList[2].Distance.Should().Be(6);
49+
shortestPathList[2].ToString().Should()
50+
.Be($"From Previous Vertex: {b} to Vertex {c} is Distance: {6}");
51+
52+
shortestPathList[3].PreviousVertex.Should().Be(b);
53+
shortestPathList[3].Vertex.Should().Be(d);
54+
shortestPathList[3].Distance.Should().Be(7);
55+
shortestPathList[3].ToString().Should()
56+
.Be($"From Previous Vertex: {b} to Vertex {d} is Distance: {7}");
57+
}
58+
}
59+
}

Algorithms/Graph/Dijkstra/DistanceModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ public DistanceModel(Vertex<T>? vertex, Vertex<T>? previousVertex, double distan
2323
}
2424

2525
public override string ToString() =>
26-
$"Vertex: {Vertex} - Distance: {Distance} - Previous: {PreviousVertex}";
26+
$"From Previous Vertex: {PreviousVertex} to Vertex {Vertex} is Distance: {Distance}";
2727
}

C-Sharp.sln

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.28803.352
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.13.35818.85 d17.13
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{DAB16DEC-AF31-4B59-8DD5-5C76C1A23052}"
77
ProjectSection(SolutionItems) = preProject
@@ -21,16 +21,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Configs", "Configs", "{F3AC
2121
EndProject
2222
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Algorithms", "Algorithms\Algorithms.csproj", "{EC967159-73D8-4E44-8455-E2D16DB4CBBB}"
2323
EndProject
24-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Algorithms.Tests", "Algorithms.Tests\Algorithms.Tests.csproj", "{56817595-1552-409B-93B8-F8082F8490A5}"
25-
EndProject
2624
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataStructures", "DataStructures\DataStructures.csproj", "{E9C27C73-1F95-4C6E-9DB4-F8585426A850}"
2725
EndProject
28-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataStructures.Tests", "DataStructures.Tests\DataStructures.Tests.csproj", "{39174100-3A6E-45B2-9AA9-7C69764C0750}"
29-
EndProject
3026
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utilities", "Utilities\Utilities.csproj", "{3A41157D-296D-4BFC-A34E-91B5ED7F0905}"
3127
EndProject
3228
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utilities.Tests", "Utilities.Tests\Utilities.Tests.csproj", "{ED47E2E2-045C-41DD-B555-A64944D6C2F5}"
3329
EndProject
30+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTest", "UnitTest", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
31+
EndProject
32+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Algorithms.Dijktra.Tests", "Algorithms.Dijktra.Tests\Algorithms.Dijktra.Tests.csproj", "{D64DF824-C9E7-4696-BA83-1B87B7C4B5E1}"
33+
EndProject
3434
Global
3535
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3636
Debug|Any CPU = Debug|Any CPU
@@ -41,18 +41,10 @@ Global
4141
{EC967159-73D8-4E44-8455-E2D16DB4CBBB}.Debug|Any CPU.Build.0 = Debug|Any CPU
4242
{EC967159-73D8-4E44-8455-E2D16DB4CBBB}.Release|Any CPU.ActiveCfg = Release|Any CPU
4343
{EC967159-73D8-4E44-8455-E2D16DB4CBBB}.Release|Any CPU.Build.0 = Release|Any CPU
44-
{56817595-1552-409B-93B8-F8082F8490A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45-
{56817595-1552-409B-93B8-F8082F8490A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
46-
{56817595-1552-409B-93B8-F8082F8490A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
47-
{56817595-1552-409B-93B8-F8082F8490A5}.Release|Any CPU.Build.0 = Release|Any CPU
4844
{E9C27C73-1F95-4C6E-9DB4-F8585426A850}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4945
{E9C27C73-1F95-4C6E-9DB4-F8585426A850}.Debug|Any CPU.Build.0 = Debug|Any CPU
5046
{E9C27C73-1F95-4C6E-9DB4-F8585426A850}.Release|Any CPU.ActiveCfg = Release|Any CPU
5147
{E9C27C73-1F95-4C6E-9DB4-F8585426A850}.Release|Any CPU.Build.0 = Release|Any CPU
52-
{39174100-3A6E-45B2-9AA9-7C69764C0750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53-
{39174100-3A6E-45B2-9AA9-7C69764C0750}.Debug|Any CPU.Build.0 = Debug|Any CPU
54-
{39174100-3A6E-45B2-9AA9-7C69764C0750}.Release|Any CPU.ActiveCfg = Release|Any CPU
55-
{39174100-3A6E-45B2-9AA9-7C69764C0750}.Release|Any CPU.Build.0 = Release|Any CPU
5648
{3A41157D-296D-4BFC-A34E-91B5ED7F0905}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5749
{3A41157D-296D-4BFC-A34E-91B5ED7F0905}.Debug|Any CPU.Build.0 = Debug|Any CPU
5850
{3A41157D-296D-4BFC-A34E-91B5ED7F0905}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -61,10 +53,17 @@ Global
6153
{ED47E2E2-045C-41DD-B555-A64944D6C2F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
6254
{ED47E2E2-045C-41DD-B555-A64944D6C2F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
6355
{ED47E2E2-045C-41DD-B555-A64944D6C2F5}.Release|Any CPU.Build.0 = Release|Any CPU
56+
{D64DF824-C9E7-4696-BA83-1B87B7C4B5E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57+
{D64DF824-C9E7-4696-BA83-1B87B7C4B5E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
58+
{D64DF824-C9E7-4696-BA83-1B87B7C4B5E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
59+
{D64DF824-C9E7-4696-BA83-1B87B7C4B5E1}.Release|Any CPU.Build.0 = Release|Any CPU
6460
EndGlobalSection
6561
GlobalSection(SolutionProperties) = preSolution
6662
HideSolutionNode = FALSE
6763
EndGlobalSection
64+
GlobalSection(NestedProjects) = preSolution
65+
{D64DF824-C9E7-4696-BA83-1B87B7C4B5E1} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
66+
EndGlobalSection
6867
GlobalSection(ExtensibilityGlobals) = postSolution
6968
SolutionGuid = {9D733AD8-7C69-4F40-ADBB-2DD8EA9F18FB}
7069
EndGlobalSection

0 commit comments

Comments
 (0)