Skip to content

Releases: pBouillon/dotnet-advent-of-code-template

v4.0

06 Nov 21:35

Choose a tag to compare

Dependencies

  • The template now targets .NET 9
  • Removed FluentAssertions in profit of Shouldly

Fluent API for Puzzle Inputs

You can now define your puzzles using the fluent API.

Before (v3.0):

public override Puzzle PartOne => new()
{
    Example = new()
    {
        RawInput = ["1", "2", "3"],
        Input = [1, 2, 3],
        Result = 3,
    },
    Solution = 5,
};

Now (v4.0):

public override Puzzle PartOne => PuzzleBuilder
    .FromInput(["1", "2", "3"])
    .ParsedAs([1, 2, 3])
    .ExpectsResult(3)
    .WithTheActualSolutionBeing(5);

Alternatively, you can use FromParsedInput to skip the test of the parsing step:

public override Puzzle PartTwo => PuzzleBuilder
    .FromParsedInput([1, 2, 3]) 
    .ExpectsResult(6)
    .WithTheActualSolutionBeing(15);

v3.0

02 Dec 09:37
ef16fbd

Choose a tag to compare

Dependencies

The template now targets .NET 8

Parser testing

You can now test your parsing.

This testing feature allows you to verify the correctness of the ParseInput method by comparing its output with manually provided raw input. It's completely optional, so you can choose to use it based on your preferences.

If you would like to, define the RawInput property along with your Input in your Example:

public override Puzzle PartOne => new()
{
    Example = new()
    {
        // 👇 Since this is defined, a test will run to check if `ParseInput(RawInput)` is equal to `Input`
        RawInput = ["1", "2", "3"],
        Input = [1, 2, 3],
        Result = 3,
    },
    Solution = 5,
};

Since the example might change from one part to the other, the RawInput is defined in each part instead of on the puzzle-level

If ShouldSkipTest is set to true, or if RawInput is not specified or an empty array, no test will be run against Solver.ParseInput:

public override Puzzle PartOne => new()
{
    Example = new()
    {
        // 👇 `RawInput` is empty, no test will be run
        RawInput = [],
        Input = [1, 2, 3],
        Result = 3,
    },
    Solution = 5,
};
public override Puzzle PartTwo => new()
{
    // 👇 `RawInput` is not set, no test will be run
    Example = new()
    {
        Input = [1, 2, 3],
        Result = 6,
    },
    Solution = 15,
};

v2.0

04 Dec 16:18
5ff5a6f

Choose a tag to compare

Remote puzzle input handling

You can now change how your input is retrieved when creating your Solver.

For the one using a local input, specify its path in the constructor:

public class Solver : Solver<int[], int>
{
    public Solver() : base(inputPath: "WithLocalInput/input.txt") { }
    // ...
}

And for the remote input, specify instead the year and the date of the puzzle:

public class Solver : Solver<int[], int>
{
    public Solver() : base(year: 2022, day: 4) { }
    // ...
}

For this to work, you will need to set your Advent of Code cookie, please refer to the troubleshooting section of the readme to do so

Disable tests on demand

If you want to skip the tests of a part of a given puzzle, all you need to set is ShouldSkipTests to true and the tests linked to this puzzle part will be skipped:

public class SolverTest : TestEngine<Solver, int[], int>
{
    // Tests for the example and puzzle input will be skipped
    public override Puzzle PartOne => new()
    {
        ShouldSkipTests = true,
        Example = new()
        {
            Input = new[] { 199, 200, 208, 210, 200, 207, 240, 269, 260, 263 },
            Result = 7,
        },
        Solution = 1696,
    };

    public override Puzzle PartTwo => new()
    {
        Example = new()
        {
            Input = new[] { 199, 200, 208, 210, 200, 207, 240, 269, 260, 263 },
            Result = 5,
        },
        Solution = 1737,
    };
}

Lazily access the puzzle input

Instead of fetching and parsing the puzzle input on creation, this will now be done only when querying it the first time

Initial release

03 Dec 14:15
f282714

Choose a tag to compare

  • Exposes the Solver and its TestEngine
  • Comes with a demo project for its usage
  • Uses xUnit and FluentAssertions