Skip to content

Commit 2a63eae

Browse files
authored
Merge pull request #208 from sir-gon/feature/refactor
Feature/refactor
2 parents ca0139e + d9b5559 commit 2a63eae

File tree

69 files changed

+927
-478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+927
-478
lines changed

.editorconfig

+20
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ dotnet_naming_rule.all_methods_must_be_camel_case.style = camel_case_style
5757
dotnet_naming_rule.all_methods_must_be_camel_case.severity = warning
5858

5959
# Due clean code suggestion
60+
61+
# CA1034: Los tipos anidados no deben ser visibles
62+
dotnet_diagnostic.CA1034.severity = none
63+
64+
# CA1002: No exponer listas genéricas
65+
dotnet_diagnostic.CA1002.severity = none
66+
67+
# CA1707: Los identificadores no deben contener caracteres de subrayado
68+
dotnet_diagnostic.CA1707.severity = none
69+
70+
# CA1308: Normalizar las cadenas en mayúsculas
71+
dotnet_diagnostic.CA1308.severity = none
72+
73+
6074
[*.{cs,vb}]
75+
# Default severity for analyzer diagnostics with category 'Style'
76+
dotnet_analyzer_diagnostic.category-Style.severity = none
77+
6178
dotnet_diagnostic.IDE0054.severity = none
6279
dotnet_diagnostic.IDE0074.severity = none
80+
81+
# CA1515: Consider making public types internal
82+
dotnet_diagnostic.CA1515.severity = none

.github/workflows/dotnet-lint.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# yamllint disable rule:line-length
2+
# This workflow will build a .NET project
3+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
4+
# yamllint enable rule:line-length
5+
6+
---
7+
name: dotNET Tests
8+
9+
on: # yamllint disable-line rule:truthy
10+
push:
11+
branches: ["main"]
12+
pull_request:
13+
# The branches below must be a subset of the branches above
14+
branches: ["main"]
15+
workflow_dispatch:
16+
17+
jobs:
18+
lint:
19+
name: "Run LINT"
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
os: ["windows-2022", "windows-2025", "ubuntu-24.04", "macos-14"]
24+
dotnet-version: [8.x, 9.x]
25+
runs-on: ${{ matrix.os }}
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Setup .NET ${{ matrix.dotnet-version }}
29+
uses: actions/setup-dotnet@v4
30+
with:
31+
dotnet-version: ${{ matrix.dotnet-version }}
32+
- name: Tooling check
33+
run: >
34+
dotnet --version
35+
- name: Restore dependencies
36+
run: dotnet restore
37+
- name: Lint (codestyle)
38+
run: dotnet format --verify-no-changes --verbosity normal

.github/workflows/dotnet.yml renamed to .github/workflows/dotnet-test.yml

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ jobs:
3636
run: dotnet restore
3737
- name: Build
3838
run: dotnet build --no-restore
39-
- name: Lint (codestyle)
40-
run: dotnet format --verify-no-changes --verbosity normal
4139
- name: Test
4240
run: >
4341
dotnet test --no-build

src/algorithm_exercises_csharp/Hello.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ namespace algorithm_exercises_csharp;
44

55
public class HelloWorld
66
{
7-
const string __message = "Hello World!";
7+
private readonly string __message = "Hello World!";
88

9-
[ExcludeFromCodeCoverage]
10-
protected HelloWorld() { }
11-
12-
public static string hello()
9+
public string hello()
1310
{
1411
return __message;
1512
}

src/algorithm_exercises_csharp/algorithm_exercises_csharp.csproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
1010

11-
<!-- Static Analysis -->
11+
<!-- Code analysis. -->
1212
<EnableNETAnalyzers>true</EnableNETAnalyzers>
1313
<AnalysisLevel>latest</AnalysisLevel>
14+
<AnalysisMode>All</AnalysisMode>
15+
<!-- <TreatWarningsAsErrors>true</TreatWarningsAsErrors> -->
16+
<!-- <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors> -->
1417
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
15-
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
1618

1719
</PropertyGroup>
1820

src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/arrays/ArraysLeftRotation.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit.arrays
44

55
using System.Diagnostics.CodeAnalysis;
66

7-
public class ArraysLeftRotation
7+
public static class ArraysLeftRotation
88
{
9-
[ExcludeFromCodeCoverage]
10-
protected ArraysLeftRotation() { }
11-
129
public const int FIRST_POSITION = 0;
1310

1411
/**
1512
* In favor of increasing performance, this implementation mutates the input list.
1613
*/
1714
public static List<int> rotLeftOne(List<int> input)
1815
{
16+
ArgumentNullException.ThrowIfNull(input);
17+
1918
int first = input[FIRST_POSITION];
2019
input.RemoveAt(FIRST_POSITION);
2120
input.Add(first);
@@ -28,6 +27,8 @@ public static List<int> rotLeftOne(List<int> input)
2827
*/
2928
public static List<int> rotLeft(List<int> input, int d)
3029
{
30+
ArgumentNullException.ThrowIfNull(input);
31+
3132
// Clone the list
3233
List<int> output = input.GetRange(FIRST_POSITION, input.Count);
3334

src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/arrays/CrushBruteForce.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit.arrays
55

66
using System.Diagnostics.CodeAnalysis;
77

8-
public class CrushBruteForce
8+
public static class CrushBruteForce
99
{
10-
[ExcludeFromCodeCoverage]
11-
protected CrushBruteForce() { }
12-
1310
private const int INITIALIZER = 0;
1411

1512
public static long arrayManipulation(int n, List<List<int>> queries)
1613
{
14+
ArgumentNullException.ThrowIfNull(queries);
15+
1716
// why adding 1?
1817
// first slot to adjust 1-based index and
1918
int[] result = new int[n + 1];

src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/arrays/CrushOptimized.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit.arrays
55

66
using System.Diagnostics.CodeAnalysis;
77

8-
public class CrushOptimized
8+
public static class CrushOptimized
99
{
10-
[ExcludeFromCodeCoverage]
11-
private CrushOptimized() { }
12-
1310
/**
1411
// arrayManipulation.
1512
*/
1613
public static long arrayManipulation(int n, List<List<int>> queries)
1714
{
15+
ArgumentNullException.ThrowIfNull(queries);
16+
1817
// why adding 2?
1918
// first slot to adjust 1-based index and
2019
// last slot for storing accumSum result

src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/arrays/NewYearChaos.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22

33
namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit.arrays;
44

5-
using System.Diagnostics.CodeAnalysis;
6-
7-
public class NewYearChaos
5+
public static class NewYearChaos
86
{
9-
[ExcludeFromCodeCoverage]
10-
protected NewYearChaos() { }
11-
12-
public const String TOO_CHAOTIC_ERROR = "Too chaotic";
7+
public const string TOO_CHAOTIC_ERROR = "Too chaotic";
138

149
/**
1510
* minimumBribesCalculate.
1611
*/
1712
public static int minimumBribesCalculate(List<int> q)
1813
{
14+
ArgumentNullException.ThrowIfNull(q);
15+
1916
int bribes = 0;
2017
int i = 0;
2118

@@ -46,16 +43,16 @@ public static int minimumBribesCalculate(List<int> q)
4643
/**
4744
* minimumBribes.
4845
*/
49-
public static String minimumBribesText(List<int> q)
46+
public static string minimumBribesText(List<int> q)
5047
{
5148
try
5249
{
5350
int bribes = minimumBribesCalculate(q);
54-
return String.Format("{0}", bribes);
51+
return string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", bribes);
5552
}
5653
catch (InvalidOperationException e)
5754
{
58-
return String.Format(e.Message);
55+
return string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", e.Message);
5956
}
6057
}
6158

@@ -64,6 +61,6 @@ public static String minimumBribesText(List<int> q)
6461
*/
6562
public static void minimumBribes(List<int> q)
6663
{
67-
Console.WriteLine("{0}", minimumBribesText(q));
64+
Console.WriteLine(minimumBribesText(q));
6865
}
6966
}

src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/arrays/TwoDArray.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit.arrays
44

55
using System.Diagnostics.CodeAnalysis;
66

7-
public class TwoDArray
7+
public static class TwoDArray
88
{
9-
[ExcludeFromCodeCoverage]
10-
protected TwoDArray() { }
11-
129
private static List<int> getHourGlass(List<List<int>> arr, int positionX, int positionY)
1310
{
1411
List<int> result = [];
@@ -31,6 +28,8 @@ private static List<int> getHourGlass(List<List<int>> arr, int positionX, int po
3128

3229
public static int hourglassSum(List<List<int>> arr)
3330
{
31+
ArgumentNullException.ThrowIfNull(arr);
32+
3433
int matrixSize = arr.Count;
3534

3635
int matrixStartIndex = 1;

src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/CountTriplets.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44

55
namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit.dictionaries_and_hashmaps;
66

7-
using System.Diagnostics.CodeAnalysis;
87
using System.Collections.Generic;
98

10-
public class CountTriplets
9+
public static class CountTriplets
1110
{
12-
[ExcludeFromCodeCoverage]
13-
protected CountTriplets() { }
14-
1511
public static long countTriplets(List<long> arr, long r)
1612
{
13+
ArgumentNullException.ThrowIfNull(arr);
14+
1715
Dictionary<long, long> aCounter = [];
1816
Dictionary<long, long> bCounter = [];
1917
long triplets = 0L;

src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/CountTripletsBruteForce.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit.dictio
55
using System.Diagnostics.CodeAnalysis;
66
using System.Collections.Generic;
77

8-
public class CountTripletsBruteForce
8+
public static class CountTripletsBruteForce
99
{
10-
[ExcludeFromCodeCoverage]
11-
protected CountTripletsBruteForce() { }
12-
1310
public static long countTriplets(List<long> arr, long r)
1411
{
12+
ArgumentNullException.ThrowIfNull(arr);
13+
1514
long size = arr.Count;
1615
long counter = 0L;
1716

src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/FrequencyQueries.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ private FrequencyQueries()
1313
reset();
1414
}
1515

16-
private static readonly long __INITIAL__ = 1L;
16+
private const long __INITIAL__ = 1L;
1717

1818
private const int __INSERT__ = 1;
1919
private const int __DELETE__ = 2;
2020
private const int __SELECT__ = 3;
2121

22-
private static readonly int __NOT_FOUND__ = 0;
23-
private static readonly int __FOUND__ = 1;
22+
private const int __NOT_FOUND__ = 0;
23+
private const int __FOUND__ = 1;
2424

2525
readonly Dictionary<long, long> valueFreqs = [];
2626
readonly Dictionary<long, List<long>> freqDictionary = [];
@@ -116,6 +116,8 @@ void select(long value)
116116
*/
117117
public static List<int> freqQuery(List<List<int>> queries)
118118
{
119+
ArgumentNullException.ThrowIfNull(queries);
120+
119121
FrequencyQueries fq = new();
120122

121123
foreach (List<int> query in queries)

src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/RansomNote.cs

+15-7
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,33 @@ namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit.dictio
55
using System.Diagnostics.CodeAnalysis;
66
using System.Collections.Generic;
77

8-
public class RansomNote
8+
public static class RansomNote
99
{
10-
[ExcludeFromCodeCoverage]
11-
protected RansomNote() { }
12-
1310
public class InvalidValueException : Exception
1411
{
1512
// constructor for the InvalidAgeException class
1613
public InvalidValueException(string msg)
1714
{
1815
Console.WriteLine(msg);
1916
}
17+
18+
public InvalidValueException()
19+
{
20+
}
21+
22+
public InvalidValueException(string message, Exception innerException) : base(message, innerException)
23+
{
24+
}
2025
}
2126

22-
private static readonly string __YES__ = "Yes";
23-
private static readonly string __NO__ = "No";
27+
private const string __YES__ = "Yes";
28+
private const string __NO__ = "No";
2429

2530
public static bool checkMagazineCompute(List<string> magazine, List<string> note)
2631
{
32+
ArgumentNullException.ThrowIfNull(magazine);
33+
ArgumentNullException.ThrowIfNull(note);
34+
2735
Dictionary<string, int> dictionary = [];
2836

2937
foreach (string word in magazine)
@@ -45,7 +53,7 @@ public static bool checkMagazineCompute(List<string> magazine, List<string> note
4553
throw new InvalidValueException("Value can't go below 0");
4654
}
4755
}
48-
catch
56+
catch (InvalidValueException)
4957
{
5058
return false;
5159
}

src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/SherlockAndAnagrams.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit.dictio
55
using System.Diagnostics.CodeAnalysis;
66
using System.Numerics;
77

8-
public class SherlockAndAnagrams
8+
public static class SherlockAndAnagrams
99
{
10-
[ExcludeFromCodeCoverage]
11-
protected SherlockAndAnagrams() { }
12-
1310
/**
1411
* factorial().
1512
*/
@@ -26,6 +23,8 @@ public static BigInteger factorial(int number)
2623

2724
public static int sherlockAndAnagrams(string s)
2825
{
26+
ArgumentException.ThrowIfNullOrEmpty(s);
27+
2928
Dictionary<string, List<string>> candidates = [];
3029

3130
int size = s.Length;

0 commit comments

Comments
 (0)