Skip to content

Commit 722a079

Browse files
author
Gonzalo Diaz
committed
WIP
1 parent 5542317 commit 722a079

File tree

8 files changed

+97
-63
lines changed

8 files changed

+97
-63
lines changed

.editorconfig

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ 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+
6067
[*.{cs,vb}]
6168
dotnet_diagnostic.IDE0054.severity = none
6269
dotnet_diagnostic.IDE0074.severity = none
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,56 @@
11
[
2-
{"input": [1, 2, 3, 4, 5], "expected": [2, 3, 4, 5, 1]},
3-
{"input": [2, 3, 4, 5, 1], "expected": [3, 4, 5, 1, 2]},
4-
{"input": [3, 4, 5, 1, 2], "expected": [4, 5, 1, 2, 3]},
5-
{"input": [4, 5, 1, 2, 3], "expected": [5, 1, 2, 3, 4]},
6-
{"input": [5, 1, 2, 3, 4], "expected": [1, 2, 3, 4, 5]}
2+
{
3+
"title": "Own 0",
4+
"input": [1, 2, 3, 4, 5],
5+
"d_rotations": 1,
6+
"expected": [2, 3, 4, 5, 1]
7+
},
8+
{
9+
"title": "Own 1",
10+
"input": [2, 3, 4, 5, 1],
11+
"d_rotations": 1,
12+
"expected": [3, 4, 5, 1, 2]
13+
},
14+
{
15+
"title": "Own 2",
16+
"input": [3, 4, 5, 1, 2],
17+
"d_rotations": 1,
18+
"expected": [4, 5, 1, 2, 3]
19+
},
20+
{
21+
"title": "Own 3",
22+
"input": [4, 5, 1, 2, 3],
23+
"d_rotations": 1,
24+
"expected": [5, 1, 2, 3, 4]
25+
},
26+
{
27+
"title": "Own 4",
28+
"input": [5, 1, 2, 3, 4],
29+
"d_rotations": 1,
30+
"expected": [1, 2, 3, 4, 5]
31+
},
32+
{
33+
"title": "Sample Test case 0",
34+
"input": [1, 2, 3, 4, 5],
35+
"d_rotations": 4,
36+
"expected": [5, 1, 2, 3, 4]
37+
},
38+
{
39+
"title": "Sample Test case 1",
40+
"input": [
41+
41, 73, 89, 7, 10, 1, 59, 58, 84, 77, 77, 97, 58, 1, 86, 58, 26, 10, 86,
42+
51
43+
],
44+
"d_rotations": 10,
45+
"expected": [
46+
77, 97, 58, 1, 86, 58, 26, 10, 86, 51, 41, 73, 89, 7, 10, 1, 59, 58, 84,
47+
77
48+
]
49+
},
50+
{
51+
"title": "Sample Test case 2",
52+
"input": [33, 47, 70, 37, 8, 53, 13, 93, 71, 72, 51, 100, 60, 87, 97],
53+
"d_rotations": 13,
54+
"expected": [87, 97, 33, 47, 70, 37, 8, 53, 13, 93, 71, 72, 51, 100, 60]
55+
}
756
]

src/algorithm_exercises_csharp_test/hackerrank/interview_preparation_kit/arrays/ArraysLeftRotation.Test.cs

+5-27
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,29 @@ namespace algorithm_exercises_csharp_test.hackerrank.interview_preparation_kit.a
55
[TestClass]
66
public class ArraysLeftRotationTest
77
{
8-
public class ArraysLeftRotationTestCase
9-
{
10-
public List<int> input { get; set; } = default!;
11-
public List<int> expected { get; set; } = default!;
12-
}
13-
148
public class ArraysLeftRotationsTestCase
159
{
16-
public List<int> input { get; set; } = default!;
10+
public List<int> input { get; } = default!;
1711
public int d { get; set; }
18-
public List<int> expected { get; set; } = default!;
12+
public List<int> expected { get; } = default!;
1913
}
2014

21-
private List<ArraysLeftRotationTestCase> testCases { get; set; } = default!;
22-
23-
private static readonly ArraysLeftRotationsTestCase[] testRotationsCases = [
24-
new() { input = [1, 2, 3, 4, 5], d = 4, expected = [5, 1, 2, 3, 4] }
25-
];
15+
private List<ArraysLeftRotationsTestCase> testCases = default!;
2616

2717
[TestInitialize]
2818
public void testInitialize()
2919
{
30-
testCases = JsonLoader.resourceLoad<List<ArraysLeftRotationTestCase>>(
20+
testCases = JsonLoader.resourceLoad<List<ArraysLeftRotationsTestCase>>(
3121
"hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json"
3222
) ?? [];
3323
}
3424

35-
[TestMethod]
36-
public void testRotLeftOne()
37-
{
38-
List<int> result;
39-
40-
foreach (ArraysLeftRotationTestCase test in testCases)
41-
{
42-
result = ArraysLeftRotation.rotLeftOne(test.input);
43-
CollectionAssert.AreEquivalent(test.expected, result);
44-
}
45-
}
46-
4725
[TestMethod]
4826
public void testRotLeft()
4927
{
5028
List<int> result;
5129

52-
foreach (ArraysLeftRotationsTestCase test in testRotationsCases)
30+
foreach (ArraysLeftRotationsTestCase test in testCases)
5331
{
5432
result = ArraysLeftRotation.rotLeft(test.input, test.d);
5533
CollectionAssert.AreEquivalent(test.expected, result);

src/algorithm_exercises_csharp_test/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/FrequencyQueries.Test.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public class FrequencyQueriesTest
88
public class FrequencyQueriesTestCase
99
{
1010
public string title { get; set; } = default!;
11-
public List<List<int>> input { get; set; } = default!;
12-
public List<int> expected { get; set; } = default!;
11+
public List<List<int>> input { get; } = default!;
12+
public List<int> expected { get; } = default!;
1313
}
1414

1515
List<FrequencyQueriesTestCase> testCases { get; set; } = default!;

src/algorithm_exercises_csharp_test/hackerrank/projecteuler/Euler001.Test.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ public class Euler001Test
66
{
77
public class Euler001TestCase
88
{
9-
public int a; public int b; public int n; public int answer;
9+
public int A { get; set; }
10+
public int B { get; set; }
11+
public int N { get; set; }
12+
public int Answer { get; set; }
1013
}
1114

12-
// dotnet_style_readonly_field = true
1315
private static readonly Euler001TestCase[] tests = [
14-
new() { a = 3, b = 5, n = 10, answer = 23 },
15-
new() { a = 3, b = 5, n = 100, answer = 2318 },
16-
new() { a = 3, b = 5, n = 1000, answer = 233168 },
17-
16+
new() { A = 3, B = 5, N = 10, Answer = 23 },
17+
new() { A = 3, B = 5, N = 100, Answer = 2318 },
18+
new() { A = 3, B = 5, N = 1000, Answer = 233168 }
1819
];
1920

2021
[TestMethod]
@@ -24,8 +25,8 @@ public void euler001Test()
2425

2526
foreach (Euler001TestCase test in tests)
2627
{
27-
result = Euler001.euler001(test.a, test.b, test.n);
28-
Assert.AreEqual(test.answer, result);
28+
result = Euler001.euler001(test.A, test.B, test.N);
29+
Assert.AreEqual(test.Answer, result);
2930
}
3031
}
3132
}

src/algorithm_exercises_csharp_test/hackerrank/projecteuler/Euler002.Test.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ public class Euler002Test
66
{
77
public class Euler002TestCase
88
{
9-
public int n; public int answer;
9+
public int N { get; set; }
10+
public int Answer { get; set; }
1011
}
1112

12-
// dotnet_style_readonly_field = true
1313
private static readonly Euler002TestCase[] tests = [
14-
new() { n = 10, answer = 10 },
15-
new() { n = 100, answer = 44 }
14+
new() { N = 10, Answer = 10 },
15+
new() { N = 100, Answer = 44 }
1616
];
1717

1818
[TestMethod]
1919
public void euler002Test()
2020
{
2121
int result;
22-
2322
foreach (Euler002TestCase test in tests)
2423
{
25-
result = Euler002.euler002(test.n);
26-
Assert.AreEqual(test.answer, result);
24+
result = Euler002.euler002(test.N);
25+
Assert.AreEqual(test.Answer, result);
2726
}
2827
}
2928
}
3029

30+

src/algorithm_exercises_csharp_test/hackerrank/projecteuler/Euler003.Test.cs

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@ public class Euler003Test
66
{
77
public class Euler003TestCase
88
{
9-
public int n; public int? answer;
9+
public int N { get; set; }
10+
public int? Answer { get; set; }
1011
}
1112

12-
// dotnet_style_readonly_field = true
1313
private static readonly Euler003TestCase[] tests = [
14-
new() { n = 1, answer = null },
15-
new() { n = 10, answer = 5 },
16-
new() { n = 17, answer = 17 }
14+
new() { N = 1, Answer = null },
15+
new() { N = 10, Answer = 5 },
16+
new() { N = 17, Answer = 17 }
1717
];
1818

1919
[TestMethod]
2020
public void euler003Test()
2121
{
2222
int? result;
23-
2423
foreach (Euler003TestCase test in tests)
2524
{
26-
result = Euler003.euler003(test.n);
27-
Assert.AreEqual(test.answer, result);
25+
result = Euler003.euler003(test.N);
26+
Assert.AreEqual(test.Answer, result);
2827
}
2928
}
3029
}

src/algorithm_exercises_csharp_test/hackerrank/warmup/AVeryBigSumTest.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ public class AVeryBigSumTest
88
{
99
public class AVeryBigSumTestCase
1010
{
11-
public List<long> ar = [];
12-
public long expected = 0;
11+
public List<long> Ar { get; set; } = default!;
12+
public long Expected { get; set; }
1313
}
1414

1515
private static readonly AVeryBigSumTestCase[] tests = [
1616
new()
1717
{
18-
ar = [1000000001, 1000000002, 1000000003, 1000000004, 1000000005],
19-
expected = 5000000015
18+
Ar = [1000000001, 1000000002, 1000000003, 1000000004, 1000000005],
19+
Expected = 5000000015
2020
}
2121
];
2222

@@ -27,8 +27,8 @@ public void testSimpleArraySum()
2727

2828
foreach (AVeryBigSumTestCase test in tests)
2929
{
30-
result = AVeryBigSum.aVeryBigSum(test.ar);
31-
Assert.AreEqual(test.expected, result);
30+
result = AVeryBigSum.aVeryBigSum(test.Ar);
31+
Assert.AreEqual(test.Expected, result);
3232
}
3333
}
3434
}

0 commit comments

Comments
 (0)