Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
Expand Down
6 changes: 3 additions & 3 deletions Algorithms/Graphs/Pathfinding/BreadthFirstSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
//In simple graphs |E| is bounded by O(|V|^2), so in such cases, one could use O(|V|^2) as the time complexity
public class BreadthFirstSearch
{
public void Run(IGraph<BFSVertex> graph, Vertex<BFSVertex> start)

Check failure on line 10 in Algorithms/Graphs/Pathfinding/BreadthFirstSearch.cs

View workflow job for this annotation

GitHub Actions / build

Member 'Run' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check failure on line 10 in Algorithms/Graphs/Pathfinding/BreadthFirstSearch.cs

View workflow job for this annotation

GitHub Actions / build

Member 'Run' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)
{
if (graph is null)
{
throw new ArgumentNullException("The graph the DFS should be run on cannot be null");
throw new ArgumentNullException(nameof(graph), "The graph the DFS should be run on cannot be null");
}

this.Initialize(graph, start);
BreadthFirstSearch.Initialize(graph, start);

//BFS is usually implemented in a way that doesn't work on disconnected graphs. BFS can therefore be
//used to find all vertices contained in a connected component of the graph.
Expand All @@ -38,7 +38,7 @@
}
}

private void Initialize(IGraph<BFSVertex> graph, Vertex<BFSVertex> start)
private static void Initialize(IGraph<BFSVertex> graph, Vertex<BFSVertex> start)
{
//Every vertex is initialized with the maximum possible distance to signify that the distance is invalid.
foreach (Vertex<BFSVertex> vertex in graph.Vertices)
Expand Down
6 changes: 3 additions & 3 deletions Algorithms/Graphs/Pathfinding/DepthFirstSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public void Run(IGraph<DFSVertex> graph)
{
if (graph is null)
{
throw new ArgumentNullException("The graph the DFS should be run on cannot be null");
throw new ArgumentNullException(nameof(graph), "The graph the DFS should be run on cannot be null");
}

this.Initialize(graph);
DepthFirstSearch.Initialize(graph);
//Current processing time
int time = 0;

Expand Down Expand Up @@ -55,7 +55,7 @@ private int RunRecursively(IGraph<DFSVertex> graph, Vertex<DFSVertex> start, int
return startTime;
}

private void Initialize(IGraph<DFSVertex> graph)
private static void Initialize(IGraph<DFSVertex> graph)
{
foreach (Vertex<DFSVertex> vertex in graph.Vertices)
{
Expand Down
5 changes: 3 additions & 2 deletions Datastructures/Collections/Queue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ namespace LunarDoggo.Datastructures.Collections
//runs full and another object is enqueued, an exception is thrown. Additionally, as the oldest items are
//dequeued first, one must keep track of the current head and tail of the queue, as it will no longer be
//guaranteed that the item at index 0 is the next item to be dequeued
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
public class Queue<T>
{
private readonly T[] cache;
private int headIndex = 0;
private int tailIndex = 0;
private int headIndex;
private int tailIndex;

public Queue(int capacity)
{
Expand Down
1 change: 1 addition & 0 deletions Datastructures/Collections/Stack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace LunarDoggo.Datastructures.Collections
//The most primitive implementation uses an array that's not resized over the stack's lifetime. If the stack
//runs full and another object is added, an exception is thrown signifying that no more items can be pushed
//onto the stack
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
public class Stack<T>
{
//-1 means that there are no items in the cache yet
Expand Down
8 changes: 4 additions & 4 deletions Datastructures/Graphs/Edge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ namespace LunarDoggo.Datastructures.Graphs
public class Edge<T>
{
/// <exception cref="ArgumentNullException"></exception>
public Edge(Vertex<T> from, Vertex<T> to, bool bidirectional)
public Edge(Vertex<T> from, Vertex<T> target, bool bidirectional)
{
//this check helps to avoid NullReferenceExceptions down the line
if (from is null || to is null)
if (from is null || target is null)
{
throw new ArgumentNullException("None of the vertices of an edge can be null!");
throw new ArgumentNullException(from is null ? nameof(from) : nameof(target), "None of the vertices of an edge can be null!");
}

this.IsBidirectional = bidirectional;
this.From = from;
this.To = to;
this.To = target;
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Datastructures/Graphs/IGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IGraph<T>
/// <summary>
/// Removes an existing Edge from <paramref name="from"/> to <paramref name="to"/> from the graph
/// </summary>
void RemoveEdge(Vertex<T> from, Vertex<T> to);
void RemoveEdge(Vertex<T> from, Vertex<T> target);
}

//Unweighted graphs can also be described as graphs where every edge has the same weight of a constant c.
Expand All @@ -42,7 +42,7 @@ public interface IUnweightedGraph<T> : IGraph<T>
/// directed or undirected depends on the implementation used
/// </summary>
/// <exception cref="ArgumentNullException"></exception>
Edge<T> AddEdge(Vertex<T> from, Vertex<T> to);
Edge<T> AddEdge(Vertex<T> from, Vertex<T> target);
}

/// <summary>
Expand All @@ -55,7 +55,7 @@ public interface IWeightedGraph<T> : IGraph<T>
/// to the graph. If the edge is directed or undirected depends on the implementation used
/// </summary>
/// <exception cref="ArgumentNullException"></exception>
Edge<T> AddEdge(Vertex<T> from, Vertex<T> to, float weight);
Edge<T> AddEdge(Vertex<T> from, Vertex<T> target, float weight);
/// <summary>
/// Returns the weight of the provided <see cref="Edge{T}"/>
/// </summary>
Expand Down
18 changes: 9 additions & 9 deletions Datastructures/Graphs/UndirectedUnweightedGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ public class UndirectedUnweightedGraph<T> : IUnweightedGraph<T>
public IEnumerable<Vertex<T>> Vertices { get => this.vertices.ToArray(); }
public IEnumerable<Edge<T>> Edges { get => this.edges.ToArray(); }

private int lastId = 0;
private int lastId;

public Edge<T> AddEdge(Vertex<T> from, Vertex<T> to)
public Edge<T> AddEdge(Vertex<T> from, Vertex<T> target)
{
//this lock ensures thread safety when adding edges, as multithreaded Add operations without locks can lead to null
//entries in the collection
lock (this.edges)
{
//The ArgumentNullException advertised in the definition of AddEdge in IUnweightedGraph will be thrown by the
//constructor of Edge<T>, therefore it isn't necessary to check from and to for null values here
Edge<T> edge = new Edge<T>(from, to, true);
Edge<T> edge = new Edge<T>(from, target, true);

//As the edge and adjacencies are stored in HashSets, it isn't necessary to check if it already exists
this.edges.Add(edge);
from.AddAdjacency(to);
to.AddAdjacency(from);
from.AddAdjacency(target);
target.AddAdjacency(from);

return edge;
}
Expand All @@ -47,17 +47,17 @@ public Vertex<T> AddVertex(T value)
}
}

public void RemoveEdge(Vertex<T> from, Vertex<T> to)
public void RemoveEdge(Vertex<T> from, Vertex<T> target)
{
lock (this.edges)
{
//As edges that contain the same values are considered equal and all edges are stored in a HashSet,
//edges can be removed by removing a new and equal edge from edges
Edge<T> edge = new Edge<T>(from, to, true);
Edge<T> edge = new Edge<T>(from, target, true);
this.edges.Remove(edge);
//The adjacency lists of the vertices also have to be updated
from.RemoveAdjacency(to);
to.RemoveAdjacency(from);
from.RemoveAdjacency(target);
target.RemoveAdjacency(from);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Projects/LunarDoggo.Beginners.ConsoleIO/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace LunarDoggo.ConsoleIO
{
class Program
sealed class Program
{
/// <summary>
/// This is the entrypoint to your application. When you execute your application, this method is called with the parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace LunarDoggo.ConsoleIOValidation
{
class Program
sealed class Program
{
/*
* you can declare and initialize variables outside of methods. Note, that a variable must be static
Expand Down
4 changes: 2 additions & 2 deletions Projects/LunarDoggo.FileSystemTree/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace LunarDoggo.FileSystemTree
{
class Program
sealed class Program
{
static void Main(string[] args)
{
Expand All @@ -28,7 +28,7 @@ private static void OutputFileSystemTreeLevel(int indentationLevel, FileSystemTr

//if the current tree item has any children, recursively print them and
//their children to the console with the corresponding indentatino level
if (item.Children != null && item.Children.Count() > 0)
if (item.Children != null && item.Children.Any())
{
foreach (FileSystemTreeItem child in item.Children)
{
Expand Down
12 changes: 6 additions & 6 deletions Projects/LunarDoggo.QuizGame/IO/FileQuizQuestionSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ public FileQuizQuestionSerializer(string filePath)

public IEnumerable<QuizQuestion> DeserializeQuestions()
{
string content = this.GetFileContent(this.filePath);
IEnumerable<QuizQuestion> questions = this.DeserializeJson(content);
this.SetGuids(questions);
string content = FileQuizQuestionSerializer.GetFileContent(this.filePath);
IEnumerable<QuizQuestion> questions = FileQuizQuestionSerializer.DeserializeJson(content);
FileQuizQuestionSerializer.SetGuids(questions);
return questions;
}

/// <summary>
///We don't trust the user to correctly set the Ids of the <see cref="QuizQuestion"/> and <see cref="QuizQuestionAnswer"/>. In order to prevent duplicate Ids
///this method assigns a unique <see cref="Guid"/> to every <see cref="QuizQuestion"/> and its <see cref="QuizQuestionAnswer"/>s
/// </summary>
private void SetGuids(IEnumerable<QuizQuestion> questions)
private static void SetGuids(IEnumerable<QuizQuestion> questions)
{
foreach (QuizQuestion question in questions)
{
Expand All @@ -45,7 +45,7 @@ private void SetGuids(IEnumerable<QuizQuestion> questions)
}
}

private IEnumerable<QuizQuestion> DeserializeJson(string content)
private static IEnumerable<QuizQuestion> DeserializeJson(string content)
{
JsonSerializerOptions options = new JsonSerializerOptions()
{
Expand All @@ -59,7 +59,7 @@ private IEnumerable<QuizQuestion> DeserializeJson(string content)
return JsonSerializer.Deserialize<QuizQuestion[]>(content, options);
}

private string GetFileContent(string filePath)
private static string GetFileContent(string filePath)
{
//Check if the file exists, if not, return an empty string to prevent a FileNotFoundException, otherwise return the files content
//Note that file access violations (e. g. another application has the file locked) are not handled and will lead to an exception
Expand Down
4 changes: 2 additions & 2 deletions Projects/LunarDoggo.QuizGame/Visuals/ConsoleVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public void DrawQuizQuestion(QuizQuestion question, Guid highlitedAnswerId)
Console.WriteLine();
foreach (QuizQuestionAnswer answer in question.Answers)
{
this.DrawQuizQuestionAnswer(answer, answer.Id == highlitedAnswerId);
ConsoleVisualizer.DrawQuizQuestionAnswer(answer, answer.Id == highlitedAnswerId);
}
Console.WriteLine();
Console.WriteLine();
}

private void DrawQuizQuestionAnswer(QuizQuestionAnswer answer, bool highlited)
private static void DrawQuizQuestionAnswer(QuizQuestionAnswer answer, bool highlited)
{
Console.SetCursorPosition(1, Console.CursorTop);
//you can write on line conditional statements in the format: {boolean expression} ? {action when the condition is met} : {action when the condition isn't met}
Expand Down
1 change: 1 addition & 0 deletions Projects/LunarDoggo.TicTacToe/LunarDoggo.TicTacToe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
Loading