2021-11-11 05:19:35 +00:00
|
|
|
namespace aoc2021.test;
|
|
|
|
|
|
|
|
[TestClass]
|
|
|
|
public class DayTests
|
|
|
|
{
|
2021-12-13 06:20:33 +00:00
|
|
|
private const string Day13Actual = @"
|
|
|
|
████▒███▒▒████▒▒██▒▒█▒▒█▒▒██▒▒█▒▒█▒█▒▒█
|
|
|
|
█▒▒▒▒█▒▒█▒▒▒▒█▒█▒▒█▒█▒█▒▒█▒▒█▒█▒▒█▒█▒▒█
|
|
|
|
███▒▒█▒▒█▒▒▒█▒▒█▒▒▒▒██▒▒▒█▒▒▒▒████▒█▒▒█
|
|
|
|
█▒▒▒▒███▒▒▒█▒▒▒█▒██▒█▒█▒▒█▒▒▒▒█▒▒█▒█▒▒█
|
|
|
|
█▒▒▒▒█▒▒▒▒█▒▒▒▒█▒▒█▒█▒█▒▒█▒▒█▒█▒▒█▒█▒▒█
|
|
|
|
████▒█▒▒▒▒████▒▒███▒█▒▒█▒▒██▒▒█▒▒█▒▒██▒
|
|
|
|
";
|
|
|
|
|
|
|
|
private const string Day13Test = @"
|
|
|
|
█████
|
|
|
|
█▒▒▒█
|
|
|
|
█▒▒▒█
|
|
|
|
█▒▒▒█
|
|
|
|
█████
|
|
|
|
";
|
|
|
|
|
2021-11-11 05:19:35 +00:00
|
|
|
[DataTestMethod]
|
2021-12-01 06:05:35 +00:00
|
|
|
[DataRow(typeof(Day01), "1616", "1645")]
|
2021-12-02 05:11:44 +00:00
|
|
|
[DataRow(typeof(Day02), "2272262", "2134882034")]
|
2021-12-03 16:59:54 +00:00
|
|
|
[DataRow(typeof(Day03), "3009600", "6940518")]
|
2021-12-04 17:52:07 +00:00
|
|
|
[DataRow(typeof(Day04), "8580", "9576")]
|
2021-12-06 00:36:45 +00:00
|
|
|
[DataRow(typeof(Day05), "7318", "19939")]
|
2021-12-06 06:00:14 +00:00
|
|
|
[DataRow(typeof(Day06), "362740", "1644874076764")]
|
2021-12-07 16:27:50 +00:00
|
|
|
[DataRow(typeof(Day07), "345035", "97038163")]
|
2021-12-08 16:33:26 +00:00
|
|
|
[DataRow(typeof(Day08), "362", "1020159")]
|
2021-12-09 06:20:41 +00:00
|
|
|
[DataRow(typeof(Day09), "478", "1327014")]
|
2021-12-10 17:49:49 +00:00
|
|
|
[DataRow(typeof(Day10), "288291", "820045242")]
|
2021-12-11 05:40:11 +00:00
|
|
|
[DataRow(typeof(Day11), "1613", "510")]
|
2021-12-12 17:51:36 +00:00
|
|
|
[DataRow(typeof(Day12), "4549", "120535")]
|
2021-12-13 06:20:33 +00:00
|
|
|
[DataRow(typeof(Day13), "837", Day13Actual)]
|
2021-12-14 16:41:00 +00:00
|
|
|
[DataRow(typeof(Day14), "5656", "12271437788530")]
|
2021-12-15 18:29:21 +00:00
|
|
|
[DataRow(typeof(Day15), "702", "2955")]
|
2021-12-16 16:48:02 +00:00
|
|
|
[DataRow(typeof(Day16), "852", "19348959966392")]
|
2021-12-17 22:00:31 +00:00
|
|
|
[DataRow(typeof(Day17), "12090", "5059")]
|
2021-12-18 15:59:07 +00:00
|
|
|
[DataRow(typeof(Day18), "4289", "4807")]
|
2021-12-19 17:46:41 +00:00
|
|
|
// [DataRow(typeof(Day19), "338", "9862")] // takes too long and i don't feel like optimizing
|
2021-12-20 06:52:10 +00:00
|
|
|
[DataRow(typeof(Day20), "5306", "17497")]
|
2021-12-22 15:04:15 +00:00
|
|
|
[DataRow(typeof(Day21), "512442", "346642902541848")]
|
|
|
|
[DataRow(typeof(Day22), "658691", "1228699515783640")]
|
2021-12-23 18:23:35 +00:00
|
|
|
[DataRow(typeof(Day23), "15365", "52055")]
|
2021-12-24 17:56:10 +00:00
|
|
|
[DataRow(typeof(Day24), "99299513899971", "93185111127911")]
|
2021-12-25 20:00:36 +00:00
|
|
|
[DataRow(typeof(Day25), "417", "")]
|
2021-11-11 05:19:35 +00:00
|
|
|
public void CheckAllDays(Type dayType, string part1, string part2)
|
|
|
|
{
|
|
|
|
var s = Stopwatch.StartNew();
|
|
|
|
var day = Activator.CreateInstance(dayType) as Day;
|
|
|
|
s.Stop();
|
|
|
|
Assert.IsNotNull(day, "failed to instantiate day object");
|
2021-12-01 15:10:43 +00:00
|
|
|
Assert.IsTrue(File.Exists(day.FileName));
|
2021-12-10 18:12:26 +00:00
|
|
|
Console.Write($"Day {day.DayNumber,2}: {day.PuzzleName,-25} ");
|
2021-11-11 05:19:35 +00:00
|
|
|
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed in constructor");
|
|
|
|
|
|
|
|
// part 1
|
|
|
|
s.Reset();
|
|
|
|
s.Start();
|
2021-12-12 20:09:41 +00:00
|
|
|
var part1Actual = day.Part1().ToString();
|
2021-11-11 05:19:35 +00:00
|
|
|
s.Stop();
|
2021-12-10 18:12:26 +00:00
|
|
|
Console.Write($"Part 1: {part1Actual,-25} ");
|
2021-12-01 15:10:43 +00:00
|
|
|
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
|
2021-11-11 05:19:35 +00:00
|
|
|
Assert.AreEqual(part1, part1Actual, $"Incorrect answer for Day {day.DayNumber} Part1");
|
|
|
|
|
|
|
|
// part 2
|
|
|
|
s.Reset();
|
|
|
|
s.Start();
|
2021-12-12 20:09:41 +00:00
|
|
|
var part2Actual = day.Part2().ToString();
|
2021-11-11 05:19:35 +00:00
|
|
|
s.Stop();
|
2021-12-10 18:12:26 +00:00
|
|
|
Console.Write($"Part 2: {part2Actual,-25} ");
|
2021-12-01 15:10:43 +00:00
|
|
|
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
|
|
|
|
Assert.AreEqual(part2, part2Actual, $"Incorrect answer for Day {day.DayNumber} Part2");
|
|
|
|
}
|
2021-12-24 17:56:10 +00:00
|
|
|
|
2021-12-01 15:10:43 +00:00
|
|
|
[DataTestMethod]
|
|
|
|
[DataRow(typeof(Day01), "7", "5")]
|
2021-12-02 05:11:44 +00:00
|
|
|
[DataRow(typeof(Day02), "150", "900")]
|
2021-12-03 06:05:45 +00:00
|
|
|
[DataRow(typeof(Day03), "198", "230")]
|
2021-12-04 17:52:07 +00:00
|
|
|
[DataRow(typeof(Day04), "4512", "1924")]
|
2021-12-06 00:36:45 +00:00
|
|
|
[DataRow(typeof(Day05), "5", "12")]
|
2021-12-06 06:00:14 +00:00
|
|
|
[DataRow(typeof(Day06), "5934", "26984457539")]
|
2021-12-07 16:27:50 +00:00
|
|
|
[DataRow(typeof(Day07), "37", "168")]
|
2021-12-08 06:42:15 +00:00
|
|
|
[DataRow(typeof(Day08), "26", "61229")]
|
2021-12-09 06:20:41 +00:00
|
|
|
[DataRow(typeof(Day09), "15", "1134")]
|
2021-12-10 05:43:57 +00:00
|
|
|
[DataRow(typeof(Day10), "26397", "288957")]
|
2021-12-11 05:40:11 +00:00
|
|
|
[DataRow(typeof(Day11), "1656", "195")]
|
2021-12-12 17:51:36 +00:00
|
|
|
[DataRow(typeof(Day12), "226", "3509")]
|
2021-12-13 06:20:33 +00:00
|
|
|
[DataRow(typeof(Day13), "17", Day13Test)]
|
2021-12-14 05:51:30 +00:00
|
|
|
[DataRow(typeof(Day14), "1588", "2188189693529")]
|
2021-12-15 18:29:21 +00:00
|
|
|
[DataRow(typeof(Day15), "40", "315")]
|
2021-12-16 16:48:02 +00:00
|
|
|
[DataRow(typeof(Day16), "16", "15")]
|
2021-12-17 21:46:29 +00:00
|
|
|
[DataRow(typeof(Day17), "45", "112")]
|
2021-12-18 15:59:07 +00:00
|
|
|
[DataRow(typeof(Day18), "4140", "3993")]
|
2021-12-19 17:46:41 +00:00
|
|
|
[DataRow(typeof(Day19), "79", "3621")]
|
2021-12-20 06:52:10 +00:00
|
|
|
[DataRow(typeof(Day20), "35", "3351")]
|
2021-12-22 15:04:15 +00:00
|
|
|
[DataRow(typeof(Day21), "739785", "444356092776315")]
|
|
|
|
[DataRow(typeof(Day22), "590784", "39769202357779")]
|
2021-12-23 18:23:35 +00:00
|
|
|
[DataRow(typeof(Day23), "12521", "44169")]
|
2021-12-25 20:00:36 +00:00
|
|
|
[DataRow(typeof(Day25), "58", "")]
|
2021-12-01 15:10:43 +00:00
|
|
|
public void CheckTestInputs(Type dayType, string part1, string part2)
|
|
|
|
{
|
|
|
|
Day.UseTestInput = true;
|
|
|
|
var s = Stopwatch.StartNew();
|
|
|
|
var day = Activator.CreateInstance(dayType) as Day;
|
|
|
|
s.Stop();
|
|
|
|
Assert.IsNotNull(day, "failed to instantiate day object");
|
|
|
|
Assert.IsTrue(File.Exists(day.FileName));
|
2021-12-10 18:12:26 +00:00
|
|
|
Console.Write($"Day {day.DayNumber,2}: {day.PuzzleName,-25} ");
|
2021-12-01 15:10:43 +00:00
|
|
|
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed in constructor");
|
|
|
|
|
|
|
|
// part 1
|
|
|
|
s.Reset();
|
|
|
|
s.Start();
|
2021-12-12 20:09:41 +00:00
|
|
|
var part1Actual = day.Part1().ToString();
|
2021-12-01 15:10:43 +00:00
|
|
|
s.Stop();
|
2021-12-10 18:12:26 +00:00
|
|
|
Console.Write($"Part 1: {part1Actual,-25} ");
|
2021-12-01 15:10:43 +00:00
|
|
|
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
|
|
|
|
Assert.AreEqual(part1, part1Actual, $"Incorrect answer for Day {day.DayNumber} Part1");
|
|
|
|
|
|
|
|
// part 2
|
|
|
|
s.Reset();
|
|
|
|
s.Start();
|
2021-12-12 20:09:41 +00:00
|
|
|
var part2Actual = day.Part2().ToString();
|
2021-12-01 15:10:43 +00:00
|
|
|
s.Stop();
|
2021-12-10 18:12:26 +00:00
|
|
|
Console.Write($"Part 2: {part2Actual,-25} ");
|
2021-12-01 15:10:43 +00:00
|
|
|
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
|
2021-11-11 05:19:35 +00:00
|
|
|
Assert.AreEqual(part2, part2Actual, $"Incorrect answer for Day {day.DayNumber} Part2");
|
|
|
|
}
|
|
|
|
}
|