From 1225e57305a137e767de698264af7fadd25a3899 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Mon, 24 Feb 2025 12:57:43 -0300 Subject: [PATCH 1/2] [Hacker Rank] Interview Preparation Kit: Array: 2D Array - DS. Better test cases. --- .../arrays/TwoDArray.cs | 7 +----- .../arrays/2d_array.testcases.json | 24 +++++++++++++++++++ .../arrays/TwoDArray.Test.cs | 11 +++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) 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); + } } From b654e94894e7838b82c9f87edc78eedefebf7b53 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Mon, 24 Feb 2025 13:00:06 -0300 Subject: [PATCH 2/2] [CONFIG] VSCode better auto-saving formating options. --- .vscode/settings.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 +}