From 5812bc408aead0d394f33bd8d64f463800d751f9 Mon Sep 17 00:00:00 2001
From: zoleee <zoleee@sch.bme.hu>
Date: Sat, 2 Dec 2023 20:28:32 +0100
Subject: [PATCH] Added test to Day2

---
 AoC.sln                       |  7 ++++++
 AoC2/AoC2.sln                 |  6 +++++
 AoC2/AoC2/Program.cs          |  8 +++----
 AoC2/AoC2Test/AoC2Test.csproj | 27 ++++++++++++++++++++++
 AoC2/AoC2Test/Tests.cs        | 43 +++++++++++++++++++++++++++++++++++
 AoC2/AoC2Test/input.txt       |  5 ++++
 6 files changed, 92 insertions(+), 4 deletions(-)
 create mode 100644 AoC2/AoC2Test/AoC2Test.csproj
 create mode 100644 AoC2/AoC2Test/Tests.cs
 create mode 100644 AoC2/AoC2Test/input.txt

diff --git a/AoC.sln b/AoC.sln
index 1567efa..3a8e8e2 100644
--- a/AoC.sln
+++ b/AoC.sln
@@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AoC2", "AoC2", "{79F9A7C9-3
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2", "AoC2\AoC2\AoC2.csproj", "{AD8879E5-3089-4B71-8362-3FC26E23242A}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2Test", "AoC2\AoC2Test\AoC2Test.csproj", "{66C828CF-6E1D-4C99-A967-216911D0FF0D}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -28,9 +30,14 @@ Global
 		{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.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
 	GlobalSection(NestedProjects) = preSolution
 		{06B4648E-79A0-4C94-926D-CEBF46E1155B} = {A56EF563-B7A2-484C-999F-BB48F1FFCCAF}
 		{AD8879E5-3089-4B71-8362-3FC26E23242A} = {79F9A7C9-3CEE-4A0C-8F55-4E8A0D44AF79}
+		{66C828CF-6E1D-4C99-A967-216911D0FF0D} = {79F9A7C9-3CEE-4A0C-8F55-4E8A0D44AF79}
 	EndGlobalSection
 EndGlobal
diff --git a/AoC2/AoC2.sln b/AoC2/AoC2.sln
index e0c823b..a95423d 100644
--- a/AoC2/AoC2.sln
+++ b/AoC2/AoC2.sln
@@ -2,6 +2,8 @@
 Microsoft Visual Studio Solution File, Format Version 12.00
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2", "AoC2\AoC2.csproj", "{4DF86EDF-0EC4-4A64-A010-80D16BA62089}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AoC2Test", "AoC2Test\AoC2Test.csproj", "{DE0D9B80-3857-4F38-A9AD-4168CD633F6F}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -12,5 +14,9 @@ Global
 		{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.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
 EndGlobal
diff --git a/AoC2/AoC2/Program.cs b/AoC2/AoC2/Program.cs
index 33e3524..c7da39a 100644
--- a/AoC2/AoC2/Program.cs
+++ b/AoC2/AoC2/Program.cs
@@ -1,8 +1,8 @@
 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
     private readonly int _red;
@@ -12,7 +12,7 @@ internal class Game
     public int Id { get; }
     public int PowerOfCubes => _red * _green * _blue;
 
-    internal Game(string line)
+    public Game(string line)
     {
         Id = int.Parse(line.Split(":")[0].Split(" ")[1]);
         
@@ -32,7 +32,7 @@ internal class Game
     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()
     {
diff --git a/AoC2/AoC2Test/AoC2Test.csproj b/AoC2/AoC2Test/AoC2Test.csproj
new file mode 100644
index 0000000..24f9b22
--- /dev/null
+++ b/AoC2/AoC2Test/AoC2Test.csproj
@@ -0,0 +1,27 @@
+<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>
diff --git a/AoC2/AoC2Test/Tests.cs b/AoC2/AoC2Test/Tests.cs
new file mode 100644
index 0000000..5941e2f
--- /dev/null
+++ b/AoC2/AoC2Test/Tests.cs
@@ -0,0 +1,43 @@
+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
diff --git a/AoC2/AoC2Test/input.txt b/AoC2/AoC2Test/input.txt
new file mode 100644
index 0000000..1cd7d33
--- /dev/null
+++ b/AoC2/AoC2Test/input.txt
@@ -0,0 +1,5 @@
+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
-- 
GitLab