Skip to content

Commit 43512e7

Browse files
authored
Merge pull request #28 from sir-gon/develop
Develop
2 parents 2ec15d1 + 93d5af4 commit 43512e7

File tree

12 files changed

+81
-43
lines changed

12 files changed

+81
-43
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,15 @@ insert_final_newline = true
3434
# Use tabs for indentation (Makefiles require tabs)
3535
indent_style = tab
3636
indent_size = 2
37+
38+
###############################
39+
# .NET C# Coding Conventions #
40+
###############################
41+
42+
[*.cs]
43+
#IDE1006
44+
dotnet_naming_style.camel_case.capitalization = camel_case
45+
dotnet_naming_symbols.private_symbols.applicable_accessibilities = private
46+
dotnet_naming_rule.camel_case_for_private.severity = warning
47+
dotnet_naming_rule.camel_case_for_private.symbols = private_symbols
48+
dotnet_naming_rule.camel_case_for_private.style = camel_case

.github/workflows/dotnet.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ jobs:
3131
run: dotnet restore
3232
- name: Build
3333
run: dotnet build --no-restore
34+
- name: Lint (codestyle)
35+
run: dotnet format --verify-no-changes --verbosity normal
3436
- name: Test
3537
run: dotnet test --no-build --verbosity normal

.github/workflows/markdown-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
os: [ubuntu-latest]
19-
node-version: [20.x]
19+
node-version: [22.x]
2020
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2121

2222
steps:

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
"sonarlint.connectedMode.project": {
33
"connectionId": "sir-gon",
44
"projectKey": "sir-gon_algorithm-exercises-csharp"
5-
}
5+
},
6+
"editor.defaultFormatter": "ms-dotnettools.csdevkit",
7+
"editor.formatOnSave": true
68
}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ lint: test/static test/styling mdlint
7474
test/static: dependencies
7575

7676
test/styling: dependencies
77+
${PACKAGE_TOOL} format --verify-no-changes --verbosity ${VERBOSITY_LEVEL}
78+
79+
format:
80+
${PACKAGE_TOOL} format --verbosity ${VERBOSITY_LEVEL}
7781

7882
build: env dependencies
7983
${PACKAGE_TOOL} build --verbosity ${VERBOSITY_LEVEL}

algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler001.Test.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ namespace algorithm_exercises_csharp.hackerrank.prohecteuler;
33
[TestClass]
44
public class Euler001Test
55
{
6-
public class Euler001TestCase {
6+
public class Euler001TestCase
7+
{
78
public int a; public int b; public int n; public int answer;
89
}
910

1011
// dotnet_style_readonly_field = true
1112
private static readonly Euler001TestCase[] tests = [
12-
new() { a = 3, b = 5, n = 10, answer = 23},
13-
new() { a = 3, b = 5, n = 100, answer = 2318},
14-
new() { a = 3, b = 5, n = 1000, answer = 233168},
13+
new() { a = 3, b = 5, n = 10, answer = 23 },
14+
new() { a = 3, b = 5, n = 100, answer = 2318 },
15+
new() { a = 3, b = 5, n = 1000, answer = 233168 },
1516

1617
];
1718

@@ -20,9 +21,10 @@ public void Euler001ProblemTest()
2021
{
2122
int result;
2223

23-
foreach (Euler001TestCase test in tests) {
24+
foreach (Euler001TestCase test in tests)
25+
{
2426
result = Euler001Problem.Euler001(test.a, test.b, test.n);
25-
Assert.AreEqual(test.answer, result);
27+
Assert.AreEqual(test.answer, result);
2628
}
2729
}
2830
}

algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler002.Test.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@ namespace algorithm_exercises_csharp.hackerrank.prohecteuler;
33
[TestClass]
44
public class Euler002Test
55
{
6-
public class Euler002TestCase {
6+
public class Euler002TestCase
7+
{
78
public int n; public int answer;
89
}
910

1011
// dotnet_style_readonly_field = true
1112
private static readonly Euler002TestCase[] tests = [
12-
new() { n = 10, answer = 10},
13-
new() { n = 100, answer = 44}
13+
new() { n = 10, answer = 10 },
14+
new() { n = 100, answer = 44 }
1415
];
1516

1617
[TestMethod]
1718
public void Euler002ProblemTest()
1819
{
1920
int result;
2021

21-
foreach (Euler002TestCase test in tests) {
22+
foreach (Euler002TestCase test in tests)
23+
{
2224
result = Euler002Problem.Euler002(test.n);
23-
Assert.AreEqual(test.answer, result);
25+
Assert.AreEqual(test.answer, result);
2426
}
2527
}
2628
}

algorithm-exercises-csharp-test/src/hackerrank/projecteuler/Euler003.Test.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ namespace algorithm_exercises_csharp.hackerrank.prohecteuler;
88
[TestClass]
99
public class Euler003Test
1010
{
11-
public class Euler003TestCase {
11+
public class Euler003TestCase
12+
{
1213
public int n; public int? answer;
1314
}
1415

1516
// dotnet_style_readonly_field = true
1617
private static readonly Euler003TestCase[] tests = [
17-
new() { n = 1, answer = null},
18-
new() { n = 10, answer = 5},
19-
new() { n = 17, answer = 17}
18+
new() { n = 1, answer = null },
19+
new() { n = 10, answer = 5 },
20+
new() { n = 17, answer = 17 }
2021
];
2122

2223
[TestMethod]
2324
public void Euler003ProblemTest()
2425
{
2526
int? result;
2627

27-
foreach (Euler003TestCase test in tests) {
28+
foreach (Euler003TestCase test in tests)
29+
{
2830
result = Euler003Problem.Euler003(test.n);
2931
Assert.AreEqual(test.answer, result);
3032
}

algorithm-exercises-csharp/src/Hello.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ public class HelloWorld
77
const string message = "Hello World!";
88

99
[ExcludeFromCodeCoverage]
10-
protected HelloWorld() {}
10+
protected HelloWorld() { }
1111

1212
public static string Hello()
1313
{
1414
return HelloWorld.message;
1515
}
1616

17-
public static HelloWorld Create() {
17+
public static HelloWorld Create()
18+
{
1819
return new HelloWorld();
1920
}
2021
}

algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler001.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ namespace algorithm_exercises_csharp.hackerrank.prohecteuler;
77
public class Euler001Problem
88
{
99
[ExcludeFromCodeCoverage]
10-
protected Euler001Problem() {}
10+
protected Euler001Problem() { }
1111

12-
public static int SuOfArithmeticProgression(int n, int d) {
12+
public static int SuOfArithmeticProgression(int n, int d)
13+
{
1314
int new_n = n / d;
1415

1516
return new_n * (1 + new_n) * d / 2;
@@ -19,7 +20,7 @@ public static int GCD(int u, int v)
1920
{
2021
if (v != 0)
2122
{
22-
return GCD(v, u % v);
23+
return GCD(v, u % v);
2324
}
2425
return u;
2526
}

algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler002.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,25 @@ namespace algorithm_exercises_csharp.hackerrank.prohecteuler;
77
public class Euler002Problem
88
{
99
[ExcludeFromCodeCoverage]
10-
protected Euler002Problem() {}
10+
protected Euler002Problem() { }
1111

12-
public static int FiboEvenSum(int n) {
12+
public static int FiboEvenSum(int n)
13+
{
1314
int total = 0;
1415
int fibo;
1516
int fibo1 = 1;
1617
int fibo2 = 1;
1718

18-
while (fibo1 + fibo2 < n) {
19-
fibo = fibo1 + fibo2;
20-
fibo1 = fibo2;
21-
fibo2 = fibo;
19+
while (fibo1 + fibo2 < n)
20+
{
21+
fibo = fibo1 + fibo2;
22+
fibo1 = fibo2;
23+
fibo2 = fibo;
2224

23-
if(fibo % 2 == 0) {
24-
total += fibo;
25-
}
25+
if (fibo % 2 == 0)
26+
{
27+
total += fibo;
28+
}
2629
}
2730

2831
return total;

algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler003.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,34 @@ namespace algorithm_exercises_csharp.hackerrank.prohecteuler;
77
public class Euler003Problem
88
{
99
[ExcludeFromCodeCoverage]
10-
protected Euler003Problem() {}
10+
protected Euler003Problem() { }
1111

12-
public static int? PrimeFactor(int n) {
13-
if (n < 2) {
12+
public static int? PrimeFactor(int n)
13+
{
14+
if (n < 2)
15+
{
1416
return null;
1517
}
1618

1719
int divisor = n;
1820
int? max_prime_factor = null;
1921

2022
int i = 2;
21-
while (i <= Math.Sqrt(divisor)) {
22-
if (0 == divisor % i) {
23-
divisor = divisor / i;
24-
max_prime_factor = divisor;
25-
} else {
26-
i += 1;
27-
}
23+
while (i <= Math.Sqrt(divisor))
24+
{
25+
if (0 == divisor % i)
26+
{
27+
divisor = divisor / i;
28+
max_prime_factor = divisor;
29+
}
30+
else
31+
{
32+
i += 1;
33+
}
2834
}
2935

30-
if (max_prime_factor is null) {
36+
if (max_prime_factor is null)
37+
{
3138
return n;
3239
}
3340

0 commit comments

Comments
 (0)