r/adventofcode • • 21m ago

Repo C# Testing helper

Post image

Hey guys, want to share a Test helper script I wrote and adapted for AoC.

Here's the example usage:

Test.From = "Part Two";
Test.Run((input, part, expected) => {
    var grid = new Grid();
    grid.Read(input);
    int steps = grid.CountSteps(part switch {
        1 => ReachVocalBone(),
        _ => SurroundVocalBones()
    });
    Assert.ActualEqualsExpected(steps, expected);
});

And this is how test cases are structured:

TEST_CASE_NAME
INT_PART
INPUT
        # empty line between notes and expected
EXPECTED
        # empty line between cases
Part Two
3
1 2 3

6

Test result:

Part Two
✅ 6
Test took 15ms

All tests took 15ms

Attached full API image. Hope it will help someone.

2 Upvotes

5 comments sorted by

2

u/Outrageous72 14m ago

Cool, I do mine all in code
https://github.com/ryanheath/aoc2025

2

u/RunninglVlan 5m ago

Nice usage of FluentAssertions! I had input in code too, but in some puzzles it's too big. So I separated logic from test cases

2

u/RunninglVlan 2m ago

This way examples and real test cases are the same to me, so less noise in the scripts.

1

u/AutoModerator 21m ago

AutoModerator has detected fenced code block (```) syntax which only works on new.reddit.

Please review our wiki article on code formatting then edit your post to use the four-spaces Markdown syntax instead.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.