eduherminio / AoCHelper

Helper .NET library for solving Advent of Code puzzles

Home Page:https://adventofcode.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possibility of testing small demo inputs

Eyap53 opened this issue · comments

Hi,
Thanks for this great tool ! I am using it again this year.

I have a mix between a feature request / question :
I'd like to implement some tests, but not using my own input files, but the small examples that is provided for each question (let's call them demo inputs).
As of now, I have to switch the inputs, but it is very redundant between each part and all my typos ^^'.

I suppose writing a Tests folder that take "test" inputs would be the best, but that mean I need to override by hand each BaseDay just to override InputFileDirPath so that it is the demo input that is used for testing.

Do you think that could be an added feature, or do you see a better way to do it ?

Hi Mael,

First of all, thanks for using AoCHelper and for your kind words. And apologies for the delay, it's being a hectic week.

I can think of two ways of making 'this' (aka providing custom input files) work: changing InputFilePath and changing InputFileDirPath, to accommodate test files/dirs. The former is more flexible, since it allows you to also choose the file name (i.e. in case of having multiple demos/tests per day).

As you probably noticed, those properties don't have a setter, and therefore cannot be modified in an obvious way from a external test method.

What one can do is modifying its getter, and making it point to another settable property.
I've added examples here and here for both cases, but essentially you need to create a custom class like this one:

    abstract class CustomInputPathBaseDay : BaseDay
    {
        public string TestInputFilePath { private get; set; }
        public override string InputFilePath => TestInputFilePath;

        protected CustomInputPathBaseDay()
        {
            TestInputFilePath = base.InputFilePath;
        }
    }

and then modify your settable variable before running the solve methods:

    [TestCase(typeof(Day_99), "TestInputs/Day_1234.txt", "Custom file path: TestInputs/Day_1234.txt", $"No longer useful InputFileDirPath: Inputs")]
    public async Task ModifyInputFilePath(Type type, string inputFilePath, string sol1, string sol2)
    {
        if (Activator.CreateInstance(type) is CustomInputPathBaseDay instance)
        {
            instance.TestInputFilePath = inputFilePath;

            Assert.AreEqual(sol1, await instance.Solve_1());
            Assert.AreEqual(sol2, await instance.Solve_2());
        }
        else
        {
            Assert.Fail();
        }
    }

I'll also note this down as a suggestion for future versions, since I admit it it's not straightforward 😅

Feel free to re-open and/or ask again if you don't manage to get it up and running or I misunderstood what you're asking for.

Well, it seems exactly what I'm looking for !
Thanks for your answer, I'll try that :)