|
1 | 1 | namespace algorithm_exercises_csharp_test.hackerrank.warmup;
|
2 | 2 | using algorithm_exercises_csharp.hackerrank.warmup;
|
3 | 3 |
|
| 4 | +using algorithm_exercises_csharp_test.lib; |
| 5 | + |
4 | 6 | [TestClass]
|
5 | 7 | public class MiniMaxSumTest
|
6 | 8 | {
|
7 |
| - public class MiniMaxSumTestCase |
| 9 | + public class MiniMaxSumTestCase(List<int> input, string expected) |
8 | 10 | {
|
9 |
| - public List<int> input = []; |
10 |
| - public string expected = ""; |
| 11 | + private readonly List<int> input = input; |
| 12 | + private readonly string expected = expected; |
| 13 | + |
| 14 | + public List<int> Input |
| 15 | + { |
| 16 | + get { return input; } |
| 17 | + } |
| 18 | + |
| 19 | + public string Expected |
| 20 | + { |
| 21 | + get { return expected; } |
| 22 | + } |
11 | 23 | }
|
12 | 24 |
|
13 |
| - private static readonly MiniMaxSumTestCase[] tests = [ |
14 |
| - new() { input = [1, 2, 3, 4, 5], expected = "10 14" }, |
15 |
| - new() { input = [5, 4, 3, 2, 1], expected = "10 14" } |
16 |
| - ]; |
| 25 | + private List<MiniMaxSumTestCase> testCases { get; set; } = default!; |
| 26 | + |
| 27 | + [TestInitialize] |
| 28 | + public void testInitialize() |
| 29 | + { |
| 30 | + testCases = JsonLoader.stringLoad<List<MiniMaxSumTestCase>>(/*lang=json,strict*/ @" |
| 31 | + [ |
| 32 | + { ""input"": [1, 2, 3, 4, 5], ""expected"": ""10 14"" }, |
| 33 | + { ""input"": [5, 4, 3, 2, 1], ""expected"": ""10 14"" } |
| 34 | + ] |
| 35 | + ") ?? []; |
| 36 | + } |
17 | 37 |
|
18 | 38 | [TestMethod]
|
19 | 39 | public void testMiniMaxSum()
|
20 | 40 | {
|
21 | 41 | string? result;
|
22 | 42 |
|
23 |
| - foreach (MiniMaxSumTestCase test in tests) |
| 43 | + foreach (MiniMaxSumTestCase test in testCases) |
24 | 44 | {
|
25 |
| - result = MiniMaxSum.miniMaxSum(test.input); |
26 |
| - Assert.AreEqual(test.expected, result); |
| 45 | + result = MiniMaxSum.miniMaxSum(test.Input); |
| 46 | + Assert.AreEqual(test.Expected, result); |
27 | 47 | }
|
28 | 48 | }
|
29 | 49 |
|
|
0 commit comments