|
1 | 1 | namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit;
|
2 | 2 |
|
| 3 | +using Newtonsoft.Json; |
| 4 | + |
3 | 5 | [TestClass]
|
4 | 6 | public class ArraysLeftRotationTest
|
5 | 7 | {
|
6 | 8 | public class ArraysLeftRotationTestCase
|
7 | 9 | {
|
8 |
| - public List<int> input = []; public List<int> expected = []; |
| 10 | + public List<int> input { get; set; } = default!; |
| 11 | + public List<int> expected { get; set; } = default!; |
9 | 12 | }
|
10 | 13 |
|
11 | 14 | public class ArraysLeftRotationsTestCase
|
12 | 15 | {
|
13 |
| - public List<int> input = []; public int d; public List<int> expected = []; |
| 16 | + public List<int> input { get; set; } = default!; |
| 17 | + public int d { get; set; } |
| 18 | + public List<int> expected { get; set; } = default!; |
14 | 19 | }
|
15 | 20 |
|
16 |
| - private static readonly ArraysLeftRotationTestCase[] tests = [ |
17 |
| - new() { input = [1, 2, 3, 4, 5], expected = [2, 3, 4, 5, 1] }, |
18 |
| - new() { input = [2, 3, 4, 5, 1], expected = [3, 4, 5, 1, 2] }, |
19 |
| - new() { input = [3, 4, 5, 1, 2], expected = [4, 5, 1, 2, 3] }, |
20 |
| - new() { input = [4, 5, 1, 2, 3], expected = [5, 1, 2, 3, 4] }, |
21 |
| - new() { input = [5, 1, 2, 3, 4], expected = [1, 2, 3, 4, 5] } |
22 |
| - ]; |
| 21 | + private List<ArraysLeftRotationTestCase> testCases { get; set; } = default!; |
23 | 22 |
|
24 | 23 | private static readonly ArraysLeftRotationsTestCase[] testRotationsCases = [
|
25 | 24 | new() { input = [1, 2, 3, 4, 5], d = 4, expected = [5, 1, 2, 3, 4] }
|
26 | 25 | ];
|
27 | 26 |
|
| 27 | + [TestInitialize] |
| 28 | + public void testInitialize() |
| 29 | + { |
| 30 | + testCases = JsonConvert.DeserializeObject<List<ArraysLeftRotationTestCase>>( |
| 31 | + JsonLoader.resourceLoad("hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json") |
| 32 | + ) ?? []; |
| 33 | + } |
| 34 | + |
28 | 35 | [TestMethod]
|
29 | 36 | public void testRotLeftOne()
|
30 | 37 | {
|
31 | 38 | List<int> result;
|
32 | 39 |
|
33 |
| - foreach (ArraysLeftRotationTestCase test in tests) |
| 40 | + foreach (ArraysLeftRotationTestCase test in testCases) |
34 | 41 | {
|
35 | 42 | result = ArraysLeftRotation.rotLeftOne(test.input);
|
36 | 43 | CollectionAssert.AreEquivalent(test.expected, result);
|
|
0 commit comments