Code cleanup
This commit is contained in:
@@ -1,36 +1,31 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class ChronoLicenceNode_Tests
|
||||
{
|
||||
public class ChronoLicenceNode_Tests
|
||||
[Fact]
|
||||
public void BuildFromIntStream__Test()
|
||||
{
|
||||
[Fact]
|
||||
public void BuildFromIntStream__Test()
|
||||
{
|
||||
Day08 day = new Day08();
|
||||
IntStream values = new("2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2");
|
||||
ChronoLicenceNode result = ChronoLicenceNode.BuildFromIntStream(values);
|
||||
|
||||
IntStream values = new IntStream("2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2");
|
||||
ChronoLicenceNode result = ChronoLicenceNode.BuildFromIntStream(values);
|
||||
Assert.Equal(2, result.Childs.Count);
|
||||
Assert.Equal(3, result.Metadata.Count);
|
||||
Assert.Equal(1, result.Metadata[0]);
|
||||
Assert.Equal(1, result.Metadata[1]);
|
||||
Assert.Equal(2, result.Metadata[2]);
|
||||
|
||||
Assert.Equal(2, result.Childs.Count);
|
||||
Assert.Equal(3, result.Metadata.Count);
|
||||
Assert.Equal(1, result.Metadata[0]);
|
||||
Assert.Equal(1, result.Metadata[1]);
|
||||
Assert.Equal(2, result.Metadata[2]);
|
||||
Assert.Empty(result.Childs[0].Childs);
|
||||
Assert.Equal(3, result.Childs[0].Metadata.Count);
|
||||
Assert.Equal(10, result.Childs[0].Metadata[0]);
|
||||
Assert.Equal(11, result.Childs[0].Metadata[1]);
|
||||
Assert.Equal(12, result.Childs[0].Metadata[2]);
|
||||
|
||||
Assert.Equal(0, result.Childs[0].Childs.Count);
|
||||
Assert.Equal(3, result.Childs[0].Metadata.Count);
|
||||
Assert.Equal(10, result.Childs[0].Metadata[0]);
|
||||
Assert.Equal(11, result.Childs[0].Metadata[1]);
|
||||
Assert.Equal(12, result.Childs[0].Metadata[2]);
|
||||
Assert.Single(result.Childs[1].Childs);
|
||||
Assert.Single(result.Childs[1].Metadata);
|
||||
Assert.Equal(2, result.Childs[1].Metadata[0]);
|
||||
|
||||
Assert.Equal(1, result.Childs[1].Childs.Count);
|
||||
Assert.Equal(1, result.Childs[1].Metadata.Count);
|
||||
Assert.Equal(2, result.Childs[1].Metadata[0]);
|
||||
|
||||
Assert.Equal(0, result.Childs[1].Childs[0].Childs.Count);
|
||||
Assert.Equal(1, result.Childs[1].Childs[0].Metadata.Count);
|
||||
Assert.Equal(99, result.Childs[1].Childs[0].Metadata[0]);
|
||||
}
|
||||
Assert.Empty(result.Childs[1].Childs[0].Childs);
|
||||
Assert.Single(result.Childs[1].Childs[0].Metadata);
|
||||
Assert.Equal(99, result.Childs[1].Childs[0].Metadata[0]);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +1,61 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class ChronoPoint_Tests
|
||||
{
|
||||
public class ChronoPoint_Tests
|
||||
#region FromString
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test1()
|
||||
{
|
||||
#region FromString
|
||||
ChronoPoint point = ChronoPoint.FromString("1, 1");
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test1()
|
||||
{
|
||||
ChronoPoint point = ChronoPoint.FromString("1, 1");
|
||||
|
||||
Assert.Equal(1, point.X);
|
||||
Assert.Equal(1, point.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test2()
|
||||
{
|
||||
ChronoPoint point = ChronoPoint.FromString("1, 6");
|
||||
|
||||
Assert.Equal(1, point.X);
|
||||
Assert.Equal(6, point.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test3()
|
||||
{
|
||||
ChronoPoint point = ChronoPoint.FromString("8, 9");
|
||||
|
||||
Assert.Equal(8, point.X);
|
||||
Assert.Equal(9, point.Y);
|
||||
}
|
||||
|
||||
#endregion FromString
|
||||
|
||||
#region ManhattanDistance
|
||||
|
||||
[Fact]
|
||||
public void ManhattanDistance__Test1()
|
||||
{
|
||||
ChronoPoint p0 = ChronoPoint.FromString("8, 9");
|
||||
ChronoPoint p1 = ChronoPoint.FromString("1, 6");
|
||||
|
||||
int distance = ChronoPoint.ManhattanDistance(p0, p1);
|
||||
|
||||
Assert.Equal(10, distance);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ManhattanDistance__Test2()
|
||||
{
|
||||
ChronoPoint p0 = ChronoPoint.FromString("1, 1");
|
||||
ChronoPoint p1 = ChronoPoint.FromString("1, 6");
|
||||
|
||||
int distance = ChronoPoint.ManhattanDistance(p0, p1);
|
||||
|
||||
Assert.Equal(5, distance);
|
||||
}
|
||||
|
||||
#endregion ManhattanDistance
|
||||
Assert.Equal(1, point.X);
|
||||
Assert.Equal(1, point.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test2()
|
||||
{
|
||||
ChronoPoint point = ChronoPoint.FromString("1, 6");
|
||||
|
||||
Assert.Equal(1, point.X);
|
||||
Assert.Equal(6, point.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test3()
|
||||
{
|
||||
ChronoPoint point = ChronoPoint.FromString("8, 9");
|
||||
|
||||
Assert.Equal(8, point.X);
|
||||
Assert.Equal(9, point.Y);
|
||||
}
|
||||
|
||||
#endregion FromString
|
||||
|
||||
#region ManhattanDistance
|
||||
|
||||
[Fact]
|
||||
public void ManhattanDistance__Test1()
|
||||
{
|
||||
ChronoPoint p0 = ChronoPoint.FromString("8, 9");
|
||||
ChronoPoint p1 = ChronoPoint.FromString("1, 6");
|
||||
|
||||
int distance = ChronoPoint.ManhattanDistance(p0, p1);
|
||||
|
||||
Assert.Equal(10, distance);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ManhattanDistance__Test2()
|
||||
{
|
||||
ChronoPoint p0 = ChronoPoint.FromString("1, 1");
|
||||
ChronoPoint p1 = ChronoPoint.FromString("1, 6");
|
||||
|
||||
int distance = ChronoPoint.ManhattanDistance(p0, p1);
|
||||
|
||||
Assert.Equal(5, distance);
|
||||
}
|
||||
|
||||
#endregion ManhattanDistance
|
||||
}
|
||||
@@ -1,96 +1,93 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Claim_Tests
|
||||
{
|
||||
public class Claim_Tests
|
||||
#region FromString
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test1()
|
||||
{
|
||||
#region FromString
|
||||
Day03.Claim claim = Day03.Claim.FromString("#123 @ 3,2: 5x4");
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test1()
|
||||
{
|
||||
Day03.Claim claim = Day03.Claim.FromString("#123 @ 3,2: 5x4");
|
||||
|
||||
Assert.Equal(123, claim.ID);
|
||||
Assert.Equal(3, claim.Left);
|
||||
Assert.Equal(2, claim.Top);
|
||||
Assert.Equal(5, claim.Width);
|
||||
Assert.Equal(4, claim.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test2()
|
||||
{
|
||||
Day03.Claim claim = Day03.Claim.FromString("#1 @ 1,3: 4x4");
|
||||
|
||||
Assert.Equal(1, claim.ID);
|
||||
Assert.Equal(1, claim.Left);
|
||||
Assert.Equal(3, claim.Top);
|
||||
Assert.Equal(4, claim.Width);
|
||||
Assert.Equal(4, claim.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test3()
|
||||
{
|
||||
Day03.Claim claim = Day03.Claim.FromString("#2 @ 3,1: 4x4");
|
||||
|
||||
Assert.Equal(2, claim.ID);
|
||||
Assert.Equal(3, claim.Left);
|
||||
Assert.Equal(1, claim.Top);
|
||||
Assert.Equal(4, claim.Width);
|
||||
Assert.Equal(4, claim.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test4()
|
||||
{
|
||||
Day03.Claim claim = Day03.Claim.FromString("#3 @ 5,5: 2x2");
|
||||
|
||||
Assert.Equal(3, claim.ID);
|
||||
Assert.Equal(5, claim.Left);
|
||||
Assert.Equal(5, claim.Top);
|
||||
Assert.Equal(2, claim.Width);
|
||||
Assert.Equal(2, claim.Height);
|
||||
}
|
||||
|
||||
#endregion FromString
|
||||
|
||||
#region Overlaps
|
||||
|
||||
[Fact]
|
||||
public void Overlaps__Test1()
|
||||
{
|
||||
Day03.Claim claim1 = Day03.Claim.FromString("#1 @ 1,3: 4x4");
|
||||
Day03.Claim claim2 = Day03.Claim.FromString("#3 @ 5,5: 2x2");
|
||||
|
||||
bool result = Day03.Claim.Overlaps(claim1, claim2);
|
||||
|
||||
Assert.Equal(false, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Overlaps__Test2()
|
||||
{
|
||||
Day03.Claim claim1 = Day03.Claim.FromString("#2 @ 3,1: 4x4");
|
||||
Day03.Claim claim2 = Day03.Claim.FromString("#3 @ 5,5: 2x2");
|
||||
|
||||
bool result = Day03.Claim.Overlaps(claim1, claim2);
|
||||
|
||||
Assert.Equal(false, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Overlaps__Test3()
|
||||
{
|
||||
Day03.Claim claim1 = Day03.Claim.FromString("#1 @ 1,3: 4x4");
|
||||
Day03.Claim claim2 = Day03.Claim.FromString("#2 @ 3,1: 4x4");
|
||||
|
||||
bool result = Day03.Claim.Overlaps(claim1, claim2);
|
||||
|
||||
Assert.Equal(true, result);
|
||||
}
|
||||
|
||||
#endregion Overlaps
|
||||
Assert.Equal(123, claim.ID);
|
||||
Assert.Equal(3, claim.Left);
|
||||
Assert.Equal(2, claim.Top);
|
||||
Assert.Equal(5, claim.Width);
|
||||
Assert.Equal(4, claim.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test2()
|
||||
{
|
||||
Day03.Claim claim = Day03.Claim.FromString("#1 @ 1,3: 4x4");
|
||||
|
||||
Assert.Equal(1, claim.ID);
|
||||
Assert.Equal(1, claim.Left);
|
||||
Assert.Equal(3, claim.Top);
|
||||
Assert.Equal(4, claim.Width);
|
||||
Assert.Equal(4, claim.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test3()
|
||||
{
|
||||
Day03.Claim claim = Day03.Claim.FromString("#2 @ 3,1: 4x4");
|
||||
|
||||
Assert.Equal(2, claim.ID);
|
||||
Assert.Equal(3, claim.Left);
|
||||
Assert.Equal(1, claim.Top);
|
||||
Assert.Equal(4, claim.Width);
|
||||
Assert.Equal(4, claim.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__Test4()
|
||||
{
|
||||
Day03.Claim claim = Day03.Claim.FromString("#3 @ 5,5: 2x2");
|
||||
|
||||
Assert.Equal(3, claim.ID);
|
||||
Assert.Equal(5, claim.Left);
|
||||
Assert.Equal(5, claim.Top);
|
||||
Assert.Equal(2, claim.Width);
|
||||
Assert.Equal(2, claim.Height);
|
||||
}
|
||||
|
||||
#endregion FromString
|
||||
|
||||
#region Overlaps
|
||||
|
||||
[Fact]
|
||||
public void Overlaps__Test1()
|
||||
{
|
||||
Day03.Claim claim1 = Day03.Claim.FromString("#1 @ 1,3: 4x4");
|
||||
Day03.Claim claim2 = Day03.Claim.FromString("#3 @ 5,5: 2x2");
|
||||
|
||||
bool result = Day03.Claim.Overlaps(claim1, claim2);
|
||||
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Overlaps__Test2()
|
||||
{
|
||||
Day03.Claim claim1 = Day03.Claim.FromString("#2 @ 3,1: 4x4");
|
||||
Day03.Claim claim2 = Day03.Claim.FromString("#3 @ 5,5: 2x2");
|
||||
|
||||
bool result = Day03.Claim.Overlaps(claim1, claim2);
|
||||
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Overlaps__Test3()
|
||||
{
|
||||
Day03.Claim claim1 = Day03.Claim.FromString("#1 @ 1,3: 4x4");
|
||||
Day03.Claim claim2 = Day03.Claim.FromString("#2 @ 3,1: 4x4");
|
||||
|
||||
bool result = Day03.Claim.Overlaps(claim1, claim2);
|
||||
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
#endregion Overlaps
|
||||
}
|
||||
@@ -1,105 +1,102 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day01_Tests
|
||||
{
|
||||
public class Day01_Tests
|
||||
#region ResolvePart1
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test1()
|
||||
{
|
||||
#region ResolvePart1
|
||||
Day01 day01 = new();
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test1()
|
||||
{
|
||||
Day01 day01 = new Day01();
|
||||
string result = day01.ResolvePart1(new[] { "+1", "-2", "+3", "+1", });
|
||||
|
||||
string result = day01.ResolvePart1(new string[] { "+1", "-2", "+3", "+1", });
|
||||
|
||||
Assert.Equal("3", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test2()
|
||||
{
|
||||
Day01 day01 = new Day01();
|
||||
|
||||
string result = day01.ResolvePart1(new string[] { "+1", "+1", "+1", });
|
||||
|
||||
Assert.Equal("3", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test3()
|
||||
{
|
||||
Day01 day01 = new Day01();
|
||||
|
||||
string result = day01.ResolvePart1(new string[] { "+1", "+1", "-2", });
|
||||
|
||||
Assert.Equal("0", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test4()
|
||||
{
|
||||
Day01 day01 = new Day01();
|
||||
|
||||
string result = day01.ResolvePart1(new string[] { "-1", "-2", "-3", });
|
||||
|
||||
Assert.Equal("-6", result);
|
||||
}
|
||||
|
||||
#endregion ResolveDay01
|
||||
|
||||
#region ResolvePart2
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test1()
|
||||
{
|
||||
Day01 day01 = new Day01();
|
||||
|
||||
string result = day01.ResolvePart2(new string[] { "+1", "-2", "+3", "+1", });
|
||||
|
||||
Assert.Equal("2", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test2()
|
||||
{
|
||||
Day01 day01 = new Day01();
|
||||
|
||||
string result = day01.ResolvePart2(new string[] { "+1", "-1", });
|
||||
|
||||
Assert.Equal("0", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test3()
|
||||
{
|
||||
Day01 day01 = new Day01();
|
||||
|
||||
string result = day01.ResolvePart2(new string[] { "+3", "+3", "+4", "-2", "-4", });
|
||||
|
||||
Assert.Equal("10", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test4()
|
||||
{
|
||||
Day01 day01 = new Day01();
|
||||
|
||||
string result = day01.ResolvePart2(new string[] { "-6", "+3", "+8", "+5", "-6", });
|
||||
|
||||
Assert.Equal("5", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test5()
|
||||
{
|
||||
Day01 day01 = new Day01();
|
||||
|
||||
string result = day01.ResolvePart2(new string[] { "+7", "+7", "-2", "-7", "-4", });
|
||||
|
||||
Assert.Equal("14", result);
|
||||
}
|
||||
|
||||
#endregion ResolvePart2
|
||||
Assert.Equal("3", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test2()
|
||||
{
|
||||
Day01 day01 = new();
|
||||
|
||||
string result = day01.ResolvePart1(new[] { "+1", "+1", "+1", });
|
||||
|
||||
Assert.Equal("3", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test3()
|
||||
{
|
||||
Day01 day01 = new();
|
||||
|
||||
string result = day01.ResolvePart1(new[] { "+1", "+1", "-2", });
|
||||
|
||||
Assert.Equal("0", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test4()
|
||||
{
|
||||
Day01 day01 = new();
|
||||
|
||||
string result = day01.ResolvePart1(new[] { "-1", "-2", "-3", });
|
||||
|
||||
Assert.Equal("-6", result);
|
||||
}
|
||||
|
||||
#endregion ResolveDay01
|
||||
|
||||
#region ResolvePart2
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test1()
|
||||
{
|
||||
Day01 day01 = new();
|
||||
|
||||
string result = day01.ResolvePart2(new[] { "+1", "-2", "+3", "+1", });
|
||||
|
||||
Assert.Equal("2", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test2()
|
||||
{
|
||||
Day01 day01 = new();
|
||||
|
||||
string result = day01.ResolvePart2(new[] { "+1", "-1", });
|
||||
|
||||
Assert.Equal("0", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test3()
|
||||
{
|
||||
Day01 day01 = new();
|
||||
|
||||
string result = day01.ResolvePart2(new[] { "+3", "+3", "+4", "-2", "-4", });
|
||||
|
||||
Assert.Equal("10", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test4()
|
||||
{
|
||||
Day01 day01 = new();
|
||||
|
||||
string result = day01.ResolvePart2(new[] { "-6", "+3", "+8", "+5", "-6", });
|
||||
|
||||
Assert.Equal("5", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test5()
|
||||
{
|
||||
Day01 day01 = new();
|
||||
|
||||
string result = day01.ResolvePart2(new[] { "+7", "+7", "-2", "-7", "-4", });
|
||||
|
||||
Assert.Equal("14", result);
|
||||
}
|
||||
|
||||
#endregion ResolvePart2
|
||||
}
|
||||
@@ -1,43 +1,40 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day02_Tests
|
||||
{
|
||||
public class Day02_Tests
|
||||
[Fact]
|
||||
public void ResolvePart1__Test1()
|
||||
{
|
||||
[Fact]
|
||||
public void ResolvePart1__Test1()
|
||||
{
|
||||
Day02 day02 = new Day02();
|
||||
Day02 day02 = new();
|
||||
|
||||
string result = day02.ResolvePart1(new string[] {
|
||||
"abcdef",
|
||||
"bababc",
|
||||
"abbcde",
|
||||
"abcccd",
|
||||
"aabcdd",
|
||||
"abcdee",
|
||||
"ababab",
|
||||
});
|
||||
string result = day02.ResolvePart1(new[] {
|
||||
"abcdef",
|
||||
"bababc",
|
||||
"abbcde",
|
||||
"abcccd",
|
||||
"aabcdd",
|
||||
"abcdee",
|
||||
"ababab",
|
||||
});
|
||||
|
||||
Assert.Equal("12", result);
|
||||
}
|
||||
Assert.Equal("12", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day02 day02 = new Day02();
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day02 day02 = new();
|
||||
|
||||
string result = day02.ResolvePart2(new string[] {
|
||||
"abcde",
|
||||
"fghij",
|
||||
"klmno",
|
||||
"pqrst",
|
||||
"fguij",
|
||||
"axcye",
|
||||
"wvxyz",
|
||||
});
|
||||
string result = day02.ResolvePart2(new[] {
|
||||
"abcde",
|
||||
"fghij",
|
||||
"klmno",
|
||||
"pqrst",
|
||||
"fguij",
|
||||
"axcye",
|
||||
"wvxyz",
|
||||
});
|
||||
|
||||
Assert.Equal("fgij", result);
|
||||
}
|
||||
Assert.Equal("fgij", result);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,32 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day03_Tests
|
||||
{
|
||||
public class Day03_Tests
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
Day03 day03 = new Day03();
|
||||
Day03 day03 = new();
|
||||
|
||||
string result = day03.ResolvePart1(new string[] {
|
||||
"#1 @ 1,3: 4x4",
|
||||
"#2 @ 3,1: 4x4",
|
||||
"#3 @ 5,5: 2x2",
|
||||
});
|
||||
string result = day03.ResolvePart1(new[] {
|
||||
"#1 @ 1,3: 4x4",
|
||||
"#2 @ 3,1: 4x4",
|
||||
"#3 @ 5,5: 2x2",
|
||||
});
|
||||
|
||||
Assert.Equal("4", result);
|
||||
}
|
||||
Assert.Equal("4", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day03 day03 = new Day03();
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day03 day03 = new();
|
||||
|
||||
string result = day03.ResolvePart2(new string[] {
|
||||
"#1 @ 1,3: 4x4",
|
||||
"#2 @ 3,1: 4x4",
|
||||
"#3 @ 5,5: 2x2",
|
||||
});
|
||||
string result = day03.ResolvePart2(new[] {
|
||||
"#1 @ 1,3: 4x4",
|
||||
"#2 @ 3,1: 4x4",
|
||||
"#3 @ 5,5: 2x2",
|
||||
});
|
||||
|
||||
Assert.Equal("3", result);
|
||||
}
|
||||
Assert.Equal("3", result);
|
||||
}
|
||||
}
|
||||
@@ -1,120 +1,117 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day04_Tests
|
||||
{
|
||||
public class Day04_Tests
|
||||
[Fact]
|
||||
public void ResolvePart1__BaseStatement()
|
||||
{
|
||||
[Fact]
|
||||
public void ResolvePart1__BaseStatement()
|
||||
{
|
||||
Day04 day04 = new Day04();
|
||||
Day04 day04 = new();
|
||||
|
||||
string result = day04.ResolvePart1(new string[] {
|
||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||
"[1518-11-01 00:05] falls asleep",
|
||||
"[1518-11-01 00:25] wakes up",
|
||||
"[1518-11-01 00:30] falls asleep",
|
||||
"[1518-11-01 00:55] wakes up",
|
||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||
"[1518-11-02 00:40] falls asleep",
|
||||
"[1518-11-02 00:50] wakes up",
|
||||
"[1518-11-03 00:05] Guard #10 begins shift",
|
||||
"[1518-11-03 00:24] falls asleep",
|
||||
"[1518-11-03 00:29] wakes up",
|
||||
"[1518-11-04 00:02] Guard #99 begins shift",
|
||||
"[1518-11-04 00:36] falls asleep",
|
||||
"[1518-11-04 00:46] wakes up",
|
||||
"[1518-11-05 00:03] Guard #99 begins shift",
|
||||
"[1518-11-05 00:45] falls asleep",
|
||||
"[1518-11-05 00:55] wakes up",
|
||||
});
|
||||
string result = day04.ResolvePart1(new[] {
|
||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||
"[1518-11-01 00:05] falls asleep",
|
||||
"[1518-11-01 00:25] wakes up",
|
||||
"[1518-11-01 00:30] falls asleep",
|
||||
"[1518-11-01 00:55] wakes up",
|
||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||
"[1518-11-02 00:40] falls asleep",
|
||||
"[1518-11-02 00:50] wakes up",
|
||||
"[1518-11-03 00:05] Guard #10 begins shift",
|
||||
"[1518-11-03 00:24] falls asleep",
|
||||
"[1518-11-03 00:29] wakes up",
|
||||
"[1518-11-04 00:02] Guard #99 begins shift",
|
||||
"[1518-11-04 00:36] falls asleep",
|
||||
"[1518-11-04 00:46] wakes up",
|
||||
"[1518-11-05 00:03] Guard #99 begins shift",
|
||||
"[1518-11-05 00:45] falls asleep",
|
||||
"[1518-11-05 00:55] wakes up",
|
||||
});
|
||||
|
||||
Assert.Equal("240", result);
|
||||
}
|
||||
Assert.Equal("240", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__BaseStatementUnsorted()
|
||||
{
|
||||
Day04 day04 = new Day04();
|
||||
[Fact]
|
||||
public void ResolvePart1__BaseStatementUnsorted()
|
||||
{
|
||||
Day04 day04 = new();
|
||||
|
||||
string result = day04.ResolvePart1(new string[] {
|
||||
"[1518-11-04 00:36] falls asleep",
|
||||
"[1518-11-04 00:46] wakes up",
|
||||
"[1518-11-05 00:03] Guard #99 begins shift",
|
||||
"[1518-11-01 00:05] falls asleep",
|
||||
"[1518-11-01 00:25] wakes up",
|
||||
"[1518-11-02 00:40] falls asleep",
|
||||
"[1518-11-01 00:30] falls asleep",
|
||||
"[1518-11-03 00:29] wakes up",
|
||||
"[1518-11-02 00:50] wakes up",
|
||||
"[1518-11-03 00:05] Guard #10 begins shift",
|
||||
"[1518-11-03 00:24] falls asleep",
|
||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||
"[1518-11-04 00:02] Guard #99 begins shift",
|
||||
"[1518-11-05 00:45] falls asleep",
|
||||
"[1518-11-01 00:55] wakes up",
|
||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||
"[1518-11-05 00:55] wakes up",
|
||||
});
|
||||
string result = day04.ResolvePart1(new[] {
|
||||
"[1518-11-04 00:36] falls asleep",
|
||||
"[1518-11-04 00:46] wakes up",
|
||||
"[1518-11-05 00:03] Guard #99 begins shift",
|
||||
"[1518-11-01 00:05] falls asleep",
|
||||
"[1518-11-01 00:25] wakes up",
|
||||
"[1518-11-02 00:40] falls asleep",
|
||||
"[1518-11-01 00:30] falls asleep",
|
||||
"[1518-11-03 00:29] wakes up",
|
||||
"[1518-11-02 00:50] wakes up",
|
||||
"[1518-11-03 00:05] Guard #10 begins shift",
|
||||
"[1518-11-03 00:24] falls asleep",
|
||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||
"[1518-11-04 00:02] Guard #99 begins shift",
|
||||
"[1518-11-05 00:45] falls asleep",
|
||||
"[1518-11-01 00:55] wakes up",
|
||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||
"[1518-11-05 00:55] wakes up",
|
||||
});
|
||||
|
||||
Assert.Equal("240", result);
|
||||
}
|
||||
Assert.Equal("240", result);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__BaseStatement()
|
||||
{
|
||||
Day04 day04 = new Day04();
|
||||
[Fact]
|
||||
public void ResolvePart2__BaseStatement()
|
||||
{
|
||||
Day04 day04 = new();
|
||||
|
||||
string result = day04.ResolvePart2(new string[] {
|
||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||
"[1518-11-01 00:05] falls asleep",
|
||||
"[1518-11-01 00:25] wakes up",
|
||||
"[1518-11-01 00:30] falls asleep",
|
||||
"[1518-11-01 00:55] wakes up",
|
||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||
"[1518-11-02 00:40] falls asleep",
|
||||
"[1518-11-02 00:50] wakes up",
|
||||
"[1518-11-03 00:05] Guard #10 begins shift",
|
||||
"[1518-11-03 00:24] falls asleep",
|
||||
"[1518-11-03 00:29] wakes up",
|
||||
"[1518-11-04 00:02] Guard #99 begins shift",
|
||||
"[1518-11-04 00:36] falls asleep",
|
||||
"[1518-11-04 00:46] wakes up",
|
||||
"[1518-11-05 00:03] Guard #99 begins shift",
|
||||
"[1518-11-05 00:45] falls asleep",
|
||||
"[1518-11-05 00:55] wakes up",
|
||||
});
|
||||
string result = day04.ResolvePart2(new[] {
|
||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||
"[1518-11-01 00:05] falls asleep",
|
||||
"[1518-11-01 00:25] wakes up",
|
||||
"[1518-11-01 00:30] falls asleep",
|
||||
"[1518-11-01 00:55] wakes up",
|
||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||
"[1518-11-02 00:40] falls asleep",
|
||||
"[1518-11-02 00:50] wakes up",
|
||||
"[1518-11-03 00:05] Guard #10 begins shift",
|
||||
"[1518-11-03 00:24] falls asleep",
|
||||
"[1518-11-03 00:29] wakes up",
|
||||
"[1518-11-04 00:02] Guard #99 begins shift",
|
||||
"[1518-11-04 00:36] falls asleep",
|
||||
"[1518-11-04 00:46] wakes up",
|
||||
"[1518-11-05 00:03] Guard #99 begins shift",
|
||||
"[1518-11-05 00:45] falls asleep",
|
||||
"[1518-11-05 00:55] wakes up",
|
||||
});
|
||||
|
||||
Assert.Equal("4455", result);
|
||||
}
|
||||
Assert.Equal("4455", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__BaseStatementUnsorted()
|
||||
{
|
||||
Day04 day04 = new Day04();
|
||||
[Fact]
|
||||
public void ResolvePart2__BaseStatementUnsorted()
|
||||
{
|
||||
Day04 day04 = new();
|
||||
|
||||
string result = day04.ResolvePart2(new string[] {
|
||||
"[1518-11-04 00:36] falls asleep",
|
||||
"[1518-11-04 00:46] wakes up",
|
||||
"[1518-11-05 00:03] Guard #99 begins shift",
|
||||
"[1518-11-01 00:05] falls asleep",
|
||||
"[1518-11-01 00:25] wakes up",
|
||||
"[1518-11-02 00:40] falls asleep",
|
||||
"[1518-11-01 00:30] falls asleep",
|
||||
"[1518-11-03 00:29] wakes up",
|
||||
"[1518-11-02 00:50] wakes up",
|
||||
"[1518-11-03 00:05] Guard #10 begins shift",
|
||||
"[1518-11-03 00:24] falls asleep",
|
||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||
"[1518-11-04 00:02] Guard #99 begins shift",
|
||||
"[1518-11-05 00:45] falls asleep",
|
||||
"[1518-11-01 00:55] wakes up",
|
||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||
"[1518-11-05 00:55] wakes up",
|
||||
});
|
||||
string result = day04.ResolvePart2(new[] {
|
||||
"[1518-11-04 00:36] falls asleep",
|
||||
"[1518-11-04 00:46] wakes up",
|
||||
"[1518-11-05 00:03] Guard #99 begins shift",
|
||||
"[1518-11-01 00:05] falls asleep",
|
||||
"[1518-11-01 00:25] wakes up",
|
||||
"[1518-11-02 00:40] falls asleep",
|
||||
"[1518-11-01 00:30] falls asleep",
|
||||
"[1518-11-03 00:29] wakes up",
|
||||
"[1518-11-02 00:50] wakes up",
|
||||
"[1518-11-03 00:05] Guard #10 begins shift",
|
||||
"[1518-11-03 00:24] falls asleep",
|
||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||
"[1518-11-04 00:02] Guard #99 begins shift",
|
||||
"[1518-11-05 00:45] falls asleep",
|
||||
"[1518-11-01 00:55] wakes up",
|
||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||
"[1518-11-05 00:55] wakes up",
|
||||
});
|
||||
|
||||
Assert.Equal("4455", result);
|
||||
}
|
||||
Assert.Equal("4455", result);
|
||||
}
|
||||
}
|
||||
@@ -1,199 +1,196 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day05_Tests
|
||||
{
|
||||
public class Day05_Tests
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.ResolvePart1(new string[] { "dabAcCaCBAcCcaDA" });
|
||||
string result = day05.ResolvePart1(new[] { "dabAcCaCBAcCcaDA" });
|
||||
|
||||
Assert.Equal("10", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.ResolvePart2(new string[] { "dabAcCaCBAcCcaDA" });
|
||||
|
||||
Assert.Equal("4", result);
|
||||
}
|
||||
|
||||
#region ReducePolymer
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Remove_cC()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.ReducePolymer("dabAcCaCBA");
|
||||
|
||||
Assert.Equal("dabAaCBA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Remove_cC_AtEnd()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.ReducePolymer("dabAcC");
|
||||
|
||||
Assert.Equal("dabA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Remove_Only_cC()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.ReducePolymer("cC");
|
||||
|
||||
Assert.Equal("", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Remove_cC_AtStart()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.ReducePolymer("cCAAAA");
|
||||
|
||||
Assert.Equal("AAAA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Remove_Aa()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.ReducePolymer("dabAaCBA");
|
||||
|
||||
Assert.Equal("dabCBA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Remove_cCc()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.ReducePolymer("dabCBAcCcaDA");
|
||||
|
||||
Assert.Equal("dabCBAcaDA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Irreductible()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.ReducePolymer("dabCBAcaDA");
|
||||
|
||||
Assert.Equal("dabCBAcaDA", result);
|
||||
}
|
||||
|
||||
#endregion ReducePolymer
|
||||
|
||||
#region FullyReducePolymer
|
||||
|
||||
[Fact]
|
||||
public void FullyReducePolymer__Test()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.FullyReducePolymer("dabAcCaCBAcCcaDA");
|
||||
|
||||
Assert.Equal("dabCBAcaDA", result);
|
||||
}
|
||||
|
||||
#endregion FullyReducePolymer
|
||||
|
||||
#region RemoveUnitTypeFromPolymer
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_a()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'a');
|
||||
|
||||
Assert.Equal("dbcCCBcCcD", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_b()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'b');
|
||||
|
||||
Assert.Equal("daAcCaCAcCcaDA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_c()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'c');
|
||||
|
||||
Assert.Equal("dabAaBAaDA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_d()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'd');
|
||||
|
||||
Assert.Equal("abAcCaCBAcCcaA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_A()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'A');
|
||||
|
||||
Assert.Equal("dbcCCBcCcD", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_B()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'B');
|
||||
|
||||
Assert.Equal("daAcCaCAcCcaDA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_C()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'C');
|
||||
|
||||
Assert.Equal("dabAaBAaDA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_D()
|
||||
{
|
||||
Day05 day05 = new Day05();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'D');
|
||||
|
||||
Assert.Equal("abAcCaCBAcCcaA", result);
|
||||
}
|
||||
|
||||
#endregion RemoveUnitTypeFromPolymer
|
||||
Assert.Equal("10", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.ResolvePart2(new[] { "dabAcCaCBAcCcaDA" });
|
||||
|
||||
Assert.Equal("4", result);
|
||||
}
|
||||
|
||||
#region ReducePolymer
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Remove_cC()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.ReducePolymer("dabAcCaCBA");
|
||||
|
||||
Assert.Equal("dabAaCBA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Remove_cC_AtEnd()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.ReducePolymer("dabAcC");
|
||||
|
||||
Assert.Equal("dabA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Remove_Only_cC()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.ReducePolymer("cC");
|
||||
|
||||
Assert.Equal("", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Remove_cC_AtStart()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.ReducePolymer("cCAAAA");
|
||||
|
||||
Assert.Equal("AAAA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Remove_Aa()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.ReducePolymer("dabAaCBA");
|
||||
|
||||
Assert.Equal("dabCBA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Remove_cCc()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.ReducePolymer("dabCBAcCcaDA");
|
||||
|
||||
Assert.Equal("dabCBAcaDA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReducePolymer__Irreductible()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.ReducePolymer("dabCBAcaDA");
|
||||
|
||||
Assert.Equal("dabCBAcaDA", result);
|
||||
}
|
||||
|
||||
#endregion ReducePolymer
|
||||
|
||||
#region FullyReducePolymer
|
||||
|
||||
[Fact]
|
||||
public void FullyReducePolymer__Test()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.FullyReducePolymer("dabAcCaCBAcCcaDA");
|
||||
|
||||
Assert.Equal("dabCBAcaDA", result);
|
||||
}
|
||||
|
||||
#endregion FullyReducePolymer
|
||||
|
||||
#region RemoveUnitTypeFromPolymer
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_a()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'a');
|
||||
|
||||
Assert.Equal("dbcCCBcCcD", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_b()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'b');
|
||||
|
||||
Assert.Equal("daAcCaCAcCcaDA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_c()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'c');
|
||||
|
||||
Assert.Equal("dabAaBAaDA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_d()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'd');
|
||||
|
||||
Assert.Equal("abAcCaCBAcCcaA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_A()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'A');
|
||||
|
||||
Assert.Equal("dbcCCBcCcD", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_B()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'B');
|
||||
|
||||
Assert.Equal("daAcCaCAcCcaDA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_C()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'C');
|
||||
|
||||
Assert.Equal("dabAaBAaDA", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveUnitTypeFromPolymer__Remove_D()
|
||||
{
|
||||
Day05 day05 = new();
|
||||
|
||||
string result = day05.RemoveUnitTypeFromPolymer("dabAcCaCBAcCcaDA", 'D');
|
||||
|
||||
Assert.Equal("abAcCaCBAcCcaA", result);
|
||||
}
|
||||
|
||||
#endregion RemoveUnitTypeFromPolymer
|
||||
}
|
||||
@@ -1,42 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day06_Tests
|
||||
{
|
||||
public class Day06_Tests
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
Day06 day06 = new Day06();
|
||||
Day06 day06 = new();
|
||||
|
||||
string result = day06.ResolvePart1(new string[] {
|
||||
"1, 1",
|
||||
"1, 6",
|
||||
"8, 3",
|
||||
"3, 4",
|
||||
"5, 5",
|
||||
"8, 9",
|
||||
});
|
||||
string result = day06.ResolvePart1(new[] {
|
||||
"1, 1",
|
||||
"1, 6",
|
||||
"8, 3",
|
||||
"3, 4",
|
||||
"5, 5",
|
||||
"8, 9",
|
||||
});
|
||||
|
||||
Assert.Equal("17", result);
|
||||
}
|
||||
Assert.Equal("17", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day06 day06 = new Day06 { DistanceThresold = 32, };
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day06 day06 = new() { DistanceThresold = 32, };
|
||||
|
||||
string result = day06.ResolvePart2(new string[] {
|
||||
"1, 1",
|
||||
"1, 6",
|
||||
"8, 3",
|
||||
"3, 4",
|
||||
"5, 5",
|
||||
"8, 9",
|
||||
});
|
||||
string result = day06.ResolvePart2(new[] {
|
||||
"1, 1",
|
||||
"1, 6",
|
||||
"8, 3",
|
||||
"3, 4",
|
||||
"5, 5",
|
||||
"8, 9",
|
||||
});
|
||||
|
||||
Assert.Equal("16", result);
|
||||
}
|
||||
Assert.Equal("16", result);
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,40 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day07_Tests
|
||||
{
|
||||
public class Day07_Tests
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
Day07 day07 = new Day07();
|
||||
Day07 day07 = new();
|
||||
|
||||
string result = day07.ResolvePart1(new string[] {
|
||||
"Step C must be finished before step A can begin.",
|
||||
"Step C must be finished before step F can begin.",
|
||||
"Step A must be finished before step B can begin.",
|
||||
"Step A must be finished before step D can begin.",
|
||||
"Step B must be finished before step E can begin.",
|
||||
"Step D must be finished before step E can begin.",
|
||||
"Step F must be finished before step E can begin.",
|
||||
});
|
||||
string result = day07.ResolvePart1(new[] {
|
||||
"Step C must be finished before step A can begin.",
|
||||
"Step C must be finished before step F can begin.",
|
||||
"Step A must be finished before step B can begin.",
|
||||
"Step A must be finished before step D can begin.",
|
||||
"Step B must be finished before step E can begin.",
|
||||
"Step D must be finished before step E can begin.",
|
||||
"Step F must be finished before step E can begin.",
|
||||
});
|
||||
|
||||
Assert.Equal("CABDFE", result);
|
||||
}
|
||||
Assert.Equal("CABDFE", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day07 day07 = new Day07 { BaseCost = 0, NumberOfWorkers = 2 };
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day07 day07 = new() { BaseCost = 0, NumberOfWorkers = 2 };
|
||||
|
||||
string result = day07.ResolvePart2(new string[] {
|
||||
"Step C must be finished before step A can begin.",
|
||||
"Step C must be finished before step F can begin.",
|
||||
"Step A must be finished before step B can begin.",
|
||||
"Step A must be finished before step D can begin.",
|
||||
"Step B must be finished before step E can begin.",
|
||||
"Step D must be finished before step E can begin.",
|
||||
"Step F must be finished before step E can begin.",
|
||||
});
|
||||
string result = day07.ResolvePart2(new[] {
|
||||
"Step C must be finished before step A can begin.",
|
||||
"Step C must be finished before step F can begin.",
|
||||
"Step A must be finished before step B can begin.",
|
||||
"Step A must be finished before step D can begin.",
|
||||
"Step B must be finished before step E can begin.",
|
||||
"Step D must be finished before step E can begin.",
|
||||
"Step F must be finished before step E can begin.",
|
||||
});
|
||||
|
||||
Assert.Equal("15", result);
|
||||
}
|
||||
Assert.Equal("15", result);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,24 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day08_Tests
|
||||
{
|
||||
public class Day08_Tests
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
Day08 day = new Day08();
|
||||
Day08 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new string[] { "2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2", });
|
||||
string result = day.ResolvePart1(new[] { "2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2", });
|
||||
|
||||
Assert.Equal("138", result);
|
||||
}
|
||||
Assert.Equal("138", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day08 day = new Day08();
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day08 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new string[] { "2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2", });
|
||||
string result = day.ResolvePart2(new[] { "2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2", });
|
||||
|
||||
Assert.Equal("66", result);
|
||||
}
|
||||
Assert.Equal("66", result);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +1,64 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day09_Tests
|
||||
{
|
||||
public class Day09_Tests
|
||||
[Fact]
|
||||
public void ResolvePart1__Test1()
|
||||
{
|
||||
[Fact]
|
||||
public void ResolvePart1__Test1()
|
||||
{
|
||||
Day09 day = new Day09();
|
||||
Day09 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new string[] { "9 players; last marble is worth 25 points" });
|
||||
string result = day.ResolvePart1(new[] { "9 players; last marble is worth 25 points" });
|
||||
|
||||
Assert.Equal("32", result);
|
||||
}
|
||||
Assert.Equal("32", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test2()
|
||||
{
|
||||
Day09 day = new Day09();
|
||||
[Fact]
|
||||
public void ResolvePart1__Test2()
|
||||
{
|
||||
Day09 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new string[] { "10 players; last marble is worth 1618 points" });
|
||||
string result = day.ResolvePart1(new[] { "10 players; last marble is worth 1618 points" });
|
||||
|
||||
Assert.Equal("8317", result);
|
||||
}
|
||||
Assert.Equal("8317", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test3()
|
||||
{
|
||||
Day09 day = new Day09();
|
||||
[Fact]
|
||||
public void ResolvePart1__Test3()
|
||||
{
|
||||
Day09 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new string[] { "13 players; last marble is worth 7999 points" });
|
||||
string result = day.ResolvePart1(new[] { "13 players; last marble is worth 7999 points" });
|
||||
|
||||
Assert.Equal("146373", result);
|
||||
}
|
||||
Assert.Equal("146373", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test4()
|
||||
{
|
||||
Day09 day = new Day09();
|
||||
[Fact]
|
||||
public void ResolvePart1__Test4()
|
||||
{
|
||||
Day09 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new string[] { "17 players; last marble is worth 1104 points" });
|
||||
string result = day.ResolvePart1(new[] { "17 players; last marble is worth 1104 points" });
|
||||
|
||||
Assert.Equal("2764", result);
|
||||
}
|
||||
Assert.Equal("2764", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test5()
|
||||
{
|
||||
Day09 day = new Day09();
|
||||
[Fact]
|
||||
public void ResolvePart1__Test5()
|
||||
{
|
||||
Day09 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new string[] { "21 players; last marble is worth 6111 points" });
|
||||
string result = day.ResolvePart1(new[] { "21 players; last marble is worth 6111 points" });
|
||||
|
||||
Assert.Equal("54718", result);
|
||||
}
|
||||
Assert.Equal("54718", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test6()
|
||||
{
|
||||
Day09 day = new Day09();
|
||||
[Fact]
|
||||
public void ResolvePart1__Test6()
|
||||
{
|
||||
Day09 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new string[] { "30 players; last marble is worth 5807 points" });
|
||||
string result = day.ResolvePart1(new[] { "30 players; last marble is worth 5807 points" });
|
||||
|
||||
Assert.Equal("37305", result);
|
||||
}
|
||||
Assert.Equal("37305", result);
|
||||
}
|
||||
}
|
||||
@@ -1,102 +1,100 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
public class Day10_Tests
|
||||
{
|
||||
public class Day10_Tests
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
Day10 day = new Day10 { Width = 12, Height = 10 };
|
||||
Day10 day = new() { Width = 12, Height = 10 };
|
||||
|
||||
string result = day.ResolvePart1(new string[] {
|
||||
"position=< 9, 1> velocity=< 0, 2>",
|
||||
"position=< 7, 0> velocity=<-1, 0>",
|
||||
"position=< 3, -2> velocity=<-1, 1>",
|
||||
"position=< 6, 10> velocity=<-2, -1>",
|
||||
"position=< 2, -4> velocity=< 2, 2>",
|
||||
"position=<-6, 10> velocity=< 2, -2>",
|
||||
"position=< 1, 8> velocity=< 1, -1>",
|
||||
"position=< 1, 7> velocity=< 1, 0>",
|
||||
"position=<-3, 11> velocity=< 1, -2>",
|
||||
"position=< 7, 6> velocity=<-1, -1>",
|
||||
"position=<-2, 3> velocity=< 1, 0>",
|
||||
"position=<-4, 3> velocity=< 2, 0>",
|
||||
"position=<10, -3> velocity=<-1, 1>",
|
||||
"position=< 5, 11> velocity=< 1, -2>",
|
||||
"position=< 4, 7> velocity=< 0, -1>",
|
||||
"position=< 8, -2> velocity=< 0, 1>",
|
||||
"position=<15, 0> velocity=<-2, 0>",
|
||||
"position=< 1, 6> velocity=< 1, 0>",
|
||||
"position=< 8, 9> velocity=< 0, -1>",
|
||||
"position=< 3, 3> velocity=<-1, 1>",
|
||||
"position=< 0, 5> velocity=< 0, -1>",
|
||||
"position=<-2, 2> velocity=< 2, 0>",
|
||||
"position=< 5, -2> velocity=< 1, 2>",
|
||||
"position=< 1, 4> velocity=< 2, 1>",
|
||||
"position=<-2, 7> velocity=< 2, -2>",
|
||||
"position=< 3, 6> velocity=<-1, -1>",
|
||||
"position=< 5, 0> velocity=< 1, 0>",
|
||||
"position=<-6, 0> velocity=< 2, 0>",
|
||||
"position=< 5, 9> velocity=< 1, -2>",
|
||||
"position=<14, 7> velocity=<-2, 0>",
|
||||
"position=<-3, 6> velocity=< 2, -1>",
|
||||
});
|
||||
string result = day.ResolvePart1(new[] {
|
||||
"position=< 9, 1> velocity=< 0, 2>",
|
||||
"position=< 7, 0> velocity=<-1, 0>",
|
||||
"position=< 3, -2> velocity=<-1, 1>",
|
||||
"position=< 6, 10> velocity=<-2, -1>",
|
||||
"position=< 2, -4> velocity=< 2, 2>",
|
||||
"position=<-6, 10> velocity=< 2, -2>",
|
||||
"position=< 1, 8> velocity=< 1, -1>",
|
||||
"position=< 1, 7> velocity=< 1, 0>",
|
||||
"position=<-3, 11> velocity=< 1, -2>",
|
||||
"position=< 7, 6> velocity=<-1, -1>",
|
||||
"position=<-2, 3> velocity=< 1, 0>",
|
||||
"position=<-4, 3> velocity=< 2, 0>",
|
||||
"position=<10, -3> velocity=<-1, 1>",
|
||||
"position=< 5, 11> velocity=< 1, -2>",
|
||||
"position=< 4, 7> velocity=< 0, -1>",
|
||||
"position=< 8, -2> velocity=< 0, 1>",
|
||||
"position=<15, 0> velocity=<-2, 0>",
|
||||
"position=< 1, 6> velocity=< 1, 0>",
|
||||
"position=< 8, 9> velocity=< 0, -1>",
|
||||
"position=< 3, 3> velocity=<-1, 1>",
|
||||
"position=< 0, 5> velocity=< 0, -1>",
|
||||
"position=<-2, 2> velocity=< 2, 0>",
|
||||
"position=< 5, -2> velocity=< 1, 2>",
|
||||
"position=< 1, 4> velocity=< 2, 1>",
|
||||
"position=<-2, 7> velocity=< 2, -2>",
|
||||
"position=< 3, 6> velocity=<-1, -1>",
|
||||
"position=< 5, 0> velocity=< 1, 0>",
|
||||
"position=<-6, 0> velocity=< 2, 0>",
|
||||
"position=< 5, 9> velocity=< 1, -2>",
|
||||
"position=<14, 7> velocity=<-2, 0>",
|
||||
"position=<-3, 6> velocity=< 2, -1>",
|
||||
});
|
||||
|
||||
Assert.Equal(
|
||||
Environment.NewLine + "............" +
|
||||
Environment.NewLine + ".#...#..###." +
|
||||
Environment.NewLine + ".#...#...#.." +
|
||||
Environment.NewLine + ".#...#...#.." +
|
||||
Environment.NewLine + ".#####...#.." +
|
||||
Environment.NewLine + ".#...#...#.." +
|
||||
Environment.NewLine + ".#...#...#.." +
|
||||
Environment.NewLine + ".#...#...#.." +
|
||||
Environment.NewLine + ".#...#..###." +
|
||||
Environment.NewLine + "............", result);
|
||||
}
|
||||
Assert.Equal(
|
||||
Environment.NewLine + "............" +
|
||||
Environment.NewLine + ".#...#..###." +
|
||||
Environment.NewLine + ".#...#...#.." +
|
||||
Environment.NewLine + ".#...#...#.." +
|
||||
Environment.NewLine + ".#####...#.." +
|
||||
Environment.NewLine + ".#...#...#.." +
|
||||
Environment.NewLine + ".#...#...#.." +
|
||||
Environment.NewLine + ".#...#...#.." +
|
||||
Environment.NewLine + ".#...#..###." +
|
||||
Environment.NewLine + "............", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day10 day = new Day10();
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day10 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new string[] {
|
||||
"position=< 9, 1> velocity=< 0, 2>",
|
||||
"position=< 7, 0> velocity=<-1, 0>",
|
||||
"position=< 3, -2> velocity=<-1, 1>",
|
||||
"position=< 6, 10> velocity=<-2, -1>",
|
||||
"position=< 2, -4> velocity=< 2, 2>",
|
||||
"position=<-6, 10> velocity=< 2, -2>",
|
||||
"position=< 1, 8> velocity=< 1, -1>",
|
||||
"position=< 1, 7> velocity=< 1, 0>",
|
||||
"position=<-3, 11> velocity=< 1, -2>",
|
||||
"position=< 7, 6> velocity=<-1, -1>",
|
||||
"position=<-2, 3> velocity=< 1, 0>",
|
||||
"position=<-4, 3> velocity=< 2, 0>",
|
||||
"position=<10, -3> velocity=<-1, 1>",
|
||||
"position=< 5, 11> velocity=< 1, -2>",
|
||||
"position=< 4, 7> velocity=< 0, -1>",
|
||||
"position=< 8, -2> velocity=< 0, 1>",
|
||||
"position=<15, 0> velocity=<-2, 0>",
|
||||
"position=< 1, 6> velocity=< 1, 0>",
|
||||
"position=< 8, 9> velocity=< 0, -1>",
|
||||
"position=< 3, 3> velocity=<-1, 1>",
|
||||
"position=< 0, 5> velocity=< 0, -1>",
|
||||
"position=<-2, 2> velocity=< 2, 0>",
|
||||
"position=< 5, -2> velocity=< 1, 2>",
|
||||
"position=< 1, 4> velocity=< 2, 1>",
|
||||
"position=<-2, 7> velocity=< 2, -2>",
|
||||
"position=< 3, 6> velocity=<-1, -1>",
|
||||
"position=< 5, 0> velocity=< 1, 0>",
|
||||
"position=<-6, 0> velocity=< 2, 0>",
|
||||
"position=< 5, 9> velocity=< 1, -2>",
|
||||
"position=<14, 7> velocity=<-2, 0>",
|
||||
"position=<-3, 6> velocity=< 2, -1>",
|
||||
});
|
||||
string result = day.ResolvePart2(new[] {
|
||||
"position=< 9, 1> velocity=< 0, 2>",
|
||||
"position=< 7, 0> velocity=<-1, 0>",
|
||||
"position=< 3, -2> velocity=<-1, 1>",
|
||||
"position=< 6, 10> velocity=<-2, -1>",
|
||||
"position=< 2, -4> velocity=< 2, 2>",
|
||||
"position=<-6, 10> velocity=< 2, -2>",
|
||||
"position=< 1, 8> velocity=< 1, -1>",
|
||||
"position=< 1, 7> velocity=< 1, 0>",
|
||||
"position=<-3, 11> velocity=< 1, -2>",
|
||||
"position=< 7, 6> velocity=<-1, -1>",
|
||||
"position=<-2, 3> velocity=< 1, 0>",
|
||||
"position=<-4, 3> velocity=< 2, 0>",
|
||||
"position=<10, -3> velocity=<-1, 1>",
|
||||
"position=< 5, 11> velocity=< 1, -2>",
|
||||
"position=< 4, 7> velocity=< 0, -1>",
|
||||
"position=< 8, -2> velocity=< 0, 1>",
|
||||
"position=<15, 0> velocity=<-2, 0>",
|
||||
"position=< 1, 6> velocity=< 1, 0>",
|
||||
"position=< 8, 9> velocity=< 0, -1>",
|
||||
"position=< 3, 3> velocity=<-1, 1>",
|
||||
"position=< 0, 5> velocity=< 0, -1>",
|
||||
"position=<-2, 2> velocity=< 2, 0>",
|
||||
"position=< 5, -2> velocity=< 1, 2>",
|
||||
"position=< 1, 4> velocity=< 2, 1>",
|
||||
"position=<-2, 7> velocity=< 2, -2>",
|
||||
"position=< 3, 6> velocity=<-1, -1>",
|
||||
"position=< 5, 0> velocity=< 1, 0>",
|
||||
"position=<-6, 0> velocity=< 2, 0>",
|
||||
"position=< 5, 9> velocity=< 1, -2>",
|
||||
"position=<14, 7> velocity=<-2, 0>",
|
||||
"position=<-3, 6> velocity=< 2, -1>",
|
||||
});
|
||||
|
||||
Assert.Equal("3", result);
|
||||
}
|
||||
Assert.Equal("3", result);
|
||||
}
|
||||
}
|
||||
@@ -1,76 +1,73 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day11_Tests
|
||||
{
|
||||
public class Day11_Tests
|
||||
[Fact]
|
||||
public void CalculatePowerLevelOfCell__Test1()
|
||||
{
|
||||
[Fact]
|
||||
public void CalculatePowerLevelOfCell__Test1()
|
||||
{
|
||||
int powerLevel = Day11.CalculatePowerLevelOfCell(3, 5, 8);
|
||||
Assert.Equal(4, powerLevel);
|
||||
}
|
||||
int powerLevel = Day11.CalculatePowerLevelOfCell(3, 5, 8);
|
||||
Assert.Equal(4, powerLevel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CalculatePowerLevelOfRegion__Test1()
|
||||
{
|
||||
int powerLevel = Day11.CalculatePowerLevelOfRegion(33, 45, 3, 18);
|
||||
Assert.Equal(29, powerLevel);
|
||||
}
|
||||
[Fact]
|
||||
public void CalculatePowerLevelOfRegion__Test1()
|
||||
{
|
||||
int powerLevel = Day11.CalculatePowerLevelOfRegion(33, 45, 3, 18);
|
||||
Assert.Equal(29, powerLevel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CalculatePowerLevelOfRegion__Test2()
|
||||
{
|
||||
int powerLevel = Day11.CalculatePowerLevelOfRegion(21, 61, 3, 42);
|
||||
Assert.Equal(30, powerLevel);
|
||||
}
|
||||
[Fact]
|
||||
public void CalculatePowerLevelOfRegion__Test2()
|
||||
{
|
||||
int powerLevel = Day11.CalculatePowerLevelOfRegion(21, 61, 3, 42);
|
||||
Assert.Equal(30, powerLevel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CalculatePowerLevelOfRegion__Test1_WithSumationField()
|
||||
{
|
||||
int[,] summationFiled = Day11.GenerateSumationField(300, 300, 18);
|
||||
int powerLevel = Day11.CalculatePowerLevelOfRegion(33, 45, 3, summationFiled);
|
||||
Assert.Equal(29, powerLevel);
|
||||
}
|
||||
[Fact]
|
||||
public void CalculatePowerLevelOfRegion__Test1_WithSumationField()
|
||||
{
|
||||
int[,] summationFiled = Day11.GenerateSumationField(300, 300, 18);
|
||||
int powerLevel = Day11.CalculatePowerLevelOfRegion(33, 45, 3, summationFiled);
|
||||
Assert.Equal(29, powerLevel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CalculatePowerLevelOfRegion__Test2_WithSumationField()
|
||||
{
|
||||
int[,] summationFiled = Day11.GenerateSumationField(300, 300, 42);
|
||||
int powerLevel = Day11.CalculatePowerLevelOfRegion(21, 61, 3, summationFiled);
|
||||
Assert.Equal(30, powerLevel);
|
||||
}
|
||||
[Fact]
|
||||
public void CalculatePowerLevelOfRegion__Test2_WithSumationField()
|
||||
{
|
||||
int[,] summationFiled = Day11.GenerateSumationField(300, 300, 42);
|
||||
int powerLevel = Day11.CalculatePowerLevelOfRegion(21, 61, 3, summationFiled);
|
||||
Assert.Equal(30, powerLevel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SearchBestRegionOfOneSize__Test1()
|
||||
{
|
||||
Day11.SearchBestRegionOfOneSize(300, 300, 3, 18, out int x, out int y);
|
||||
Assert.Equal(33, x);
|
||||
Assert.Equal(45, y);
|
||||
}
|
||||
[Fact]
|
||||
public void SearchBestRegionOfOneSize__Test1()
|
||||
{
|
||||
Day11.SearchBestRegionOfOneSize(300, 300, 3, 18, out int x, out int y);
|
||||
Assert.Equal(33, x);
|
||||
Assert.Equal(45, y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SearchBestRegionOfOneSize__Test2()
|
||||
{
|
||||
Day11.SearchBestRegionOfOneSize(300, 300, 3, 42, out int x, out int y);
|
||||
Assert.Equal(21, x);
|
||||
Assert.Equal(61, y);
|
||||
}
|
||||
[Fact]
|
||||
public void SearchBestRegionOfOneSize__Test2()
|
||||
{
|
||||
Day11.SearchBestRegionOfOneSize(300, 300, 3, 42, out int x, out int y);
|
||||
Assert.Equal(21, x);
|
||||
Assert.Equal(61, y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test1()
|
||||
{
|
||||
Day11 day = new Day11();
|
||||
string result = day.ResolvePart2(new string[] { "18" });
|
||||
Assert.Equal("90,269,16", result);
|
||||
}
|
||||
[Fact]
|
||||
public void ResolvePart2__Test1()
|
||||
{
|
||||
Day11 day = new();
|
||||
string result = day.ResolvePart2(new[] { "18" });
|
||||
Assert.Equal("90,269,16", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test2()
|
||||
{
|
||||
Day11 day = new Day11();
|
||||
string result = day.ResolvePart2(new string[] { "42" });
|
||||
Assert.Equal("232,251,12", result);
|
||||
}
|
||||
[Fact]
|
||||
public void ResolvePart2__Test2()
|
||||
{
|
||||
Day11 day = new();
|
||||
string result = day.ResolvePart2(new[] { "42" });
|
||||
Assert.Equal("232,251,12", result);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,32 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day12_Tests
|
||||
{
|
||||
public class Day12_Tests
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
Day12 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new[]
|
||||
{
|
||||
Day12 day = new Day12();
|
||||
"initial state: #..#.#..##......###...###",
|
||||
"",
|
||||
"...## => #",
|
||||
"..#.. => #",
|
||||
".#... => #",
|
||||
".#.#. => #",
|
||||
".#.## => #",
|
||||
".##.. => #",
|
||||
".#### => #",
|
||||
"#.#.# => #",
|
||||
"#.### => #",
|
||||
"##.#. => #",
|
||||
"##.## => #",
|
||||
"###.. => #",
|
||||
"###.# => #",
|
||||
"####. => #",
|
||||
});
|
||||
|
||||
string result = day.ResolvePart1(new string[]
|
||||
{
|
||||
"initial state: #..#.#..##......###...###",
|
||||
"",
|
||||
"...## => #",
|
||||
"..#.. => #",
|
||||
".#... => #",
|
||||
".#.#. => #",
|
||||
".#.## => #",
|
||||
".##.. => #",
|
||||
".#### => #",
|
||||
"#.#.# => #",
|
||||
"#.### => #",
|
||||
"##.#. => #",
|
||||
"##.## => #",
|
||||
"###.. => #",
|
||||
"###.# => #",
|
||||
"####. => #",
|
||||
});
|
||||
|
||||
Assert.Equal("325", result);
|
||||
}
|
||||
Assert.Equal("325", result);
|
||||
}
|
||||
}
|
||||
@@ -1,60 +1,57 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day13_Tests
|
||||
{
|
||||
public class Day13_Tests
|
||||
[Fact]
|
||||
public void ResolvePart1__Test1()
|
||||
{
|
||||
[Fact]
|
||||
public void ResolvePart1__Test1()
|
||||
{
|
||||
Day13 day = new Day13();
|
||||
Day13 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new string[] {
|
||||
"|",
|
||||
"v",
|
||||
"|",
|
||||
"|",
|
||||
"|",
|
||||
"^",
|
||||
"|",
|
||||
});
|
||||
string result = day.ResolvePart1(new[] {
|
||||
"|",
|
||||
"v",
|
||||
"|",
|
||||
"|",
|
||||
"|",
|
||||
"^",
|
||||
"|",
|
||||
});
|
||||
|
||||
Assert.Equal("0,3", result);
|
||||
}
|
||||
Assert.Equal("0,3", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test2()
|
||||
{
|
||||
Day13 day = new Day13();
|
||||
[Fact]
|
||||
public void ResolvePart1__Test2()
|
||||
{
|
||||
Day13 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new string[] {
|
||||
@"/->-\ ",
|
||||
@"| | /----\",
|
||||
@"| /-+--+-\ |",
|
||||
@"| | | | v |",
|
||||
@"\-+-/ \-+--/",
|
||||
@" \------/ ",
|
||||
});
|
||||
string result = day.ResolvePart1(new[] {
|
||||
@"/->-\ ",
|
||||
@"| | /----\",
|
||||
@"| /-+--+-\ |",
|
||||
@"| | | | v |",
|
||||
@"\-+-/ \-+--/",
|
||||
@" \------/ ",
|
||||
});
|
||||
|
||||
Assert.Equal("7,3", result);
|
||||
}
|
||||
Assert.Equal("7,3", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day13 day = new Day13();
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day13 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new string[] {
|
||||
@"/>-<\ ",
|
||||
@"| | ",
|
||||
@"| /<+-\",
|
||||
@"| | | v",
|
||||
@"\>+</ |",
|
||||
@" | ^",
|
||||
@" \<->/",
|
||||
});
|
||||
string result = day.ResolvePart2(new[] {
|
||||
@"/>-<\ ",
|
||||
@"| | ",
|
||||
@"| /<+-\",
|
||||
@"| | | v",
|
||||
@"\>+</ |",
|
||||
@" | ^",
|
||||
@" \<->/",
|
||||
});
|
||||
|
||||
Assert.Equal("6,4", result);
|
||||
}
|
||||
Assert.Equal("6,4", result);
|
||||
}
|
||||
}
|
||||
@@ -1,95 +1,92 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day14_Tests
|
||||
{
|
||||
public class Day14_Tests
|
||||
#region ResolvePart1
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test1()
|
||||
{
|
||||
#region ResolvePart1
|
||||
Day14 day = new();
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test1()
|
||||
{
|
||||
Day14 day = new Day14();
|
||||
string result = day.ResolvePart1(new[] { "9", });
|
||||
|
||||
string result = day.ResolvePart1(new string[] { "9", });
|
||||
|
||||
Assert.Equal("5158916779", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test2()
|
||||
{
|
||||
Day14 day = new Day14();
|
||||
|
||||
string result = day.ResolvePart1(new string[] { "5", });
|
||||
|
||||
Assert.Equal("0124515891", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test3()
|
||||
{
|
||||
Day14 day = new Day14();
|
||||
|
||||
string result = day.ResolvePart1(new string[] { "18", });
|
||||
|
||||
Assert.Equal("9251071085", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test4()
|
||||
{
|
||||
Day14 day = new Day14();
|
||||
|
||||
string result = day.ResolvePart1(new string[] { "2018", });
|
||||
|
||||
Assert.Equal("5941429882", result);
|
||||
}
|
||||
|
||||
#endregion ResolvePart1
|
||||
|
||||
#region ResolvePart2
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test1()
|
||||
{
|
||||
Day14 day = new Day14();
|
||||
|
||||
string result = day.ResolvePart2(new string[] { "51589", });
|
||||
|
||||
Assert.Equal("9", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test2()
|
||||
{
|
||||
Day14 day = new Day14();
|
||||
|
||||
string result = day.ResolvePart2(new string[] { "01245", });
|
||||
|
||||
Assert.Equal("5", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test3()
|
||||
{
|
||||
Day14 day = new Day14();
|
||||
|
||||
string result = day.ResolvePart2(new string[] { "92510", });
|
||||
|
||||
Assert.Equal("18", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test4()
|
||||
{
|
||||
Day14 day = new Day14();
|
||||
|
||||
string result = day.ResolvePart2(new string[] { "59414", });
|
||||
|
||||
Assert.Equal("2018", result);
|
||||
}
|
||||
|
||||
#endregion ResolvePart2
|
||||
Assert.Equal("5158916779", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test2()
|
||||
{
|
||||
Day14 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new[] { "5", });
|
||||
|
||||
Assert.Equal("0124515891", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test3()
|
||||
{
|
||||
Day14 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new[] { "18", });
|
||||
|
||||
Assert.Equal("9251071085", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test4()
|
||||
{
|
||||
Day14 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new[] { "2018", });
|
||||
|
||||
Assert.Equal("5941429882", result);
|
||||
}
|
||||
|
||||
#endregion ResolvePart1
|
||||
|
||||
#region ResolvePart2
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test1()
|
||||
{
|
||||
Day14 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new[] { "51589", });
|
||||
|
||||
Assert.Equal("9", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test2()
|
||||
{
|
||||
Day14 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new[] { "01245", });
|
||||
|
||||
Assert.Equal("5", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test3()
|
||||
{
|
||||
Day14 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new[] { "92510", });
|
||||
|
||||
Assert.Equal("18", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test4()
|
||||
{
|
||||
Day14 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new[] { "59414", });
|
||||
|
||||
Assert.Equal("2018", result);
|
||||
}
|
||||
|
||||
#endregion ResolvePart2
|
||||
}
|
||||
@@ -1,223 +1,214 @@
|
||||
using Xunit;
|
||||
using AdventOfCode2018;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day15_Tests
|
||||
{
|
||||
public class Day15_Tests
|
||||
#region ResolvePart1
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test1()
|
||||
{
|
||||
#region ResolvePart1
|
||||
Day15 day = new();
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test1()
|
||||
{
|
||||
Day15 day = new Day15();
|
||||
string result = day.ResolvePart1(new[] {
|
||||
"#######",
|
||||
"#.G...#",
|
||||
"#...EG#",
|
||||
"#.#.#G#",
|
||||
"#..G#E#",
|
||||
"#.....#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
string result = day.ResolvePart1(new string[] {
|
||||
"#######",
|
||||
"#.G...#",
|
||||
"#...EG#",
|
||||
"#.#.#G#",
|
||||
"#..G#E#",
|
||||
"#.....#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("27730", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test2()
|
||||
{
|
||||
Day15 day = new Day15();
|
||||
|
||||
string result = day.ResolvePart1(new string[] {
|
||||
"#######",
|
||||
"#G..#E#",
|
||||
"#E#E.E#",
|
||||
"#G.##.#",
|
||||
"#...#E#",
|
||||
"#...E.#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("36334", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test3()
|
||||
{
|
||||
Day15 day = new Day15();
|
||||
|
||||
string result = day.ResolvePart1(new string[] {
|
||||
"#######",
|
||||
"#E..EG#",
|
||||
"#.#G.E#",
|
||||
"#E.##E#",
|
||||
"#G..#.#",
|
||||
"#..E#.#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("39514", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test4()
|
||||
{
|
||||
Day15 day = new Day15();
|
||||
|
||||
string result = day.ResolvePart1(new string[] {
|
||||
"#######",
|
||||
"#E.G#.#",
|
||||
"#.#G..#",
|
||||
"#G.#.G#",
|
||||
"#G..#.#",
|
||||
"#...E.#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("27755", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test5()
|
||||
{
|
||||
Day15 day = new Day15();
|
||||
|
||||
string result = day.ResolvePart1(new string[] {
|
||||
"#######",
|
||||
"#.E...#",
|
||||
"#.#..G#",
|
||||
"#.###.#",
|
||||
"#E#G#G#",
|
||||
"#...#G#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("28944", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test6()
|
||||
{
|
||||
Day15 day = new Day15();
|
||||
|
||||
string result = day.ResolvePart1(new string[] {
|
||||
"#########",
|
||||
"#G......#",
|
||||
"#.E.#...#",
|
||||
"#..##..G#",
|
||||
"#...##..#",
|
||||
"#...#...#",
|
||||
"#.G...G.#",
|
||||
"#.....G.#",
|
||||
"#########",
|
||||
});
|
||||
|
||||
Assert.Equal("18740", result);
|
||||
}
|
||||
|
||||
#endregion ResolvePart1
|
||||
|
||||
#region ResolvePart2
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test1()
|
||||
{
|
||||
Day15 day = new Day15();
|
||||
|
||||
string result = day.ResolvePart2(new string[] {
|
||||
"#######",
|
||||
"#.G...#",
|
||||
"#...EG#",
|
||||
"#.#.#G#",
|
||||
"#..G#E#",
|
||||
"#.....#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("4988", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test3()
|
||||
{
|
||||
Day15 day = new Day15();
|
||||
|
||||
string result = day.ResolvePart2(new string[] {
|
||||
"#######",
|
||||
"#E..EG#",
|
||||
"#.#G.E#",
|
||||
"#E.##E#",
|
||||
"#G..#.#",
|
||||
"#..E#.#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("31284", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test4()
|
||||
{
|
||||
Day15 day = new Day15();
|
||||
|
||||
string result = day.ResolvePart2(new string[] {
|
||||
"#######",
|
||||
"#E.G#.#",
|
||||
"#.#G..#",
|
||||
"#G.#.G#",
|
||||
"#G..#.#",
|
||||
"#...E.#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("3478", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test5()
|
||||
{
|
||||
Day15 day = new Day15();
|
||||
|
||||
string result = day.ResolvePart2(new string[] {
|
||||
"#######",
|
||||
"#.E...#",
|
||||
"#.#..G#",
|
||||
"#.###.#",
|
||||
"#E#G#G#",
|
||||
"#...#G#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("6474", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test6()
|
||||
{
|
||||
Day15 day = new Day15();
|
||||
|
||||
string result = day.ResolvePart2(new string[] {
|
||||
"#########",
|
||||
"#G......#",
|
||||
"#.E.#...#",
|
||||
"#..##..G#",
|
||||
"#...##..#",
|
||||
"#...#...#",
|
||||
"#.G...G.#",
|
||||
"#.....G.#",
|
||||
"#########",
|
||||
});
|
||||
|
||||
Assert.Equal("1140", result);
|
||||
}
|
||||
|
||||
#endregion ResolvePart2
|
||||
Assert.Equal("27730", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test2()
|
||||
{
|
||||
Day15 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new[] {
|
||||
"#######",
|
||||
"#G..#E#",
|
||||
"#E#E.E#",
|
||||
"#G.##.#",
|
||||
"#...#E#",
|
||||
"#...E.#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("36334", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test3()
|
||||
{
|
||||
Day15 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new[] {
|
||||
"#######",
|
||||
"#E..EG#",
|
||||
"#.#G.E#",
|
||||
"#E.##E#",
|
||||
"#G..#.#",
|
||||
"#..E#.#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("39514", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test4()
|
||||
{
|
||||
Day15 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new[] {
|
||||
"#######",
|
||||
"#E.G#.#",
|
||||
"#.#G..#",
|
||||
"#G.#.G#",
|
||||
"#G..#.#",
|
||||
"#...E.#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("27755", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test5()
|
||||
{
|
||||
Day15 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new[] {
|
||||
"#######",
|
||||
"#.E...#",
|
||||
"#.#..G#",
|
||||
"#.###.#",
|
||||
"#E#G#G#",
|
||||
"#...#G#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("28944", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart1__Test6()
|
||||
{
|
||||
Day15 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new[] {
|
||||
"#########",
|
||||
"#G......#",
|
||||
"#.E.#...#",
|
||||
"#..##..G#",
|
||||
"#...##..#",
|
||||
"#...#...#",
|
||||
"#.G...G.#",
|
||||
"#.....G.#",
|
||||
"#########",
|
||||
});
|
||||
|
||||
Assert.Equal("18740", result);
|
||||
}
|
||||
|
||||
#endregion ResolvePart1
|
||||
|
||||
#region ResolvePart2
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test1()
|
||||
{
|
||||
Day15 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new[] {
|
||||
"#######",
|
||||
"#.G...#",
|
||||
"#...EG#",
|
||||
"#.#.#G#",
|
||||
"#..G#E#",
|
||||
"#.....#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("4988", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test3()
|
||||
{
|
||||
Day15 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new[] {
|
||||
"#######",
|
||||
"#E..EG#",
|
||||
"#.#G.E#",
|
||||
"#E.##E#",
|
||||
"#G..#.#",
|
||||
"#..E#.#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("31284", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test4()
|
||||
{
|
||||
Day15 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new[] {
|
||||
"#######",
|
||||
"#E.G#.#",
|
||||
"#.#G..#",
|
||||
"#G.#.G#",
|
||||
"#G..#.#",
|
||||
"#...E.#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("3478", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test5()
|
||||
{
|
||||
Day15 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new[] {
|
||||
"#######",
|
||||
"#.E...#",
|
||||
"#.#..G#",
|
||||
"#.###.#",
|
||||
"#E#G#G#",
|
||||
"#...#G#",
|
||||
"#######",
|
||||
});
|
||||
|
||||
Assert.Equal("6474", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test6()
|
||||
{
|
||||
Day15 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new[] {
|
||||
"#########",
|
||||
"#G......#",
|
||||
"#.E.#...#",
|
||||
"#..##..G#",
|
||||
"#...##..#",
|
||||
"#...#...#",
|
||||
"#.G...G.#",
|
||||
"#.....G.#",
|
||||
"#########",
|
||||
});
|
||||
|
||||
Assert.Equal("1140", result);
|
||||
}
|
||||
|
||||
#endregion ResolvePart2
|
||||
}
|
||||
@@ -1,45 +1,41 @@
|
||||
using AdventOfCode2018;
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class Day23_Tests
|
||||
{
|
||||
public class Day23_Tests
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
[Fact]
|
||||
public void ResolvePart1__Test()
|
||||
{
|
||||
Day23 day = new Day23();
|
||||
Day23 day = new();
|
||||
|
||||
string result = day.ResolvePart1(new string[] {
|
||||
"pos=<0,0,0>, r=4",
|
||||
"pos=<1,0,0>, r=1",
|
||||
"pos=<4,0,0>, r=3",
|
||||
"pos=<0,2,0>, r=1",
|
||||
"pos=<0,5,0>, r=3",
|
||||
"pos=<0,0,3>, r=1",
|
||||
"pos=<1,1,1>, r=1",
|
||||
"pos=<1,1,2>, r=1",
|
||||
"pos=<1,3,1>, r=1",
|
||||
});
|
||||
string result = day.ResolvePart1(new[] {
|
||||
"pos=<0,0,0>, r=4",
|
||||
"pos=<1,0,0>, r=1",
|
||||
"pos=<4,0,0>, r=3",
|
||||
"pos=<0,2,0>, r=1",
|
||||
"pos=<0,5,0>, r=3",
|
||||
"pos=<0,0,3>, r=1",
|
||||
"pos=<1,1,1>, r=1",
|
||||
"pos=<1,1,2>, r=1",
|
||||
"pos=<1,3,1>, r=1",
|
||||
});
|
||||
|
||||
Assert.Equal("7", result);
|
||||
}
|
||||
Assert.Equal("7", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day23 day = new Day23();
|
||||
[Fact]
|
||||
public void ResolvePart2__Test()
|
||||
{
|
||||
Day23 day = new();
|
||||
|
||||
string result = day.ResolvePart2(new string[] {
|
||||
"pos=<10,12,12>, r=2",
|
||||
"pos=<12,14,12>, r=2",
|
||||
"pos=<16,12,12>, r=4",
|
||||
"pos=<14,14,14>, r=6",
|
||||
"pos=<50,50,50>, r=200",
|
||||
"pos=<10,10,10>, r=5",
|
||||
});
|
||||
string result = day.ResolvePart2(new[] {
|
||||
"pos=<10,12,12>, r=2",
|
||||
"pos=<12,14,12>, r=2",
|
||||
"pos=<16,12,12>, r=4",
|
||||
"pos=<14,14,14>, r=6",
|
||||
"pos=<50,50,50>, r=200",
|
||||
"pos=<10,10,10>, r=5",
|
||||
});
|
||||
|
||||
Assert.Equal("36", result);
|
||||
}
|
||||
Assert.Equal("36", result);
|
||||
}
|
||||
}
|
||||
@@ -1,133 +1,131 @@
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
public class GuardEvent_Tests
|
||||
{
|
||||
public class GuardEvent_Tests
|
||||
#region FromString
|
||||
|
||||
[Fact]
|
||||
public void FromString__ShiftBegin()
|
||||
{
|
||||
#region FromString
|
||||
GuardEvent guardEvent = GuardEvent.FromString("[1518-11-01 00:00] Guard #10 begins shift");
|
||||
|
||||
[Fact]
|
||||
public void FromString__ShiftBegin()
|
||||
{
|
||||
GuardEvent guardEvent = GuardEvent.FromString("[1518-11-01 00:00] Guard #10 begins shift");
|
||||
|
||||
Assert.Equal(10, guardEvent.ID);
|
||||
Assert.Equal(11, guardEvent.Date.Month);
|
||||
Assert.Equal(1, guardEvent.Date.Day);
|
||||
Assert.Equal(0, guardEvent.Date.Hour);
|
||||
Assert.Equal(0, guardEvent.Date.Minute);
|
||||
Assert.Equal(GuardEventType.ShiftBegin, guardEvent.Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__FallSleep()
|
||||
{
|
||||
GuardEvent guardEvent = GuardEvent.FromString("[1518-11-02 00:40] falls asleep");
|
||||
|
||||
Assert.Equal(null, guardEvent.ID);
|
||||
Assert.Equal(11, guardEvent.Date.Month);
|
||||
Assert.Equal(2, guardEvent.Date.Day);
|
||||
Assert.Equal(0, guardEvent.Date.Hour);
|
||||
Assert.Equal(40, guardEvent.Date.Minute);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvent.Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__WakeUp()
|
||||
{
|
||||
GuardEvent guardEvent = GuardEvent.FromString("[1518-11-03 00:29] wakes up");
|
||||
|
||||
Assert.Equal(null, guardEvent.ID);
|
||||
Assert.Equal(11, guardEvent.Date.Month);
|
||||
Assert.Equal(3, guardEvent.Date.Day);
|
||||
Assert.Equal(0, guardEvent.Date.Hour);
|
||||
Assert.Equal(29, guardEvent.Date.Minute);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvent.Type);
|
||||
}
|
||||
|
||||
#endregion FromString
|
||||
|
||||
#region FromStringArray
|
||||
|
||||
[Fact]
|
||||
public void FromStringArray__TestBase()
|
||||
{
|
||||
List<GuardEvent> guardEvents = GuardEvent.FromStringArray(new string[] {
|
||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||
"[1518-11-01 00:05] falls asleep",
|
||||
"[1518-11-01 00:25] wakes up",
|
||||
"[1518-11-01 00:30] falls asleep",
|
||||
"[1518-11-01 00:55] wakes up",
|
||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||
"[1518-11-02 00:40] falls asleep",
|
||||
"[1518-11-02 00:50] wakes up",
|
||||
});
|
||||
|
||||
Assert.Equal(10, guardEvents[0].ID);
|
||||
Assert.Equal(GuardEventType.ShiftBegin, guardEvents[0].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[1].ID);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvents[1].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[2].ID);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvents[2].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[3].ID);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvents[3].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[4].ID);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvents[4].Type);
|
||||
|
||||
Assert.Equal(99, guardEvents[5].ID);
|
||||
Assert.Equal(GuardEventType.ShiftBegin, guardEvents[5].Type);
|
||||
|
||||
Assert.Equal(99, guardEvents[6].ID);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvents[6].Type);
|
||||
|
||||
Assert.Equal(99, guardEvents[7].ID);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvents[7].Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromStringArray__TestBaseUnsorted()
|
||||
{
|
||||
List<GuardEvent> guardEvents = GuardEvent.FromStringArray(new string[] {
|
||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||
"[1518-11-01 00:30] falls asleep",
|
||||
"[1518-11-02 00:40] falls asleep",
|
||||
"[1518-11-01 00:05] falls asleep",
|
||||
"[1518-11-02 00:50] wakes up",
|
||||
"[1518-11-01 00:55] wakes up",
|
||||
"[1518-11-01 00:25] wakes up",
|
||||
});
|
||||
|
||||
Assert.Equal(10, guardEvents[0].ID);
|
||||
Assert.Equal(GuardEventType.ShiftBegin, guardEvents[0].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[1].ID);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvents[1].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[2].ID);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvents[2].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[3].ID);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvents[3].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[4].ID);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvents[4].Type);
|
||||
|
||||
Assert.Equal(99, guardEvents[5].ID);
|
||||
Assert.Equal(GuardEventType.ShiftBegin, guardEvents[5].Type);
|
||||
|
||||
Assert.Equal(99, guardEvents[6].ID);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvents[6].Type);
|
||||
|
||||
Assert.Equal(99, guardEvents[7].ID);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvents[7].Type);
|
||||
}
|
||||
|
||||
#endregion FromStringArray
|
||||
Assert.Equal(10, guardEvent.ID);
|
||||
Assert.Equal(11, guardEvent.Date.Month);
|
||||
Assert.Equal(1, guardEvent.Date.Day);
|
||||
Assert.Equal(0, guardEvent.Date.Hour);
|
||||
Assert.Equal(0, guardEvent.Date.Minute);
|
||||
Assert.Equal(GuardEventType.ShiftBegin, guardEvent.Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__FallSleep()
|
||||
{
|
||||
GuardEvent guardEvent = GuardEvent.FromString("[1518-11-02 00:40] falls asleep");
|
||||
|
||||
Assert.Null(guardEvent.ID);
|
||||
Assert.Equal(11, guardEvent.Date.Month);
|
||||
Assert.Equal(2, guardEvent.Date.Day);
|
||||
Assert.Equal(0, guardEvent.Date.Hour);
|
||||
Assert.Equal(40, guardEvent.Date.Minute);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvent.Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromString__WakeUp()
|
||||
{
|
||||
GuardEvent guardEvent = GuardEvent.FromString("[1518-11-03 00:29] wakes up");
|
||||
|
||||
Assert.Null(guardEvent.ID);
|
||||
Assert.Equal(11, guardEvent.Date.Month);
|
||||
Assert.Equal(3, guardEvent.Date.Day);
|
||||
Assert.Equal(0, guardEvent.Date.Hour);
|
||||
Assert.Equal(29, guardEvent.Date.Minute);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvent.Type);
|
||||
}
|
||||
|
||||
#endregion FromString
|
||||
|
||||
#region FromStringArray
|
||||
|
||||
[Fact]
|
||||
public void FromStringArray__TestBase()
|
||||
{
|
||||
List<GuardEvent> guardEvents = GuardEvent.FromStringArray(new[] {
|
||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||
"[1518-11-01 00:05] falls asleep",
|
||||
"[1518-11-01 00:25] wakes up",
|
||||
"[1518-11-01 00:30] falls asleep",
|
||||
"[1518-11-01 00:55] wakes up",
|
||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||
"[1518-11-02 00:40] falls asleep",
|
||||
"[1518-11-02 00:50] wakes up",
|
||||
});
|
||||
|
||||
Assert.Equal(10, guardEvents[0].ID);
|
||||
Assert.Equal(GuardEventType.ShiftBegin, guardEvents[0].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[1].ID);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvents[1].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[2].ID);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvents[2].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[3].ID);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvents[3].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[4].ID);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvents[4].Type);
|
||||
|
||||
Assert.Equal(99, guardEvents[5].ID);
|
||||
Assert.Equal(GuardEventType.ShiftBegin, guardEvents[5].Type);
|
||||
|
||||
Assert.Equal(99, guardEvents[6].ID);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvents[6].Type);
|
||||
|
||||
Assert.Equal(99, guardEvents[7].ID);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvents[7].Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromStringArray__TestBaseUnsorted()
|
||||
{
|
||||
List<GuardEvent> guardEvents = GuardEvent.FromStringArray(new[] {
|
||||
"[1518-11-01 00:00] Guard #10 begins shift",
|
||||
"[1518-11-01 23:58] Guard #99 begins shift",
|
||||
"[1518-11-01 00:30] falls asleep",
|
||||
"[1518-11-02 00:40] falls asleep",
|
||||
"[1518-11-01 00:05] falls asleep",
|
||||
"[1518-11-02 00:50] wakes up",
|
||||
"[1518-11-01 00:55] wakes up",
|
||||
"[1518-11-01 00:25] wakes up",
|
||||
});
|
||||
|
||||
Assert.Equal(10, guardEvents[0].ID);
|
||||
Assert.Equal(GuardEventType.ShiftBegin, guardEvents[0].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[1].ID);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvents[1].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[2].ID);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvents[2].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[3].ID);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvents[3].Type);
|
||||
|
||||
Assert.Equal(10, guardEvents[4].ID);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvents[4].Type);
|
||||
|
||||
Assert.Equal(99, guardEvents[5].ID);
|
||||
Assert.Equal(GuardEventType.ShiftBegin, guardEvents[5].Type);
|
||||
|
||||
Assert.Equal(99, guardEvents[6].ID);
|
||||
Assert.Equal(GuardEventType.FallSleep, guardEvents[6].Type);
|
||||
|
||||
Assert.Equal(99, guardEvents[7].ID);
|
||||
Assert.Equal(GuardEventType.WakeUp, guardEvents[7].Type);
|
||||
}
|
||||
|
||||
#endregion FromStringArray
|
||||
}
|
||||
@@ -1,73 +1,70 @@
|
||||
using Xunit;
|
||||
namespace AdventOfCode2018.Tests;
|
||||
|
||||
namespace AdventOfCode2018.Tests
|
||||
public class MarbleGame_Tests
|
||||
{
|
||||
public class MarbleGame_Tests
|
||||
[Fact]
|
||||
public void PlayGame__Test1()
|
||||
{
|
||||
[Fact]
|
||||
public void PlayGame__Test1()
|
||||
{
|
||||
MarbleGame marbleGame = new MarbleGame();
|
||||
MarbleGame marbleGame = new();
|
||||
|
||||
marbleGame.PlayGame(9, 25);
|
||||
long highScore = marbleGame.GetHighScore();
|
||||
marbleGame.PlayGame(9, 25);
|
||||
long highScore = marbleGame.GetHighScore();
|
||||
|
||||
Assert.Equal(32, highScore);
|
||||
}
|
||||
Assert.Equal(32, highScore);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PlayGame__Test2()
|
||||
{
|
||||
MarbleGame marbleGame = new MarbleGame();
|
||||
[Fact]
|
||||
public void PlayGame__Test2()
|
||||
{
|
||||
MarbleGame marbleGame = new();
|
||||
|
||||
marbleGame.PlayGame(10, 1618);
|
||||
long highScore = marbleGame.GetHighScore();
|
||||
marbleGame.PlayGame(10, 1618);
|
||||
long highScore = marbleGame.GetHighScore();
|
||||
|
||||
Assert.Equal(8317, highScore);
|
||||
}
|
||||
Assert.Equal(8317, highScore);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PlayGame__Test3()
|
||||
{
|
||||
MarbleGame marbleGame = new MarbleGame();
|
||||
[Fact]
|
||||
public void PlayGame__Test3()
|
||||
{
|
||||
MarbleGame marbleGame = new();
|
||||
|
||||
marbleGame.PlayGame(13, 7999);
|
||||
long highScore = marbleGame.GetHighScore();
|
||||
marbleGame.PlayGame(13, 7999);
|
||||
long highScore = marbleGame.GetHighScore();
|
||||
|
||||
Assert.Equal(146373, highScore);
|
||||
}
|
||||
Assert.Equal(146373, highScore);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PlayGame__Test4()
|
||||
{
|
||||
MarbleGame marbleGame = new MarbleGame();
|
||||
[Fact]
|
||||
public void PlayGame__Test4()
|
||||
{
|
||||
MarbleGame marbleGame = new();
|
||||
|
||||
marbleGame.PlayGame(17, 1104);
|
||||
long highScore = marbleGame.GetHighScore();
|
||||
marbleGame.PlayGame(17, 1104);
|
||||
long highScore = marbleGame.GetHighScore();
|
||||
|
||||
Assert.Equal(2764, highScore);
|
||||
}
|
||||
Assert.Equal(2764, highScore);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PlayGame__Test5()
|
||||
{
|
||||
MarbleGame marbleGame = new MarbleGame();
|
||||
[Fact]
|
||||
public void PlayGame__Test5()
|
||||
{
|
||||
MarbleGame marbleGame = new();
|
||||
|
||||
marbleGame.PlayGame(21, 6111);
|
||||
long highScore = marbleGame.GetHighScore();
|
||||
marbleGame.PlayGame(21, 6111);
|
||||
long highScore = marbleGame.GetHighScore();
|
||||
|
||||
Assert.Equal(54718, highScore);
|
||||
}
|
||||
Assert.Equal(54718, highScore);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PlayGame__Test6()
|
||||
{
|
||||
MarbleGame marbleGame = new MarbleGame();
|
||||
[Fact]
|
||||
public void PlayGame__Test6()
|
||||
{
|
||||
MarbleGame marbleGame = new();
|
||||
|
||||
marbleGame.PlayGame(30, 5807);
|
||||
long highScore = marbleGame.GetHighScore();
|
||||
marbleGame.PlayGame(30, 5807);
|
||||
long highScore = marbleGame.GetHighScore();
|
||||
|
||||
Assert.Equal(37305, highScore);
|
||||
}
|
||||
Assert.Equal(37305, highScore);
|
||||
}
|
||||
}
|
||||
1
AdventOfCode2018.Tests/Usings.cs
Normal file
1
AdventOfCode2018.Tests/Usings.cs
Normal file
@@ -0,0 +1 @@
|
||||
global using Xunit;
|
||||
Reference in New Issue
Block a user