Skip to content
Snippets Groups Projects
Commit 5812bc40 authored by Horváth Zoltán's avatar Horváth Zoltán
Browse files

Added test to Day2

parent 8b5b3a6f
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AoC2", "AoC2", "{79F9A7C9-3 ...@@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AoC2", "AoC2", "{79F9A7C9-3
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2", "AoC2\AoC2\AoC2.csproj", "{AD8879E5-3089-4B71-8362-3FC26E23242A}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2", "AoC2\AoC2\AoC2.csproj", "{AD8879E5-3089-4B71-8362-3FC26E23242A}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2Test", "AoC2\AoC2Test\AoC2Test.csproj", "{66C828CF-6E1D-4C99-A967-216911D0FF0D}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
...@@ -28,9 +30,14 @@ Global ...@@ -28,9 +30,14 @@ Global
{AD8879E5-3089-4B71-8362-3FC26E23242A}.Debug|Any CPU.Build.0 = Debug|Any CPU {AD8879E5-3089-4B71-8362-3FC26E23242A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD8879E5-3089-4B71-8362-3FC26E23242A}.Release|Any CPU.ActiveCfg = Release|Any CPU {AD8879E5-3089-4B71-8362-3FC26E23242A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD8879E5-3089-4B71-8362-3FC26E23242A}.Release|Any CPU.Build.0 = Release|Any CPU {AD8879E5-3089-4B71-8362-3FC26E23242A}.Release|Any CPU.Build.0 = Release|Any CPU
{66C828CF-6E1D-4C99-A967-216911D0FF0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{66C828CF-6E1D-4C99-A967-216911D0FF0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66C828CF-6E1D-4C99-A967-216911D0FF0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66C828CF-6E1D-4C99-A967-216911D0FF0D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution GlobalSection(NestedProjects) = preSolution
{06B4648E-79A0-4C94-926D-CEBF46E1155B} = {A56EF563-B7A2-484C-999F-BB48F1FFCCAF} {06B4648E-79A0-4C94-926D-CEBF46E1155B} = {A56EF563-B7A2-484C-999F-BB48F1FFCCAF}
{AD8879E5-3089-4B71-8362-3FC26E23242A} = {79F9A7C9-3CEE-4A0C-8F55-4E8A0D44AF79} {AD8879E5-3089-4B71-8362-3FC26E23242A} = {79F9A7C9-3CEE-4A0C-8F55-4E8A0D44AF79}
{66C828CF-6E1D-4C99-A967-216911D0FF0D} = {79F9A7C9-3CEE-4A0C-8F55-4E8A0D44AF79}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2", "AoC2\AoC2.csproj", "{4DF86EDF-0EC4-4A64-A010-80D16BA62089}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2", "AoC2\AoC2.csproj", "{4DF86EDF-0EC4-4A64-A010-80D16BA62089}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2Test", "AoC2Test\AoC2Test.csproj", "{DE0D9B80-3857-4F38-A9AD-4168CD633F6F}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
...@@ -12,5 +14,9 @@ Global ...@@ -12,5 +14,9 @@ Global
{4DF86EDF-0EC4-4A64-A010-80D16BA62089}.Debug|Any CPU.Build.0 = Debug|Any CPU {4DF86EDF-0EC4-4A64-A010-80D16BA62089}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4DF86EDF-0EC4-4A64-A010-80D16BA62089}.Release|Any CPU.ActiveCfg = Release|Any CPU {4DF86EDF-0EC4-4A64-A010-80D16BA62089}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4DF86EDF-0EC4-4A64-A010-80D16BA62089}.Release|Any CPU.Build.0 = Release|Any CPU {4DF86EDF-0EC4-4A64-A010-80D16BA62089}.Release|Any CPU.Build.0 = Release|Any CPU
{DE0D9B80-3857-4F38-A9AD-4168CD633F6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE0D9B80-3857-4F38-A9AD-4168CD633F6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE0D9B80-3857-4F38-A9AD-4168CD633F6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE0D9B80-3857-4F38-A9AD-4168CD633F6F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal
namespace AoC2; namespace AoC2;
internal readonly record struct Bag(int Red, int Green, int Blue); public readonly record struct Bag(int Red, int Green, int Blue);
internal class Game public class Game
{ {
// Max amount for each // Max amount for each
private readonly int _red; private readonly int _red;
...@@ -12,7 +12,7 @@ internal class Game ...@@ -12,7 +12,7 @@ internal class Game
public int Id { get; } public int Id { get; }
public int PowerOfCubes => _red * _green * _blue; public int PowerOfCubes => _red * _green * _blue;
internal Game(string line) public Game(string line)
{ {
Id = int.Parse(line.Split(":")[0].Split(" ")[1]); Id = int.Parse(line.Split(":")[0].Split(" ")[1]);
...@@ -32,7 +32,7 @@ internal class Game ...@@ -32,7 +32,7 @@ internal class Game
public bool PossibleWithBag(in Bag bag) => bag.Red >= _red && bag.Green >= _green && bag.Blue >= _blue; public bool PossibleWithBag(in Bag bag) => bag.Red >= _red && bag.Green >= _green && bag.Blue >= _blue;
} }
internal static class Program public static class Program
{ {
public static void Main() public static void Main()
{ {
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/>
<PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AoC2\AoC2.csproj" />
</ItemGroup>
</Project>
using System.Collections.Generic;
using System.Linq;
using AoC2;
using Xunit;
namespace AoC2Test;
// Tests should not be written like this... Maybe next day
// For now, good enough to test CI
public class Tests
{
private const string input = @"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";
private readonly Bag _bag;
private readonly IEnumerable<Game> _games;
public Tests()
{
_bag = new Bag(12, 13, 14);
_games = input.Split("\n")
.Select(line => new Game(line));
}
[Fact]
public void Day2Part1_Examples_Pass()
{
var sum = _games.Where(game => game.PossibleWithBag(_bag))
.Sum(game => game.Id);
Assert.Equal(8, sum);
}
[Fact]
public void Day2Part2_Examples_Pass()
{
long power = _games.Sum(game => game.PowerOfCubes);
Assert.Equal(2286, power);
}
}
\ No newline at end of file
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
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment