|
1 | 1 | namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit;
|
2 | 2 |
|
| 3 | +using System.Reflection; |
| 4 | +using System.Text; |
| 5 | +using System.Text.Json; |
| 6 | +using Newtonsoft.Json; |
| 7 | + |
3 | 8 | [TestClass]
|
4 | 9 | public class ArraysLeftRotationTest
|
5 | 10 | {
|
6 | 11 | public class ArraysLeftRotationTestCase
|
7 | 12 | {
|
8 |
| - public List<int> input = []; public List<int> expected = []; |
| 13 | + public List<Int32> input = []; public List<Int32> expected = []; |
9 | 14 | }
|
10 | 15 |
|
11 | 16 | public class ArraysLeftRotationsTestCase
|
12 | 17 | {
|
13 | 18 | public List<int> input = []; public int d; public List<int> expected = [];
|
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 static List<ArraysLeftRotationTestCase> testCases = []; |
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 | + var info = Assembly.GetExecutingAssembly().GetName(); |
| 31 | + var name = info.Name; |
| 32 | + using var stream = Assembly |
| 33 | + .GetExecutingAssembly() |
| 34 | + .GetManifestResourceStream($"{name}.Resources.hackerrank.interview_preparation_kit.arrays.ctci_array_left_rotation.testcases.json")!; |
| 35 | + |
| 36 | + using var streamReader = new StreamReader(stream, Encoding.UTF8); |
| 37 | + |
| 38 | + testCases = JsonConvert.DeserializeObject<List<ArraysLeftRotationTestCase>>(streamReader.ReadToEnd()) ?? []; |
| 39 | + } |
| 40 | + |
28 | 41 | [TestMethod]
|
29 | 42 | public void testRotLeftOne()
|
30 | 43 | {
|
31 | 44 | List<int> result;
|
32 | 45 |
|
33 |
| - foreach (ArraysLeftRotationTestCase test in tests) |
| 46 | + foreach (ArraysLeftRotationTestCase test in testCases) |
34 | 47 | {
|
35 | 48 | result = ArraysLeftRotation.rotLeftOne(test.input);
|
36 | 49 | CollectionAssert.AreEquivalent(test.expected, result);
|
|
0 commit comments