-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Support for "test mode" #211
Comments
Let me give it a thought, because I rather provide facilitate doing this in a simple way using proper tests projects, instead of a boolean. Meanwhile, right now you can already do something like this (note the two variants): using NUnit.Framework;
namespace AoC_2024.Test;
public class Day_01 : AoC_2024.Day_01
{
protected override string InputFileDirPath => "TestInputs";
}
public class AnyName : Day_02
{
public override string InputFilePath => Path.Combine(
"TestInputs",
"02_Example.txt");
}
public static class ExampleTests
{
[TestCase(typeof(Day_01), "11", "31")]
[TestCase(typeof(AnyName), "2", "4")]
public static async Task Test(Type type, string sol1, string sol2)
{
if (Activator.CreateInstance(type) is BaseDay instance)
{
await Assert.ThatAsync(async () => await instance.Solve_1(), Is.EqualTo(sol1));
await Assert.ThatAsync(async () => await instance.Solve_2(), Is.EqualTo(sol2));
}
else
{
Assert.Fail($"{type} is not a BaseDay");
}
}
}
I'm aware that having to create another class per day just to override the input file dir path isn't ideal, of course. |
Worth noting: there can be different test data for part 1 vs part 2. See for instance: https://adventofcode.com/2024/day/3 Part 1 test data: EDIT: also, I am implementing your unit test suggestion in this year's Advent, so thanks for the tip! https://github.com/codemonkey85/Advent-of-Code-2024 |
I'm sure you considered this already, but this could be done in a simple way, if there were a way to override the
|
Exactly, my code works in the current version, I provided it as a temporary alternative until this is solved properly. |
Every day's puzzle has some test input data (see https://adventofcode.com/2024/day/1 for instance). What I like to do (and what I assume everyone else does) is build my code around the test, checking that when I'm done, the output matches the provided test solution. However, what this library doesn't have is a way to directly support this pattern. What if we could hardcode the test data as a string in our Day code, and pass in a bool or something from the console to tell the app to use the test data instead of the input data?
For example:
The text was updated successfully, but these errors were encountered: