Skip to content

Commit d939ac1

Browse files
committed
2025 day 2 and 3 + benchmarks
1 parent 69494b6 commit d939ac1

29 files changed

Lines changed: 1619 additions & 13 deletions

2025/helloserve.com.AdventOfCode.Test/Day01.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ public sealed class Day01
88
public void Part1(string filename, string expected)
99
{
1010
AdventOfCode.Day01 day01 = new();
11-
var result = day01.Part1(filename);
11+
day01.Filename = filename;
12+
var result = day01.Part1();
1213
Assert.AreEqual(expected, result);
1314
}
1415

@@ -17,7 +18,8 @@ public void Part1(string filename, string expected)
1718
public void Part2(string filename, string expected)
1819
{
1920
AdventOfCode.Day01 day01 = new();
20-
var result = day01.Part2(filename);
21+
day01.Filename = filename;
22+
var result = day01.Part2();
2123
Assert.AreEqual(expected, result);
2224
}
2325

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace helloserve.com.AdventOfCode.Test;
2+
3+
[TestClass]
4+
public class Day02
5+
{
6+
[TestMethod]
7+
[DataRow("Day02.txt", "1227775554")]
8+
public void Day02_Part1(string filename, string expected)
9+
{
10+
AdventOfCode.Day02 day02 = new();
11+
day02.Filename = filename;
12+
var result = day02.Part1();
13+
Assert.AreEqual(expected, result);
14+
}
15+
16+
[TestMethod]
17+
[DataRow("Day02.txt", "4174379265")]
18+
public void Day02_Part2(string filename, string expected)
19+
{
20+
AdventOfCode.Day02 day02 = new();
21+
day02.Filename = filename;
22+
var result = day02.Part2();
23+
Assert.AreEqual(expected, result);
24+
}
25+
26+
[TestMethod]
27+
[DataRow(1188511885, true)]
28+
[DataRow(222220, false)]
29+
[DataRow(222222, true)]
30+
[DataRow(38593859, true)]
31+
[DataRow(82882882, false)]
32+
[DataRow(808080, true)]
33+
public void Day02_IsExtendedId_Test(long value, bool expected)
34+
{
35+
Assert.AreEqual(expected, Range.IsExtendedInvalidId(value));
36+
}
37+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace helloserve.com.AdventOfCode.Test;
2+
3+
[TestClass]
4+
public class Day03
5+
{
6+
[TestMethod]
7+
[DataRow("Day03.txt", "357")]
8+
public void Day03_Part1_Test(string filename, string expected)
9+
{
10+
var day03 = new AdventOfCode.Day03();
11+
day03.Filename = filename;
12+
var actual = day03.Part1();
13+
Assert.AreEqual(expected, actual);
14+
}
15+
16+
[TestMethod]
17+
[DataRow("Day03.txt", "3121910778619")]
18+
public void Day03_Part2_Test(string filename, string expected)
19+
{
20+
var day03 = new AdventOfCode.Day03();
21+
day03.Filename = filename;
22+
var actual = day03.Part2();
23+
Assert.AreEqual(expected, actual);
24+
}
25+
26+
[TestMethod]
27+
[DataRow("818181911112111", 92)]
28+
[DataRow("811111111111119", 89)]
29+
[DataRow("234234234234278", 78)]
30+
[DataRow("987654321111111", 98)]
31+
[DataRow("5342626167342261132346432442524535654423854254336833422424525424435362223322423132824617223244222225", 88)]
32+
[DataRow("3858362282172", 88)]
33+
public void Day03_BatteryBank_Part1_Test(string bank, int expected)
34+
{
35+
var b = new BatteryBank(bank, 2);
36+
Assert.AreEqual(expected, b.BankJoltage);
37+
}
38+
39+
[TestMethod]
40+
[DataRow("818181911112111", 888911112111)]
41+
[DataRow("811111111111119", 811111111119)]
42+
[DataRow("234234234234278", 434234234278)]
43+
[DataRow("987654321111111", 987654321111)]
44+
public void Day03_BatteryBank_Part2_Test(string bank, long expected)
45+
{
46+
var b = new BatteryBank(bank, 12);
47+
Assert.AreEqual(expected, b.BankJoltage);
48+
}
49+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
987654321111111
2+
811111111111119
3+
234234234234278
4+
818181911112111

2025/helloserve.com.AdventOfCode.Test/helloserve.com.AdventOfCode.Test.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
<None Update="Day01.txt">
1717
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1818
</None>
19+
<None Update="Day03.txt">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</None>
22+
<None Update="Day02.txt">
23+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24+
</None>
1925
</ItemGroup>
2026

2127
</Project>
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
namespace helloserve.com.AdventOfCode;
22
public abstract class Base
33
{
4-
public T[] ReadInput<T>(string filename, Func<string, T> parseLine)
4+
public abstract string Filename { get; set; }
5+
6+
public T[] ReadMultiLineInput<T>(string filename, Func<string, T> parseLine)
57
{
68
var allText = File.ReadAllText(filename);
79
return allText.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
810
.Select(o => parseLine(o))
911
.ToArray();
1012
}
1113

12-
public abstract string Part1(string filename);
13-
public abstract string Part2(string filename);
14+
public T[] ReadSingleLineInput<T>(string filename, Func<string, T> parseValue, char separator = ',')
15+
{
16+
var allText = File.ReadAllText(filename);
17+
return allText.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries)
18+
.Select(o => parseValue(o))
19+
.ToArray();
20+
}
21+
22+
public abstract string Part1();
23+
public abstract string Part2();
1424
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Validating benchmarks:
2+
// * Assembly helloserve.com.AdventOfCode which defines benchmarks is non-optimized
3+
Benchmark was built without optimization enabled (most probably a DEBUG configuration). Please, build it in RELEASE.
4+
If you want to debug the benchmarks, please see https://benchmarkdotnet.org/articles/guides/troubleshooting.html#debugging-benchmarks.
5+

0 commit comments

Comments
 (0)