Skip to content

Commit 9711116

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] code style fixing
1 parent 23fc3b7 commit 9711116

File tree

7 files changed

+59
-41
lines changed

7 files changed

+59
-41
lines changed

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)