Skip to content
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

feat: test file generator #11

Merged
merged 7 commits into from
Dec 2, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: skip puzzle tests conditionally
  • Loading branch information
S-ecki committed Dec 2, 2023
commit 33bd36e1ab3d2c69a5bd13042996517591673f60
22 changes: 18 additions & 4 deletions day_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ const _exampleSolutionPart2 = 0;
/// The actual solution for the FIRST PART of the puzzle, based on your input.
/// This can only be filled out after you have solved the puzzle and is used
/// for regression testing when refactoring.
const _puzzleSolutionPart1 = 0;
/// As long as the variable is `null`, the tests will be skipped.
const _puzzleSolutionPart1 = null;

/// The actual solution for the SECOND PART of the puzzle, based on your input.
/// This can only be filled out after you have solved the puzzle and is used
/// for regression testing when refactoring.
const _puzzleSolutionPart2 = 0;
/// As long as the variable is `null`, the tests will be skipped.
const _puzzleSolutionPart2 = null;

void main() {
group(
Expand All @@ -177,8 +179,20 @@ void main() {
'Day $day - Puzzle Input',
() {
final day = Day$day();
// test('Part 1', () => expect(day.solvePart1(), _puzzleSolutionPart1));
// test('Part 2', () => expect(day.solvePart2(), _puzzleSolutionPart2));
test(
'Part 1',
skip: _puzzleSolutionPart1 == null
? 'Skipped because _puzzleSolutionPart1 is null'
: false,
() => expect(day.solvePart1(), _puzzleSolutionPart1),
);
test(
'Part 2',
skip: _puzzleSolutionPart2 == null
? 'Skipped because _puzzleSolutionPart2 is null'
: false,
() => expect(day.solvePart1(), _puzzleSolutionPart2),
);
},
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the Puzzle Input group commented out by default to prevent the tests from failing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Else the test suite would still fail until you provide the _puzzleSolutionPart1 and _puzzleSolutionPart2 variables and make it less clear that your solution worked.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point! Pushed the changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could be a bit more "smart" about it and skip the test if the solution hasn't been filled in:

const _puzzleSolutionPart1 = null;
const _puzzleSolutionPart2 = null;

group(
    'Day 01 - Puzzle Input',
    () {
      final day = Day01();
      test(
        'Part 1',
        skip: _puzzleSolutionPart1 == null
            ? 'Skipped because _puzzleSolutionPart1 is null'
            : false,
        () => expect(day.solvePart1(), _puzzleSolutionPart1),
      );
      test(
        'Part 1',
        skip: _puzzleSolutionPart2 == null
            ? 'Skipped because _puzzleSolutionPart2 is null'
            : false,
        () => expect(day.solvePart1(), _puzzleSolutionPart2),
      );
    },
  );

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is perfect! I will add and commit it! 🚀
Was also thinking about skipping the tests without touching the actual test code, but stopped at the thought of a shouldTest boolean set by the user 😅
Thanks a lot! 💙

}
Expand Down