Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routers #12

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions Routers/Routers/GraphTest/GraphTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
namespace GraphTest;

using NUnit.Framework;
using Routers;

public class Tests
{
IGraph graph = new Graph();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
IGraph graph = new Graph();
private IGraph graph = new Graph();


[SetUp]
public void Setup()
{
graph = new Graph();
}

[Test]
public void ShouldExpectedFalseWhenIsTheGraphConnectedForDisconnectGraph()
{
graph.AddNode(2);
graph.AddNode(4);
graph.AddNode(6);
graph.AddNode(7);
graph.AddNode(1);
graph.AddNode(5);
graph.AddNode(9);
graph.AddNode(8);

graph.SetLength(6, 9, 12);
graph.SetLength(2, 4, 3);
graph.SetLength(2, 6, 4);
graph.SetLength(2, 7, 8);
graph.SetLength(2, 5, 2);
graph.SetLength(7, 8, 13);

Assert.False(graph.IsTheGraphConnected());
}

[Test]
public void ShouldExpectedTrueWhenIsTheGraphConnectedForGraphConsisting1Node()
{
graph.AddNode(2);
Assert.True(graph.IsTheGraphConnected());
}

[Test]
public void ShouldExpectedTrueWhenIsTheGraphConnectedForEmptyGraph()
{
Assert.True(graph.IsTheGraphConnected());
}

[Test]
public void ShouldThrowsDisconnectedGraphWhenBuildAcyclicGraphForDisconnectGraph()
{
graph.AddNode(2);
graph.AddNode(4);
graph.AddNode(6);
graph.AddNode(7);
graph.AddNode(1);
graph.AddNode(5);
graph.AddNode(9);
graph.AddNode(8);

graph.SetLength(2, 4, 3);
graph.SetLength(2, 6, 4);
graph.SetLength(2, 7, 8);
graph.SetLength(2, 5, 2);
graph.SetLength(7, 8, 13);

Assert.Throws<DisconnectedGraph>(() => graph.BuildAcyclicGraph());
}

[Test]
public void ShouldExpectedTrueWhenIsTheGraphConnectedForConnectedGraph()
{
graph.AddNode(2);
graph.AddNode(4);
graph.AddNode(6);
graph.AddNode(7);
graph.AddNode(1);
graph.AddNode(5);
graph.AddNode(9);
graph.AddNode(8);

graph.SetLength(1, 6, 12);
graph.SetLength(6, 9, 12);
graph.SetLength(2, 4, 3);
graph.SetLength(2, 6, 4);
graph.SetLength(2, 7, 8);
graph.SetLength(2, 5, 2);
graph.SetLength(7, 8, 13);

Assert.True(graph.IsTheGraphConnected());
}

[Test]
public void ShouldExpectedFalseWhenAddExistingNode()
{
graph.AddNode(2);
Assert.False(graph.AddNode(2));
}

[Test]
public void ShouldExpectedFalseWhenSetLengthForNonExistingNode()
{
Assert.False(graph.SetLength(2, 6, 4));
}

[Test]
public void DisconnectedGraph()
{
graph.BuildGraph("..//..//..//InputTest.txt");
Assert.Throws<DisconnectedGraph>(() => graph.BuildAcyclicGraph());
}
}
21 changes: 21 additions & 0 deletions Routers/Routers/GraphTest/GraphTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Routers\Routers.csproj" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions Routers/Routers/GraphTest/InputTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1 : 4 (3), 6 (5)
2 : 3 (8)
6 : 8 (12)
31 changes: 31 additions & 0 deletions Routers/Routers/Routers.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32228.430
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Routers", "Routers\Routers.csproj", "{78B74291-487A-4340-AE29-2114D18ED214}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphTest", "GraphTest\GraphTest.csproj", "{FC895312-F6AB-48CF-A16B-4B7E8CCB7A88}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{78B74291-487A-4340-AE29-2114D18ED214}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78B74291-487A-4340-AE29-2114D18ED214}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78B74291-487A-4340-AE29-2114D18ED214}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78B74291-487A-4340-AE29-2114D18ED214}.Release|Any CPU.Build.0 = Release|Any CPU
{FC895312-F6AB-48CF-A16B-4B7E8CCB7A88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC895312-F6AB-48CF-A16B-4B7E8CCB7A88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC895312-F6AB-48CF-A16B-4B7E8CCB7A88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC895312-F6AB-48CF-A16B-4B7E8CCB7A88}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {31700D31-9087-4D39-BA64-4DC5A05C25BE}
EndGlobalSection
EndGlobal
20 changes: 20 additions & 0 deletions Routers/Routers/Routers/Comparator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Routers;

using System.Collections.Generic;

public class Comparator : IComparer<int>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этой штуке тоже нужен комментарий

{
int IComparer<int>.Compare(int x, int y)
{
if (x > y)
{
return -1;
}
else if (x == y)
{
return 0;
}
return 1;
}
}

9 changes: 9 additions & 0 deletions Routers/Routers/Routers/DisconnectedGraphException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Routers;

/// <summary>
/// A class for creating custom exceptions
/// </summary>
public class DisconnectedGraph : Exception

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class DisconnectedGraph : Exception
public class DisconnectedGraphException : Exception

Все исключения в .NET именуются с суффиксом Exception

{
public DisconnectedGraph() : base() { }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это можно не писать, оно само сгенерится

}
44 changes: 44 additions & 0 deletions Routers/Routers/Routers/IGraph.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Routers;

public interface IGraph

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Интерфейсу тоже нужен комментарий, но я не уверен, что интерфейс нужен вообще

{
/// <summary>
/// Function for adding a node
/// </summary>
/// <param name="index">Node value</param>
/// <returns>Was there a value in the graph</returns>
public bool AddNode(int index);

/// <summary>
/// Function for creating an edge between vertices
/// </summary>
/// <param name="valueFirstNode">Value of the first node</param>
/// <param name="valueSecondNode">Value of the second node</param>
/// <param name="length">Edge length</param>
/// <returns>Was there an edge in the graph</returns>
public bool SetLength(int valueFirstNode, int valueSecondNode, int length);

/// <summary>
/// Function for constructing a new graph without cycles
/// </summary>
/// <returns>Acyclic graph, with maximum sum of edges</returns>
public Graph BuildAcyclicGraph();

/// <summary>
/// Function for graph construction
/// </summary>
/// <param name="pathToFile">The path to the file with the table</param>
public void BuildGraph(string pathToFile);

/// <summary>
/// Function for graph printing
/// </summary>
/// <param name="pathToFile">File path</param>
public void PrintGraph(string pathToFile);

/// <summary>
/// Function for checking the connectivity of a graph
/// </summary>
/// <returns>Is the graph connected</returns>
public bool IsTheGraphConnected();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше IsConnected — и так понятно, что речь про текущий граф, и он вряд ли The (если речь не про графа Дракулу, например).

}
Loading