Skip to content

Commit

Permalink
day 3
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszzborek committed Dec 3, 2023
1 parent 0c70269 commit 506e2ba
Show file tree
Hide file tree
Showing 16 changed files with 1,807 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,5 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

.idea/
30 changes: 30 additions & 0 deletions AdventOfCode.Tests/AdventOfCode.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="Shouldly" Version="4.2.1"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AdventOfCode\AdventOfCode.csproj"/>
</ItemGroup>

</Project>
138 changes: 138 additions & 0 deletions AdventOfCode.Tests/DayTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using Shouldly;
using Xunit;

namespace AdventOfCode.Tests;

public class DayTests
{
[Fact]
public void Day01_01_Test1()
{
var strList = string.Join("\r\n", new List<string>
{
"1abc2",
"pqr3stu8vwx",
"a1b2c3d4e5f",
"treb7uchet"
});

var day = new Day01();
day.IsTest = true;
day.TestInput = strList;
var result = day.Solve_1()
.Result;
result.ShouldBe("142");
}

[Fact]
public void Day01_02_Test1()
{
var strList = string.Join("\r\n", new List<string>
{
"two1nine",
"eightwothree",
"abcone2threexyz",
"xtwone3four",
"4nineeightseven2",
"zoneight234",
"7pqrstsixteen"
});

var day = new Day01();
day.IsTest = true;
day.TestInput = strList;
var result = day.Solve_2()
.Result;
result.ShouldBe("281");
}

[Fact]
public void Day02_01_Test1()
{
var strList = string.Join("\r\n", new List<string>
{
"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green",
"Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue",
"Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red",
"Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red",
"Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"
});

var day = new Day02();
day.IsTest = true;
day.TestInput = strList;
var result = day.Solve_1()
.Result;
result.ShouldBe("8");
}

[Fact]
public void Day02_02_Test1()
{
var strList = string.Join("\r\n", new List<string>
{
"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green",
"Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue",
"Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red",
"Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red",
"Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"
});

var day = new Day02();
day.IsTest = true;
day.TestInput = strList;
var result = day.Solve_2()
.Result;
result.ShouldBe("2286");
}

[Fact]
public void Day03_01_Test1()
{
var strList = string.Join("\r\n", new List<string>
{
"467..114..",
"...*......",
"..35..633.",
"......#...",
"617*......",
".....+.58.",
"..592.....",
"......755.",
"...$.*....",
".664.598.."
});

var day = new Day03();
day.IsTest = true;
day.TestInput = strList;
var result = day.Solve_1()
.Result;
result.ShouldBe("4361");
}

[Fact]
public void Day03_02_Test1()
{
var strList = string.Join("\r\n", new List<string>
{
"467..114..",
"...*......",
"..35..633.",
"......#...",
"617*......",
".....+.58.",
"..592.....",
"......755.",
"...$.*....",
".664.598.."
});

var day = new Day03();
day.IsTest = true;
day.TestInput = strList;
var result = day.Solve_2()
.Result;
result.ShouldBe("467835");
}
}
14 changes: 14 additions & 0 deletions AdventOfCode.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdventOfCode", "AdventOfCod
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FBE09BBA-34E4-4DED-94F2-44217330E37F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode.Tests", "AdventOfCode.Tests\AdventOfCode.Tests.csproj", "{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -29,6 +31,18 @@ Global
{6B01383F-FF08-4839-BF44-2DE9071CCC37}.Release|x64.Build.0 = Release|Any CPU
{6B01383F-FF08-4839-BF44-2DE9071CCC37}.Release|x86.ActiveCfg = Release|Any CPU
{6B01383F-FF08-4839-BF44-2DE9071CCC37}.Release|x86.Build.0 = Release|Any CPU
{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}.Debug|x64.ActiveCfg = Debug|Any CPU
{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}.Debug|x64.Build.0 = Debug|Any CPU
{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}.Debug|x86.ActiveCfg = Debug|Any CPU
{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}.Debug|x86.Build.0 = Debug|Any CPU
{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}.Release|Any CPU.Build.0 = Release|Any CPU
{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}.Release|x64.ActiveCfg = Release|Any CPU
{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}.Release|x64.Build.0 = Release|Any CPU
{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}.Release|x86.ActiveCfg = Release|Any CPU
{1A2DED5C-1CF2-4A2B-9B35-92EE53F683D8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
34 changes: 18 additions & 16 deletions AdventOfCode/AdventOfCode.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AoCHelper" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AoCHelper" Version="3.0.0"/>
</ItemGroup>

<PropertyGroup>
<NoWarn>S101</NoWarn>
</PropertyGroup>
<PropertyGroup>
<NoWarn>S101</NoWarn>
</PropertyGroup>

<ItemGroup>
<None Update="Inputs\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="Inputs\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Inputs\03.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions AdventOfCode/Core/BetterBaseDay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.IO;
using AoCHelper;

namespace AdventOfCode.Core;

public abstract class BetterBaseDay : BaseDay
{
public bool IsTest { get; set; } = false;
public string TestInput { get; set; }
protected string InputData => GetData();

private string GetData()
{
return IsTest ? TestInput : File.ReadAllText(InputFilePath);
}
}
Loading

0 comments on commit 506e2ba

Please sign in to comment.