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