diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab7c0aa..eede0b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: windows-latest steps: - uses: actions/checkout@v3 - name: Setup .NET diff --git a/Algorithms/Graphs/Pathfinding/BreadthFirstSearch.cs b/Algorithms/Graphs/Pathfinding/BreadthFirstSearch.cs index ef5e420..029d936 100644 --- a/Algorithms/Graphs/Pathfinding/BreadthFirstSearch.cs +++ b/Algorithms/Graphs/Pathfinding/BreadthFirstSearch.cs @@ -11,10 +11,10 @@ public void Run(IGraph graph, Vertex start) { 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. @@ -38,7 +38,7 @@ public void Run(IGraph graph, Vertex start) } } - private void Initialize(IGraph graph, Vertex start) + private static void Initialize(IGraph graph, Vertex start) { //Every vertex is initialized with the maximum possible distance to signify that the distance is invalid. foreach (Vertex vertex in graph.Vertices) diff --git a/Algorithms/Graphs/Pathfinding/DepthFirstSearch.cs b/Algorithms/Graphs/Pathfinding/DepthFirstSearch.cs index 977ebb9..6a4f0f5 100644 --- a/Algorithms/Graphs/Pathfinding/DepthFirstSearch.cs +++ b/Algorithms/Graphs/Pathfinding/DepthFirstSearch.cs @@ -13,10 +13,10 @@ public void Run(IGraph 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; @@ -55,7 +55,7 @@ private int RunRecursively(IGraph graph, Vertex start, int return startTime; } - private void Initialize(IGraph graph) + private static void Initialize(IGraph graph) { foreach (Vertex vertex in graph.Vertices) { diff --git a/Datastructures/Collections/Queue.cs b/Datastructures/Collections/Queue.cs index 0c70264..a56fcc1 100644 --- a/Datastructures/Collections/Queue.cs +++ b/Datastructures/Collections/Queue.cs @@ -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 { private readonly T[] cache; - private int headIndex = 0; - private int tailIndex = 0; + private int headIndex; + private int tailIndex; public Queue(int capacity) { diff --git a/Datastructures/Collections/Stack.cs b/Datastructures/Collections/Stack.cs index 09423f1..108a9ed 100644 --- a/Datastructures/Collections/Stack.cs +++ b/Datastructures/Collections/Stack.cs @@ -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 { //-1 means that there are no items in the cache yet diff --git a/Datastructures/Graphs/Edge.cs b/Datastructures/Graphs/Edge.cs index 85273bb..27cd43a 100644 --- a/Datastructures/Graphs/Edge.cs +++ b/Datastructures/Graphs/Edge.cs @@ -5,17 +5,17 @@ namespace LunarDoggo.Datastructures.Graphs public class Edge { /// - public Edge(Vertex from, Vertex to, bool bidirectional) + public Edge(Vertex from, Vertex 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; } /// diff --git a/Datastructures/Graphs/IGraph.cs b/Datastructures/Graphs/IGraph.cs index 4a49877..e042a79 100644 --- a/Datastructures/Graphs/IGraph.cs +++ b/Datastructures/Graphs/IGraph.cs @@ -24,7 +24,7 @@ public interface IGraph /// /// Removes an existing Edge from to from the graph /// - void RemoveEdge(Vertex from, Vertex to); + void RemoveEdge(Vertex from, Vertex target); } //Unweighted graphs can also be described as graphs where every edge has the same weight of a constant c. @@ -42,7 +42,7 @@ public interface IUnweightedGraph : IGraph /// directed or undirected depends on the implementation used /// /// - Edge AddEdge(Vertex from, Vertex to); + Edge AddEdge(Vertex from, Vertex target); } /// @@ -55,7 +55,7 @@ public interface IWeightedGraph : IGraph /// to the graph. If the edge is directed or undirected depends on the implementation used /// /// - Edge AddEdge(Vertex from, Vertex to, float weight); + Edge AddEdge(Vertex from, Vertex target, float weight); /// /// Returns the weight of the provided /// diff --git a/Datastructures/Graphs/UndirectedUnweightedGraph.cs b/Datastructures/Graphs/UndirectedUnweightedGraph.cs index 9d0cb27..e2ba6ee 100644 --- a/Datastructures/Graphs/UndirectedUnweightedGraph.cs +++ b/Datastructures/Graphs/UndirectedUnweightedGraph.cs @@ -12,9 +12,9 @@ public class UndirectedUnweightedGraph : IUnweightedGraph public IEnumerable> Vertices { get => this.vertices.ToArray(); } public IEnumerable> Edges { get => this.edges.ToArray(); } - private int lastId = 0; + private int lastId; - public Edge AddEdge(Vertex from, Vertex to) + public Edge AddEdge(Vertex from, Vertex target) { //this lock ensures thread safety when adding edges, as multithreaded Add operations without locks can lead to null //entries in the collection @@ -22,12 +22,12 @@ public Edge AddEdge(Vertex from, Vertex to) { //The ArgumentNullException advertised in the definition of AddEdge in IUnweightedGraph will be thrown by the //constructor of Edge, therefore it isn't necessary to check from and to for null values here - Edge edge = new Edge(from, to, true); + Edge edge = new Edge(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; } @@ -47,17 +47,17 @@ public Vertex AddVertex(T value) } } - public void RemoveEdge(Vertex from, Vertex to) + public void RemoveEdge(Vertex from, Vertex 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 edge = new Edge(from, to, true); + Edge edge = new Edge(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); } } diff --git a/Projects/LunarDoggo.Beginners.ConsoleIO/Program.cs b/Projects/LunarDoggo.Beginners.ConsoleIO/Program.cs index 021635d..4870e44 100644 --- a/Projects/LunarDoggo.Beginners.ConsoleIO/Program.cs +++ b/Projects/LunarDoggo.Beginners.ConsoleIO/Program.cs @@ -4,7 +4,7 @@ namespace LunarDoggo.ConsoleIO { - class Program + sealed class Program { /// /// This is the entrypoint to your application. When you execute your application, this method is called with the parameters diff --git a/Projects/LunarDoggo.Beginners.ConsoleIOValidation/Program.cs b/Projects/LunarDoggo.Beginners.ConsoleIOValidation/Program.cs index 3720373..7a77b33 100644 --- a/Projects/LunarDoggo.Beginners.ConsoleIOValidation/Program.cs +++ b/Projects/LunarDoggo.Beginners.ConsoleIOValidation/Program.cs @@ -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 diff --git a/Projects/LunarDoggo.FileSystemTree/Program.cs b/Projects/LunarDoggo.FileSystemTree/Program.cs index 193af99..f8852d5 100644 --- a/Projects/LunarDoggo.FileSystemTree/Program.cs +++ b/Projects/LunarDoggo.FileSystemTree/Program.cs @@ -6,7 +6,7 @@ namespace LunarDoggo.FileSystemTree { - class Program + sealed class Program { static void Main(string[] args) { @@ -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) { diff --git a/Projects/LunarDoggo.QuizGame/IO/FileQuizQuestionSerializer.cs b/Projects/LunarDoggo.QuizGame/IO/FileQuizQuestionSerializer.cs index 0284556..e1df9dc 100644 --- a/Projects/LunarDoggo.QuizGame/IO/FileQuizQuestionSerializer.cs +++ b/Projects/LunarDoggo.QuizGame/IO/FileQuizQuestionSerializer.cs @@ -22,9 +22,9 @@ public FileQuizQuestionSerializer(string filePath) public IEnumerable DeserializeQuestions() { - string content = this.GetFileContent(this.filePath); - IEnumerable questions = this.DeserializeJson(content); - this.SetGuids(questions); + string content = FileQuizQuestionSerializer.GetFileContent(this.filePath); + IEnumerable questions = FileQuizQuestionSerializer.DeserializeJson(content); + FileQuizQuestionSerializer.SetGuids(questions); return questions; } @@ -32,7 +32,7 @@ public IEnumerable DeserializeQuestions() ///We don't trust the user to correctly set the Ids of the and . In order to prevent duplicate Ids ///this method assigns a unique to every and its s /// - private void SetGuids(IEnumerable questions) + private static void SetGuids(IEnumerable questions) { foreach (QuizQuestion question in questions) { @@ -45,7 +45,7 @@ private void SetGuids(IEnumerable questions) } } - private IEnumerable DeserializeJson(string content) + private static IEnumerable DeserializeJson(string content) { JsonSerializerOptions options = new JsonSerializerOptions() { @@ -59,7 +59,7 @@ private IEnumerable DeserializeJson(string content) return JsonSerializer.Deserialize(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 diff --git a/Projects/LunarDoggo.QuizGame/Visuals/ConsoleVisualizer.cs b/Projects/LunarDoggo.QuizGame/Visuals/ConsoleVisualizer.cs index 2021f0d..cfdedec 100644 --- a/Projects/LunarDoggo.QuizGame/Visuals/ConsoleVisualizer.cs +++ b/Projects/LunarDoggo.QuizGame/Visuals/ConsoleVisualizer.cs @@ -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} diff --git a/Projects/LunarDoggo.TicTacToe/LunarDoggo.TicTacToe.csproj b/Projects/LunarDoggo.TicTacToe/LunarDoggo.TicTacToe.csproj index af74345..d8f225d 100644 --- a/Projects/LunarDoggo.TicTacToe/LunarDoggo.TicTacToe.csproj +++ b/Projects/LunarDoggo.TicTacToe/LunarDoggo.TicTacToe.csproj @@ -14,6 +14,7 @@ 4 true true + true AnyCPU