Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Tests

on:
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
reason:
description: 'Reason for manual trigger'
required: false
default: 'Manual test run'

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'

- name: Restore dependencies
run: dotnet restore

- name: Build solution
run: dotnet build --no-restore --configuration Release

- name: Run tests
run: dotnet test --no-build --configuration Release --verbosity normal --logger trx --results-directory "TestResults"

- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure() # run this step even if tests failed
with:
name: .NET Tests
path: TestResults/*.trx
reporter: dotnet-trx
6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<RepoRootPath>$(MSBuildThisFileDirectory)</RepoRootPath>
<BaseIntermediateOutputPath>$(RepoRootPath)obj\$([MSBuild]::MakeRelative($(RepoRootPath), $(MSBuildProjectDirectory)))\</BaseIntermediateOutputPath>
<BaseOutputPath Condition=" '$(BaseOutputPath)' == '' ">$(RepoRootPath)bin\$(MSBuildProjectName)\</BaseOutputPath>
</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "9.0.0",
"rollForward": "latestFeature"
}
}
4 changes: 2 additions & 2 deletions test/AdventOfCode.2020/Day04.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public void Part2()
}

private static Regex s_Regex = new Regex(
@"(?'value'(?'key'byr|iyr|eyr|hgt|hcl|ecl|pid|cid):[#\w]+( |\r\n)?){7,8}",
@"(?'value'(?'key'byr|iyr|eyr|hgt|hcl|ecl|pid|cid):[#\w]+( |\r?\n)?){7,8}",
RegexOptions.Compiled);

private static Regex s_Regex2 = new Regex(
@"((?'x'(byr|iyr|eyr):\d{4}|hgt:\d{2,3}(cm|in)|hcl:#[a-f0-9]{6}|ecl:(amb|blu|brn|gry|grn|hzl|oth)|pid:\d{9}|cid:\w+)( |\r\n)?){7,8}",
@"((?'x'(byr|iyr|eyr):\d{4}|hgt:\d{2,3}(cm|in)|hcl:#[a-f0-9]{6}|ecl:(amb|blu|brn|gry|grn|hzl|oth)|pid:\d{9}|cid:\w+)( |\r?\n)?){7,8}",
RegexOptions.Compiled);
}
39 changes: 39 additions & 0 deletions test/AdventOfCode.2022/Day01.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace AdventOfCode._2022;

public class Day01
{

List<List<int>> input;

public Day01()
{
this.input = new();
List<int> current = new();
foreach (string line in File.ReadAllLines("Inputs/day01.txt"))

Check failure on line 12 in test/AdventOfCode.2022/Day01.cs

View workflow job for this annotation

GitHub Actions / .NET Tests

AdventOfCode._2022.Day01 ► Part1

Failed test found in: TestResults/_pkrvmjbmru5nbw0_2025-08-07_17_01_04.trx TestResults/_pkrvmjbmru5nbw0_2025-08-07_17_01_04.trx Error: System.IO.FileNotFoundException : Could not find file '/home/runner/work/AdventOfCode/AdventOfCode/bin/AdventOfCode.2022/Release/net9.0/Inputs/day01.txt'.
Raw output
System.IO.FileNotFoundException : Could not find file '/home/runner/work/AdventOfCode/AdventOfCode/bin/AdventOfCode.2022/Release/net9.0/Inputs/day01.txt'.
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
   at System.IO.File.ReadAllLines(String path, Encoding encoding)
   at AdventOfCode._2022.Day01..ctor() in /home/runner/work/AdventOfCode/AdventOfCode/test/AdventOfCode.2022/Day01.cs:line 12
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
{
if (line == string.Empty)
{
this.input.Add(current);
current = new();
}
else
{
current.Add(int.Parse(line));
}
}
}

[Fact]
public void Part1()
{
int answer = this.input.Select(g => g.Sum()).Max();
Assert.Equal(66616, answer);
}

[Fact]
public void Part2()
{
int answer = this.input.Select(g => g.Sum()).OrderByDescending(i => i).Take(3).Sum();
Assert.Equal(199172, answer);
}
}
57 changes: 57 additions & 0 deletions test/AdventOfCode.2022/Day02.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Net;

namespace AdventOfCode._2022;

public class Day02
{
List<(char, char)> input;

public Day02()
{
input = File.ReadAllLines("Inputs/Day02.txt")
.Select(line => line.Split(' '))
.Select(parts => (parts[0][0], parts[1][0]))
.ToList();
}

[Fact]
public void Part1()
{
static int Result(char a, char b) => (a, b) switch
{
('A', 'X') => 4, // Rock vs Rock
('A', 'Y') => 8, // Rock vs Paper
('A', 'Z') => 3, // Rock vs Scissors
('B', 'X') => 1, // Paper vs Rock
('B', 'Y') => 5, // Paper vs Paper
('B', 'Z') => 9, // Paper vs Scissors
('C', 'X') => 7, // Scissors vs Rock
('C', 'Y') => 2, // Scissors vs Paper
('C', 'Z') => 6, // Scissors vs Scissors
_ => throw new ArgumentException("Invalid input")
};

int answer = input.Sum(pair => Result(pair.Item1, pair.Item2));
Assert.Equal(14297, answer);
}

[Fact]
public void Part2()
{
static int Result(char a, char b) => (a, b) switch
{
('A', 'X') => 3, // Rock vs Scissors
('A', 'Y') => 4, // Rock vs Rock
('A', 'Z') => 8, // Rock vs Paper
('B', 'X') => 1, // Paper vs Rock
('B', 'Y') => 5, // Paper vs Paper
('B', 'Z') => 9, // Paper vs Scissors
('C', 'X') => 2, // Scissors vs Paper
('C', 'Y') => 6, // Scissors vs Scissors
('C', 'Z') => 7, // Scissors vs Rock
_ => throw new ArgumentException("Invalid input")
};
int answer = input.Sum(pair => Result(pair.Item1, pair.Item2));
Assert.Equal(10498, answer);
}
}
Loading
Loading