Skip to content

Commit 0ca389d

Browse files
authored
Merge pull request #3 from chuckries/dev/chuckr/improvements
Dev/chuckr/improvements
2 parents 6960328 + 2c8e414 commit 0ca389d

File tree

8 files changed

+4901
-2
lines changed

8 files changed

+4901
-2
lines changed

.github/workflows/test.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
inputs:
8+
reason:
9+
description: 'Reason for manual trigger'
10+
required: false
11+
default: 'Manual test run'
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup .NET
22+
uses: actions/setup-dotnet@v4
23+
with:
24+
dotnet-version: '9.0.x'
25+
26+
- name: Restore dependencies
27+
run: dotnet restore
28+
29+
- name: Build solution
30+
run: dotnet build --no-restore --configuration Release
31+
32+
- name: Run tests
33+
run: dotnet test --no-build --configuration Release --verbosity normal --logger trx --results-directory "TestResults"
34+
35+
- name: Test Report
36+
uses: dorny/test-reporter@v1
37+
if: success() || failure() # run this step even if tests failed
38+
with:
39+
name: .NET Tests
40+
path: TestResults/*.trx
41+
reporter: dotnet-trx

Directory.Build.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<RepoRootPath>$(MSBuildThisFileDirectory)</RepoRootPath>
11+
<BaseIntermediateOutputPath>$(RepoRootPath)obj\$([MSBuild]::MakeRelative($(RepoRootPath), $(MSBuildProjectDirectory)))\</BaseIntermediateOutputPath>
12+
<BaseOutputPath Condition=" '$(BaseOutputPath)' == '' ">$(RepoRootPath)bin\$(MSBuildProjectName)\</BaseOutputPath>
13+
</PropertyGroup>
814
</Project>

global.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sdk": {
3+
"version": "9.0.0",
4+
"rollForward": "latestFeature"
5+
}
6+
}

test/AdventOfCode.2020/Day04.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public void Part2()
7373
}
7474

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

7979
private static Regex s_Regex2 = new Regex(
80-
@"((?'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}",
80+
@"((?'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}",
8181
RegexOptions.Compiled);
8282
}

test/AdventOfCode.2022/Day01.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace AdventOfCode._2022;
2+
3+
public class Day01
4+
{
5+
6+
List<List<int>> input;
7+
8+
public Day01()
9+
{
10+
this.input = new();
11+
List<int> current = new();
12+
foreach (string line in File.ReadAllLines("Inputs/day01.txt"))
13+
{
14+
if (line == string.Empty)
15+
{
16+
this.input.Add(current);
17+
current = new();
18+
}
19+
else
20+
{
21+
current.Add(int.Parse(line));
22+
}
23+
}
24+
}
25+
26+
[Fact]
27+
public void Part1()
28+
{
29+
int answer = this.input.Select(g => g.Sum()).Max();
30+
Assert.Equal(66616, answer);
31+
}
32+
33+
[Fact]
34+
public void Part2()
35+
{
36+
int answer = this.input.Select(g => g.Sum()).OrderByDescending(i => i).Take(3).Sum();
37+
Assert.Equal(199172, answer);
38+
}
39+
}

test/AdventOfCode.2022/Day02.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.Net;
2+
3+
namespace AdventOfCode._2022;
4+
5+
public class Day02
6+
{
7+
List<(char, char)> input;
8+
9+
public Day02()
10+
{
11+
input = File.ReadAllLines("Inputs/Day02.txt")
12+
.Select(line => line.Split(' '))
13+
.Select(parts => (parts[0][0], parts[1][0]))
14+
.ToList();
15+
}
16+
17+
[Fact]
18+
public void Part1()
19+
{
20+
static int Result(char a, char b) => (a, b) switch
21+
{
22+
('A', 'X') => 4, // Rock vs Rock
23+
('A', 'Y') => 8, // Rock vs Paper
24+
('A', 'Z') => 3, // Rock vs Scissors
25+
('B', 'X') => 1, // Paper vs Rock
26+
('B', 'Y') => 5, // Paper vs Paper
27+
('B', 'Z') => 9, // Paper vs Scissors
28+
('C', 'X') => 7, // Scissors vs Rock
29+
('C', 'Y') => 2, // Scissors vs Paper
30+
('C', 'Z') => 6, // Scissors vs Scissors
31+
_ => throw new ArgumentException("Invalid input")
32+
};
33+
34+
int answer = input.Sum(pair => Result(pair.Item1, pair.Item2));
35+
Assert.Equal(14297, answer);
36+
}
37+
38+
[Fact]
39+
public void Part2()
40+
{
41+
static int Result(char a, char b) => (a, b) switch
42+
{
43+
('A', 'X') => 3, // Rock vs Scissors
44+
('A', 'Y') => 4, // Rock vs Rock
45+
('A', 'Z') => 8, // Rock vs Paper
46+
('B', 'X') => 1, // Paper vs Rock
47+
('B', 'Y') => 5, // Paper vs Paper
48+
('B', 'Z') => 9, // Paper vs Scissors
49+
('C', 'X') => 2, // Scissors vs Paper
50+
('C', 'Y') => 6, // Scissors vs Scissors
51+
('C', 'Z') => 7, // Scissors vs Rock
52+
_ => throw new ArgumentException("Invalid input")
53+
};
54+
int answer = input.Sum(pair => Result(pair.Item1, pair.Item2));
55+
Assert.Equal(10498, answer);
56+
}
57+
}

0 commit comments

Comments
 (0)