Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
eminencegrs committed Dec 9, 2024
1 parent fb2df6a commit e67809c
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ 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);
}

public static IEnumerable<object[]> TestData()
{
yield return [ Array.Empty<int>(), 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>(), 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];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public void GivenNumbers_WhenGetResultNotUsingDivision_ThenResultAsExpected(

public static IEnumerable<object[]> 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<int>(), Array.Empty<int>() ];
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<int>(), Array.Empty<int>()];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@ 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);
}

[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);
}

public static IEnumerable<object[]> 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 }];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ public void GivenBrackets_WhenCheckIfBalanced_ThenResultAsExpected(string bracke

public static IEnumerable<object[]> 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];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ public void GivenVariableAndExponent_WhenCallRecursivePow_ThenResultAsExpected(

public static IEnumerable<object[]> 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];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace DailyCodingProblem.Challenges.UnitTests.Y2024.M10.Day28;

// TODO: fix the unit tests.
public class SolutionTests
{
[Theory (Skip = "Investigation is required")]
Expand Down

0 comments on commit e67809c

Please sign in to comment.