aoc2021/aoc2021.test/DayTests.cs

91 lines
3.5 KiB
C#
Raw Normal View History

2021-11-11 05:19:35 +00:00
namespace aoc2021.test;
[TestClass]
public class DayTests
{
[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-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");
}
[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-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");
}
}