my AoC solutions in c#
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
5.6 KiB

9 months ago
namespace aoc2021.test;
[TestClass]
public class DayTests
{
8 months ago
private const string Day13Actual = @"
";
private const string Day13Test = @"
";
9 months ago
[DataTestMethod]
9 months ago
[DataRow(typeof(Day01), "1616", "1645")]
9 months ago
[DataRow(typeof(Day02), "2272262", "2134882034")]
8 months ago
[DataRow(typeof(Day03), "3009600", "6940518")]
8 months ago
[DataRow(typeof(Day04), "8580", "9576")]
8 months ago
[DataRow(typeof(Day05), "7318", "19939")]
8 months ago
[DataRow(typeof(Day06), "362740", "1644874076764")]
8 months ago
[DataRow(typeof(Day07), "345035", "97038163")]
[DataRow(typeof(Day08), "362", "1020159")]
8 months ago
[DataRow(typeof(Day09), "478", "1327014")]
8 months ago
[DataRow(typeof(Day10), "288291", "820045242")]
8 months ago
[DataRow(typeof(Day11), "1613", "510")]
8 months ago
[DataRow(typeof(Day12), "4549", "120535")]
8 months ago
[DataRow(typeof(Day13), "837", Day13Actual)]
8 months ago
[DataRow(typeof(Day14), "5656", "12271437788530")]
8 months ago
[DataRow(typeof(Day15), "702", "2955")]
[DataRow(typeof(Day16), "852", "19348959966392")]
8 months ago
[DataRow(typeof(Day17), "12090", "5059")]
8 months ago
[DataRow(typeof(Day18), "4289", "4807")]
8 months ago
// [DataRow(typeof(Day19), "338", "9862")] // takes too long and i don't feel like optimizing
8 months ago
[DataRow(typeof(Day20), "5306", "17497")]
8 months ago
[DataRow(typeof(Day21), "512442", "346642902541848")]
[DataRow(typeof(Day22), "658691", "1228699515783640")]
8 months ago
[DataRow(typeof(Day23), "15365", "52055")]
8 months ago
[DataRow(typeof(Day24), "99299513899971", "93185111127911")]
8 months ago
[DataRow(typeof(Day25), "417", "")]
9 months ago
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");
Assert.IsTrue(File.Exists(day.FileName));
8 months ago
Console.Write($"Day {day.DayNumber,2}: {day.PuzzleName,-25} ");
9 months ago
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed in constructor");
// part 1
s.Reset();
s.Start();
var part1Actual = day.Part1().ToString();
9 months ago
s.Stop();
8 months ago
Console.Write($"Part 1: {part1Actual,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
9 months ago
Assert.AreEqual(part1, part1Actual, $"Incorrect answer for Day {day.DayNumber} Part1");
// part 2
s.Reset();
s.Start();
var part2Actual = day.Part2().ToString();
9 months ago
s.Stop();
8 months ago
Console.Write($"Part 2: {part2Actual,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
Assert.AreEqual(part2, part2Actual, $"Incorrect answer for Day {day.DayNumber} Part2");
}
8 months ago
[DataTestMethod]
[DataRow(typeof(Day01), "7", "5")]
9 months ago
[DataRow(typeof(Day02), "150", "900")]
8 months ago
[DataRow(typeof(Day03), "198", "230")]
8 months ago
[DataRow(typeof(Day04), "4512", "1924")]
8 months ago
[DataRow(typeof(Day05), "5", "12")]
8 months ago
[DataRow(typeof(Day06), "5934", "26984457539")]
8 months ago
[DataRow(typeof(Day07), "37", "168")]
[DataRow(typeof(Day08), "26", "61229")]
8 months ago
[DataRow(typeof(Day09), "15", "1134")]
8 months ago
[DataRow(typeof(Day10), "26397", "288957")]
8 months ago
[DataRow(typeof(Day11), "1656", "195")]
8 months ago
[DataRow(typeof(Day12), "226", "3509")]
8 months ago
[DataRow(typeof(Day13), "17", Day13Test)]
8 months ago
[DataRow(typeof(Day14), "1588", "2188189693529")]
8 months ago
[DataRow(typeof(Day15), "40", "315")]
[DataRow(typeof(Day16), "16", "15")]
8 months ago
[DataRow(typeof(Day17), "45", "112")]
8 months ago
[DataRow(typeof(Day18), "4140", "3993")]
8 months ago
[DataRow(typeof(Day19), "79", "3621")]
8 months ago
[DataRow(typeof(Day20), "35", "3351")]
8 months ago
[DataRow(typeof(Day21), "739785", "444356092776315")]
[DataRow(typeof(Day22), "590784", "39769202357779")]
8 months ago
[DataRow(typeof(Day23), "12521", "44169")]
8 months ago
[DataRow(typeof(Day25), "58", "")]
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));
8 months ago
Console.Write($"Day {day.DayNumber,2}: {day.PuzzleName,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed in constructor");
// part 1
s.Reset();
s.Start();
var part1Actual = day.Part1().ToString();
s.Stop();
8 months ago
Console.Write($"Part 1: {part1Actual,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
Assert.AreEqual(part1, part1Actual, $"Incorrect answer for Day {day.DayNumber} Part1");
// part 2
s.Reset();
s.Start();
var part2Actual = day.Part2().ToString();
s.Stop();
8 months ago
Console.Write($"Part 2: {part2Actual,-25} ");
Console.WriteLine($"{s.ScaleMilliseconds()} ms elapsed");
9 months ago
Assert.AreEqual(part2, part2Actual, $"Incorrect answer for Day {day.DayNumber} Part2");
}
}