diff --git a/.vscode/settings.json b/.vscode/settings.json index efc2a83..1a92387 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,9 +7,12 @@ "[csharp]": { "editor.defaultFormatter": "ms-dotnettools.csharp" }, - "omnisharp.enableEditorConfigSupport": true, + "[json]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, "[github-actions-workflow]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, + "omnisharp.enableEditorConfigSupport": true, "snyk.advanced.additionalParameters": "--exclude=.trunk,coverage-report" -} \ No newline at end of file +} diff --git a/src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/arrays/TwoDArray.cs b/src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/arrays/TwoDArray.cs index 5a41762..83f9bf1 100644 --- a/src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/arrays/TwoDArray.cs +++ b/src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/arrays/TwoDArray.cs @@ -31,12 +31,7 @@ private static List getHourGlass(List> arr, int positionX, int po public static int hourglassSum(List> arr) { - int matrixSize = 0; - - if (arr.Count > 0) - { - matrixSize = arr.Count; - } + int matrixSize = arr.Count; int matrixStartIndex = 1; int matrixEndIndex = matrixSize - 2; diff --git a/src/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/arrays/2d_array.testcases.json b/src/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/arrays/2d_array.testcases.json index f32bdef..91ecbd7 100644 --- a/src/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/arrays/2d_array.testcases.json +++ b/src/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/arrays/2d_array.testcases.json @@ -10,5 +10,29 @@ [0, 0, 1, 2, 4, 0] ], "expected": 19 + }, + { + "title": "Sample Test Case 1", + "input": [ + [1, 1, 1, 0, 0, 0], + [0, 1, 0, 0, 0, 0], + [1, 1, 1, 0, 0, 0], + [0, 9, 2, -4, -4, 0], + [0, 0, 0, -2, 0, 0], + [0, 0, -1, -2, -4, 0] + ], + "expected": 13 + }, + { + "title": "Sample Test Case 2", + "input": [ + [-9, -9, -9, 1, 1, 1], + [0, -9, 0, 4, 3, 2], + [-9, -9, -9, 1, 2, 3], + [0, 0, 8, 6, 6, 0], + [0, 0, 0, -2, 0, 0], + [0, 0, 1, 2, 4, 0] + ], + "expected": 28 } ] diff --git a/src/algorithm_exercises_csharp_test/hackerrank/interview_preparation_kit/arrays/TwoDArray.Test.cs b/src/algorithm_exercises_csharp_test/hackerrank/interview_preparation_kit/arrays/TwoDArray.Test.cs index 9d1349a..a12c28d 100644 --- a/src/algorithm_exercises_csharp_test/hackerrank/interview_preparation_kit/arrays/TwoDArray.Test.cs +++ b/src/algorithm_exercises_csharp_test/hackerrank/interview_preparation_kit/arrays/TwoDArray.Test.cs @@ -33,5 +33,16 @@ public void testHourglassSum() Assert.AreEqual(test.expected, result); } } + + + [TestMethod] + public void testHourglassSumEdgeCases() + { + List> input = []; + int expected = 0; + int result = TwoDArray.hourglassSum(input); + + Assert.AreEqual(expected, result); + } }