Skip to content

Commit 25f7a29

Browse files
committed
Merge branch 'main' into handle-for-remote-input
2 parents 4c83674 + 43e4d4e commit 25f7a29

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

src/AdventOfCode.Commons/AdventOfCode.Commons.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2929
<PrivateAssets>all</PrivateAssets>
3030
</PackageReference>
31+
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
3132
</ItemGroup>
3233

3334
</Project>

src/AdventOfCode.Commons/TestEngine.cs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ namespace AdventOfCode.Commons;
77
/// <summary>
88
/// Test engine for the implemented <typeparamref name="TSolver"/>
99
/// </summary>
10-
///
10+
///
1111
/// <typeparam name="TSolver">
1212
/// The <see cref="Solver{TInput, TResult}"/> to use
1313
/// </typeparam>
14-
///
14+
///
1515
/// <typeparam name="TInput">
1616
/// The type of the data used to solve the puzzle
1717
/// </typeparam>
18-
///
18+
///
1919
/// <typeparam name="TResult">
2020
/// The type of the result of the puzzle
2121
/// </typeparam>
@@ -47,6 +47,14 @@ public record Example
4747
/// </summary>
4848
public record Puzzle
4949
{
50+
/// <summary>
51+
/// If set to <c>true</c>, the tests for this puzzle will be skipped
52+
/// </summary>
53+
/// <remarks>
54+
/// Default is <c>false</c>
55+
/// </remarks>
56+
public bool ShouldSkipTests { get; init; } = false;
57+
5058
/// <summary>
5159
/// The <see cref="Example"/> to use to test <see cref="Solver{TInput, TResult}"/>
5260
/// </summary>
@@ -63,30 +71,40 @@ public record Puzzle
6371
/// </summary>
6472
private readonly TSolver _solver;
6573

66-
protected TestEngine()
74+
protected TestEngine()
6775
=> _solver = new TSolver();
6876

6977
#region Part #1
7078

7179
public abstract Puzzle PartOne { get; }
7280

73-
[Fact(DisplayName = "Part One - Example")]
81+
[SkippableFact(DisplayName = "Part One - Example")]
7482
public void PartOneExampleTest()
7583
{
84+
Skip.If(PartOne.ShouldSkipTests, "Puzzle.ShouldSkipTests has been set to true, test skipped");
85+
86+
// Arrange
7687
var input = PartOne.Example.Input;
7788

89+
// Act
7890
var result = _solver.PartOne(input);
7991

92+
// Assert
8093
result.Should().Be(PartOne.Example.Result);
8194
}
8295

83-
[Fact(DisplayName = "Part One - Solution")]
96+
[SkippableFact(DisplayName = "Part One - Solution")]
8497
public void PartOneSolutionTest()
8598
{
99+
Skip.If(PartOne.ShouldSkipTests, "Puzzle.ShouldSkipTests has been set to true, test skipped");
100+
101+
// Arrange
86102
var input = _solver.Input;
87103

104+
// Act
88105
var result = _solver.PartOne(input.Value);
89106

107+
// Assert
90108
result.Should().Be(PartOne.Solution);
91109
}
92110

@@ -96,23 +114,33 @@ public void PartOneSolutionTest()
96114

97115
public abstract Puzzle PartTwo { get; }
98116

99-
[Fact(DisplayName = "Part Two - Example")]
117+
[SkippableFact(DisplayName = "Part Two - Example")]
100118
public void PartTwoExampleTest()
101119
{
120+
Skip.If(PartTwo.ShouldSkipTests, "Puzzle.ShouldSkipTests has been set to true, test skipped");
121+
122+
// Arrange
102123
var input = PartTwo.Example.Input;
103124

125+
// Act
104126
var result = _solver.PartTwo(input);
105127

128+
// Assert
106129
result.Should().Be(PartTwo.Example.Result);
107130
}
108131

109-
[Fact(DisplayName = "Part Two - Solution")]
132+
[SkippableFact(DisplayName = "Part Two - Solution")]
110133
public void PartTwoSolutionTest()
111134
{
135+
Skip.If(PartTwo.ShouldSkipTests, "Puzzle.ShouldSkipTests has been set to true, test skipped");
136+
137+
// Arrange
112138
var input = _solver.Input;
113139

140+
// Act
114141
var result = _solver.PartTwo(input.Value);
115142

143+
// Assert
116144
result.Should().Be(PartTwo.Solution);
117145
}
118146

src/AdventOfCode.Usage/WithLocalInput/SolverTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class SolverTest : TestEngine<Solver, int[], int>
1717
Input = new[] { 1, 2, 3 },
1818
Result = 3,
1919
},
20-
2120
Solution = 5,
2221
};
2322

@@ -28,7 +27,6 @@ public class SolverTest : TestEngine<Solver, int[], int>
2827
Input = new[] { 1, 2, 3 },
2928
Result = 6,
3029
},
31-
3230
Solution = 15,
3331
};
3432
}

0 commit comments

Comments
 (0)