diff --git a/.editorconfig b/.editorconfig index 8225c31..dc7a948 100644 --- a/.editorconfig +++ b/.editorconfig @@ -41,8 +41,22 @@ indent_size = 2 [*.cs] #IDE1006 -dotnet_naming_style.camel_case.capitalization = camel_case -dotnet_naming_symbols.private_symbols.applicable_accessibilities = private -dotnet_naming_rule.camel_case_for_private.severity = warning -dotnet_naming_rule.camel_case_for_private.symbols = private_symbols -dotnet_naming_rule.camel_case_for_private.style = camel_case +# Defining the 'all_methods' symbol group +dotnet_naming_symbols.all_methods.applicable_kinds = method +dotnet_naming_symbols.public_symbols.applicable_accessibilities = public +dotnet_naming_symbols.public_symbols.required_modifiers = readonly +# Defining the 'first_word_upper_case_style' naming style +dotnet_naming_style.camel_case_style.capitalization = camel_case + +# Defining the 'all_methods_must_be_camel_case' naming rule, by setting the +# symbol group to the 'public symbols' symbol group, +dotnet_naming_rule.all_methods_must_be_camel_case.symbols = all_methods +# setting the naming style to the 'first_word_upper_case_style' naming style, +dotnet_naming_rule.all_methods_must_be_camel_case.style = camel_case_style +# and setting the severity. +dotnet_naming_rule.all_methods_must_be_camel_case.severity = warning + +# Due clean code suggestion +[*.{cs,vb}] +dotnet_diagnostic.IDE0054.severity = none +dotnet_diagnostic.IDE0074.severity = none diff --git a/.vscode/settings.json b/.vscode/settings.json index 6120401..17ebf04 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,13 @@ { - "sonarlint.connectedMode.project": { - "connectionId": "sir-gon", - "projectKey": "sir-gon_algorithm-exercises-csharp" - }, - "editor.defaultFormatter": "ms-dotnettools.csdevkit", - "editor.formatOnSave": true + "sonarlint.connectedMode.project": { + "connectionId": "sir-gon", + "projectKey": "sir-gon_algorithm-exercises-csharp" + }, + "editor.formatOnSave": true, + "[csharp]": { + "editor.defaultFormatter": "ms-dotnettools.csharp" + }, + "[github-actions-workflow]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + } } diff --git a/algorithm-exercises-csharp-test/src/Hello.Test.cs b/algorithm-exercises-csharp-test/src/Hello.Test.cs index 16598fe..32b10ea 100644 --- a/algorithm-exercises-csharp-test/src/Hello.Test.cs +++ b/algorithm-exercises-csharp-test/src/Hello.Test.cs @@ -4,10 +4,10 @@ namespace algorithm_exercises_csharp; public class HelloWorldTest { [TestMethod] - public void TestInstance() + public void testInstance() { - HelloWorld a = HelloWorld.Create(); - HelloWorld b = HelloWorld.Create(); + HelloWorld a = HelloWorld.create(); + HelloWorld b = HelloWorld.create(); Type knownType = typeof(HelloWorld); Type resultType = a.GetType(); @@ -28,10 +28,10 @@ public void TestInstance() } [TestMethod] - public void TestHello() + public void testHello() { string expected = "Hello World!"; - string result = HelloWorld.Hello(); + string result = HelloWorld.hello(); Assert.AreEqual(expected, result); diff --git a/algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler001.Test.cs b/algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler001.Test.cs index 8c8d77e..58af132 100644 --- a/algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler001.Test.cs +++ b/algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler001.Test.cs @@ -17,13 +17,13 @@ public class Euler001TestCase ]; [TestMethod] - public void Euler001ProblemTest() + public void euler001Test() { int result; foreach (Euler001TestCase test in tests) { - result = Euler001Problem.Euler001(test.a, test.b, test.n); + result = Euler001.euler001(test.a, test.b, test.n); Assert.AreEqual(test.answer, result); } } diff --git a/algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler002.Test.cs b/algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler002.Test.cs index 7e2f0dd..a7ba75d 100644 --- a/algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler002.Test.cs +++ b/algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler002.Test.cs @@ -15,13 +15,13 @@ public class Euler002TestCase ]; [TestMethod] - public void Euler002ProblemTest() + public void euler002Test() { int result; foreach (Euler002TestCase test in tests) { - result = Euler002Problem.Euler002(test.n); + result = Euler002.euler002(test.n); Assert.AreEqual(test.answer, result); } } diff --git a/algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler003.Test.cs b/algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler003.Test.cs index 371ed2e..1ecc265 100644 --- a/algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler003.Test.cs +++ b/algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler003.Test.cs @@ -21,13 +21,13 @@ public class Euler003TestCase ]; [TestMethod] - public void Euler003ProblemTest() + public void euler003Test() { int? result; foreach (Euler003TestCase test in tests) { - result = Euler003Problem.Euler003(test.n); + result = Euler003.euler003(test.n); Assert.AreEqual(test.answer, result); } } diff --git a/algorithm-exercises-csharp-test/src/hackerrank/warmup/SolveMeFirst.Test.cs b/algorithm-exercises-csharp-test/src/hackerrank/warmup/SolveMeFirst.Test.cs index 1e2087b..00fc686 100644 --- a/algorithm-exercises-csharp-test/src/hackerrank/warmup/SolveMeFirst.Test.cs +++ b/algorithm-exercises-csharp-test/src/hackerrank/warmup/SolveMeFirst.Test.cs @@ -4,7 +4,7 @@ namespace algorithm_exercises_csharp; public class SolveMeFirstTest { [TestMethod] - public void TestSolveMeFirst() + public void testSolveMeFirst() { int expectedAnswer = 5; int a = 2; diff --git a/algorithm-exercises-csharp/src/Hello.cs b/algorithm-exercises-csharp/src/Hello.cs index bd49008..ada786a 100644 --- a/algorithm-exercises-csharp/src/Hello.cs +++ b/algorithm-exercises-csharp/src/Hello.cs @@ -4,17 +4,17 @@ namespace algorithm_exercises_csharp; public class HelloWorld { - const string message = "Hello World!"; + const string __message = "Hello World!"; [ExcludeFromCodeCoverage] protected HelloWorld() { } - public static string Hello() + public static string hello() { - return HelloWorld.message; + return __message; } - public static HelloWorld Create() + public static HelloWorld create() { return new HelloWorld(); } diff --git a/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler001.cs b/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler001.cs index 58c5266..3d5dc84 100644 --- a/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler001.cs +++ b/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler001.cs @@ -4,36 +4,36 @@ namespace algorithm_exercises_csharp.hackerrank.prohecteuler; using System.Diagnostics.CodeAnalysis; -public class Euler001Problem +public class Euler001 { [ExcludeFromCodeCoverage] - protected Euler001Problem() { } + protected Euler001() { } - public static int SuOfArithmeticProgression(int n, int d) + public static int sumOfArithmeticProgression(int n, int d) { int new_n = n / d; return new_n * (1 + new_n) * d / 2; } - public static int GCD(int u, int v) + public static int gcd(int u, int v) { if (v != 0) { - return GCD(v, u % v); + return gcd(v, u % v); } return u; } // Function to find the sum of all multiples of a and b below n - public static int Euler001(int a, int b, int n) + public static int euler001(int a, int b, int n) { // Since, we need the sum of multiples less than N int new_n = n - 1; - int lcm = a * b / GCD(a, b); + int lcm = a * b / gcd(a, b); - return SuOfArithmeticProgression(new_n, a) + - SuOfArithmeticProgression(new_n, b) - - SuOfArithmeticProgression(new_n, lcm); + return sumOfArithmeticProgression(new_n, a) + + sumOfArithmeticProgression(new_n, b) - + sumOfArithmeticProgression(new_n, lcm); } } diff --git a/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler002.cs b/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler002.cs index b70b7a4..31d97f6 100644 --- a/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler002.cs +++ b/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler002.cs @@ -4,12 +4,12 @@ namespace algorithm_exercises_csharp.hackerrank.prohecteuler; using System.Diagnostics.CodeAnalysis; -public class Euler002Problem +public class Euler002 { [ExcludeFromCodeCoverage] - protected Euler002Problem() { } + protected Euler002() { } - public static int FiboEvenSum(int n) + public static int fiboEvenSum(int n) { int total = 0; int fibo; @@ -32,8 +32,8 @@ public static int FiboEvenSum(int n) } // Function to find the sum of all multiples of a and b below n - public static int Euler002(int n) + public static int euler002(int n) { - return FiboEvenSum(n); + return fiboEvenSum(n); } } diff --git a/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler003.cs b/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler003.cs index a46a74a..65cc565 100644 --- a/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler003.cs +++ b/algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler003.cs @@ -4,12 +4,12 @@ namespace algorithm_exercises_csharp.hackerrank.prohecteuler; using System.Diagnostics.CodeAnalysis; -public class Euler003Problem +public class Euler003 { [ExcludeFromCodeCoverage] - protected Euler003Problem() { } + protected Euler003() { } - public static int? PrimeFactor(int n) + public static int? primeFactor(int n) { if (n < 2) { @@ -42,8 +42,8 @@ protected Euler003Problem() { } } // Function to find the sum of all multiples of a and b below n - public static int? Euler003(int n) + public static int? euler003(int n) { - return PrimeFactor(n); + return primeFactor(n); } }