From e9fa6bc5d1c9a210c74bc5ad2b1e04ecd5ff102b Mon Sep 17 00:00:00 2001 From: eminencegrs Date: Mon, 9 Dec 2024 22:44:12 +0100 Subject: [PATCH] Refactoring. --- .../Y2024/M07/Day18Tests.cs | 15 +++---- .../Y2024/M07/Day19Tests.cs | 10 ++--- .../Y2024/M08/Day04Tests.cs | 14 ++++--- .../Y2024/M08/Day07Tests.cs | 3 +- .../Y2024/M08/Day13Tests.cs | 40 +++++++++---------- .../Y2024/M09/Day16Tests.cs | 26 ++++++------ .../Y2024/M10/Day28/SolutionTests.cs | 1 + .../Y2024/M11/Day12/SolutionTests.cs | 2 +- .../N_0257_BinaryTreePaths/SolutionTests.cs | 2 +- 9 files changed, 59 insertions(+), 54 deletions(-) diff --git a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M07/Day18Tests.cs b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M07/Day18Tests.cs index 41a95d3..fec969b 100644 --- a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M07/Day18Tests.cs +++ b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M07/Day18Tests.cs @@ -8,7 +8,8 @@ public class Day18Tests { [Theory] [MemberData(nameof(TestData))] - public void GivenNumbersAndTarget_WhenGetResult_ThenResultAsExpected(int[] numbers, int target, bool expectedResult) + public void GivenNumbersAndTarget_WhenGetResult_ThenResultAsExpected( + int[] numbers, int target, bool expectedResult) { bool actualResult = Day18Task.GetResult(numbers, target); actualResult.ShouldBeEquivalentTo(expectedResult); @@ -16,11 +17,11 @@ public void GivenNumbersAndTarget_WhenGetResult_ThenResultAsExpected(int[] numbe public static IEnumerable TestData() { - yield return [ Array.Empty(), int.MaxValue, false ]; - yield return [ new [] { 10, 15, 3, 7 }, 17, true ]; - yield return [ new [] { 10, 7, 6, 3, 1, 0 }, 15, false ]; - yield return [ new [] { 21, -13, -5, 14, -10, 8, 0, -1, 5, 100 }, 100, true ]; - yield return [ new [] { 21, -13, -5, 14, -10, 8, 0, -1, 5, 100 }, 0, true ]; - yield return [ new [] { 21, -13, -5, 14, -10, 8, 0, -1, 5, 100 }, 200, false ]; + yield return [Array.Empty(), int.MaxValue, false]; + yield return [new[] { 10, 15, 3, 7 }, 17, true]; + yield return [new[] { 10, 7, 6, 3, 1, 0 }, 15, false]; + yield return [new[] { 21, -13, -5, 14, -10, 8, 0, -1, 5, 100 }, 100, true]; + yield return [new[] { 21, -13, -5, 14, -10, 8, 0, -1, 5, 100 }, 0, true]; + yield return [new[] { 21, -13, -5, 14, -10, 8, 0, -1, 5, 100 }, 200, false]; } } diff --git a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M07/Day19Tests.cs b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M07/Day19Tests.cs index 3b861ce..9d0dbbe 100644 --- a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M07/Day19Tests.cs +++ b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M07/Day19Tests.cs @@ -25,10 +25,10 @@ public void GivenNumbers_WhenGetResultNotUsingDivision_ThenResultAsExpected( public static IEnumerable TestData() { - yield return [ new [] { 1, 2, 3, 4, 5 }, new [] { 120, 60, 40, 30, 24 } ]; - yield return [ new [] { 3, 2, 1 }, new [] { 2, 3, 6 } ]; - yield return [ new [] { -3, -2, 1 }, new [] { -2, -3, 6 } ]; - yield return [ new [] { 0, 4, 7 }, new [] { 0, 0, 0 } ]; - yield return [ Array.Empty(), Array.Empty() ]; + yield return [new[] { 1, 2, 3, 4, 5 }, new[] { 120, 60, 40, 30, 24 }]; + yield return [new[] { 3, 2, 1 }, new[] { 2, 3, 6 }]; + yield return [new[] { -3, -2, 1 }, new[] { -2, -3, 6 }]; + yield return [new[] { 0, 4, 7 }, new[] { 0, 0, 0 }]; + yield return [Array.Empty(), Array.Empty()]; } } diff --git a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M08/Day04Tests.cs b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M08/Day04Tests.cs index 73dc94b..21b3146 100644 --- a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M08/Day04Tests.cs +++ b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M08/Day04Tests.cs @@ -8,7 +8,8 @@ public class Day04Tests { [Theory] [MemberData(nameof(TestData))] - public void GivenNumbers_WhenGetResultByUsingBruteForce_ThenResultAsExpected(int[] numbers, int k, int[] expectedResult) + public void GivenNumbers_WhenGetResultByUsingBruteForce_ThenResultAsExpected( + int[] numbers, int k, int[] expectedResult) { var actualResult = Day04Task.BruteForceApproach.GetResult(numbers, k); actualResult.ShouldBeEquivalentTo(expectedResult); @@ -16,7 +17,8 @@ public void GivenNumbers_WhenGetResultByUsingBruteForce_ThenResultAsExpected(int [Theory] [MemberData(nameof(TestData))] - public void GivenNumbers_WhenGetResultByUsingSlidingWindow_ThenResultAsExpected(int[] numbers, int k, int[] expectedResult) + public void GivenNumbers_WhenGetResultByUsingSlidingWindow_ThenResultAsExpected( + int[] numbers, int k, int[] expectedResult) { var actualResult = Day04Task.SlidingWindowApproach.GetResult(numbers, k); actualResult.ShouldBeEquivalentTo(expectedResult); @@ -24,9 +26,9 @@ public void GivenNumbers_WhenGetResultByUsingSlidingWindow_ThenResultAsExpected( public static IEnumerable TestData() { - yield return [ new[] { 10, 5, 2, 7, 8, 7 }, 3, new[] { 10, 7, 8, 8 } ]; - yield return [ new[] { 1, 3, -1, -3, 5, 3, 6, 7 }, 3, new[] { 3, 3, 5, 5, 6, 7 } ]; - yield return [ new[] { 1 }, 1, new[] { 1 } ]; - yield return [ new[] { 1, -1 }, 1, new[] { 1, -1 } ]; + yield return [new[] { 10, 5, 2, 7, 8, 7 }, 3, new[] { 10, 7, 8, 8 }]; + yield return [new[] { 1, 3, -1, -3, 5, 3, 6, 7 }, 3, new[] { 3, 3, 5, 5, 6, 7 }]; + yield return [new[] { 1 }, 1, new[] { 1 }]; + yield return [new[] { 1, -1 }, 1, new[] { 1, -1 }]; } } diff --git a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M08/Day07Tests.cs b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M08/Day07Tests.cs index bd3ef79..798d383 100644 --- a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M08/Day07Tests.cs +++ b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M08/Day07Tests.cs @@ -8,7 +8,8 @@ public class Day07Tests { [Theory] [MemberData(nameof(TestData))] - public void GivenNumbers_WhenGetResultByUsingBruteForce_ThenResultAsExpected(int[][] numbers, int expectedResult) + public void GivenNumbers_WhenGetResultByUsingBruteForce_ThenResultAsExpected( + int[][] numbers, int expectedResult) { Day07Task.GetMinNumberOfRooms(numbers).ShouldBe(expectedResult); } diff --git a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M08/Day13Tests.cs b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M08/Day13Tests.cs index ab945d4..57ed77e 100644 --- a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M08/Day13Tests.cs +++ b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M08/Day13Tests.cs @@ -16,25 +16,25 @@ public void GivenBrackets_WhenCheckIfBalanced_ThenResultAsExpected(string bracke public static IEnumerable TestData() { - yield return [ "()", true ]; - yield return [ ")(", false ]; - yield return [ "[]", true ]; - yield return [ "][", false ]; - yield return [ "{}", true ]; - yield return [ "}{", false ]; - yield return [ "()[]{}", true ]; - yield return [ "[]{}()", true ]; - yield return [ "{}()[]", true ]; - yield return [ "([{}])", true ]; - yield return [ "([{([{}])}])", true ]; - yield return [ "([])[{}]{()}", true ]; - yield return [ "{[()]}([{}])", true ]; - yield return [ ")[()]", false ]; - yield return [ "([])[", false ]; - yield return [ "(}[)", false ]; - yield return [ "((()", false ]; - yield return [ "()))", false ]; - yield return [ "[[[[[[[[[[]]]]]]]]]", false ]; - yield return [ "{{{{{{{{{}}}}}}}}}}", false ]; + yield return ["()", true]; + yield return [")(", false]; + yield return ["[]", true]; + yield return ["][", false]; + yield return ["{}", true]; + yield return ["}{", false]; + yield return ["()[]{}", true]; + yield return ["[]{}()", true]; + yield return ["{}()[]", true]; + yield return ["([{}])", true]; + yield return ["([{([{}])}])", true]; + yield return ["([])[{}]{()}", true]; + yield return ["{[()]}([{}])", true]; + yield return [")[()]", false]; + yield return ["([])[", false]; + yield return ["(}[)", false]; + yield return ["((()", false]; + yield return ["()))", false]; + yield return ["[[[[[[[[[[]]]]]]]]]", false]; + yield return ["{{{{{{{{{}}}}}}}}}}", false]; } } diff --git a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M09/Day16Tests.cs b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M09/Day16Tests.cs index 098522e..eae74b3 100644 --- a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M09/Day16Tests.cs +++ b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M09/Day16Tests.cs @@ -17,18 +17,18 @@ public void GivenVariableAndExponent_WhenCallRecursivePow_ThenResultAsExpected( public static IEnumerable TestData() { - yield return [ 0, 0, 0 ]; - yield return [ 0, 1, 0 ]; - yield return [ 1, 0, 1 ]; - yield return [ 1, 1, 1 ]; - yield return [ -2, -2, (1.0/4) ]; - yield return [ -2, 2, 4 ]; - yield return [ -2, -3, (-1.0/8) ]; - yield return [ -2, 3, -8 ]; - yield return [ 2, -3, (1.0/8) ]; - yield return [ 2, 3, 8 ]; - yield return [ 2, 10, 1024 ]; - yield return [ 3, -3, (1.0/27) ]; - yield return [ 3, 3, 27 ]; + yield return [0, 0, 0]; + yield return [0, 1, 0]; + yield return [1, 0, 1]; + yield return [1, 1, 1]; + yield return [-2, -2, (1.0 / 4)]; + yield return [-2, 2, 4]; + yield return [-2, -3, (-1.0 / 8)]; + yield return [-2, 3, -8]; + yield return [2, -3, (1.0 / 8)]; + yield return [2, 3, 8]; + yield return [2, 10, 1024]; + yield return [3, -3, (1.0 / 27)]; + yield return [3, 3, 27]; } } diff --git a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M10/Day28/SolutionTests.cs b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M10/Day28/SolutionTests.cs index 569f812..fdb1570 100644 --- a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M10/Day28/SolutionTests.cs +++ b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M10/Day28/SolutionTests.cs @@ -4,6 +4,7 @@ namespace DailyCodingProblem.Challenges.UnitTests.Y2024.M10.Day28; +// TODO: fix the unit tests. public class SolutionTests { [Theory (Skip = "Investigation is required")] diff --git a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M11/Day12/SolutionTests.cs b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M11/Day12/SolutionTests.cs index c4d2e68..45142e9 100644 --- a/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M11/Day12/SolutionTests.cs +++ b/DailyCodingProblem/tests/DailyCodingProblem.Challenges.UnitTests/Y2024/M11/Day12/SolutionTests.cs @@ -8,7 +8,7 @@ public class SolutionTests { [Theory] [MemberData(nameof(TestData))] - public void GivenTree_WhenGetTreeLevelWithMinSum_ThenResultAsExpected(TreeNode root, int expected) + public void GivenTreeNode_WhenGetTreeLevelWithMinSum_ThenResultAsExpected(TreeNode root, int expected) { Solution.GetTreeLevelWithMinSum(root).ShouldBe(expected); } diff --git a/LeetCode/tests/LeetCode.Challenges.UnitTests/Problems02xx/N_0257_BinaryTreePaths/SolutionTests.cs b/LeetCode/tests/LeetCode.Challenges.UnitTests/Problems02xx/N_0257_BinaryTreePaths/SolutionTests.cs index 8f5c937..8ea01ee 100644 --- a/LeetCode/tests/LeetCode.Challenges.UnitTests/Problems02xx/N_0257_BinaryTreePaths/SolutionTests.cs +++ b/LeetCode/tests/LeetCode.Challenges.UnitTests/Problems02xx/N_0257_BinaryTreePaths/SolutionTests.cs @@ -8,7 +8,7 @@ public class SolutionTests { [Theory] [MemberData(nameof(TestData))] - public void GivenTree_WhenSerialize_ThenStringAsExpected(TreeNode root, IList expectedResult) + public void GivenTreeNode_WhenBinaryTreePaths_ThenResultAsExpected(TreeNode root, IList expectedResult) { Solution.BinaryTreePaths(root).Should().BeEquivalentTo(expectedResult); }