Refactor Day06 part 2, usage of magic number
This commit is contained in:
@@ -26,9 +26,9 @@ namespace AdventOfCode2018.Tests
|
||||
[TestMethod()]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day06 day06 = new Day06();
|
||||
Day06 day06 = new Day06 { DistanceThresold = 32, };
|
||||
|
||||
List<ChronoPoint> points = day06.InputsToPoints(new string[] {
|
||||
string result = day06.ResolvePart2(new string[] {
|
||||
"1, 1",
|
||||
"1, 6",
|
||||
"8, 3",
|
||||
@@ -36,9 +36,8 @@ namespace AdventOfCode2018.Tests
|
||||
"5, 5",
|
||||
"8, 9",
|
||||
});
|
||||
int result = day06.AreaInThresold(points, 32);
|
||||
|
||||
Assert.AreEqual(16, result);
|
||||
Assert.AreEqual("16", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ namespace AdventOfCode2018
|
||||
|
||||
public class Day06 : IDay
|
||||
{
|
||||
public List<ChronoPoint> InputsToPoints(string[] inputs)
|
||||
private List<ChronoPoint> InputsToPoints(string[] inputs)
|
||||
{
|
||||
return inputs
|
||||
.Where(input => string.IsNullOrEmpty(input) == false)
|
||||
@@ -164,7 +164,7 @@ namespace AdventOfCode2018
|
||||
return maxArea.ToString();
|
||||
}
|
||||
|
||||
public int AreaInThresold(List<ChronoPoint> points, int distanceThresold)
|
||||
private int AreaInThresold(List<ChronoPoint> points, int distanceThresold)
|
||||
{
|
||||
int minX = points.Min(p => p.X) - 1;
|
||||
int maxX = points.Max(p => p.X) + 1;
|
||||
@@ -188,10 +188,12 @@ namespace AdventOfCode2018
|
||||
return areaInRange;
|
||||
}
|
||||
|
||||
public int DistanceThresold { get; set; } = 10000;
|
||||
|
||||
public string ResolvePart2(string[] inputs)
|
||||
{
|
||||
List<ChronoPoint> points = InputsToPoints(inputs);
|
||||
int areaInRange = AreaInThresold(points, 10000);
|
||||
int areaInRange = AreaInThresold(points, DistanceThresold);
|
||||
return areaInRange.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user