Added test project and started adding Days to it.
This commit is contained in:
parent
45ccaf5c22
commit
59d50bfd5b
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,6 @@
|
|||||||
AOC2021/bin
|
AOC2021/bin
|
||||||
AOC2021/obj
|
AOC2021/obj
|
||||||
.vs
|
.vs
|
||||||
|
AOC2021.Test/bin/
|
||||||
|
packages/
|
||||||
|
AOC2021.Test/obj/
|
||||||
|
35
AOC2021.Test/AOC2021.Test.csproj
Normal file
35
AOC2021.Test/AOC2021.Test.csproj
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.0.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AOC2021\AOC2021.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="Input\Day1_input.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Input\Day1_test.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Input\Day2_input.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Input\Day2_test.txt">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
69
AOC2021.Test/AOCTester.cs
Normal file
69
AOC2021.Test/AOCTester.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
using AOC2021.Models;
|
||||||
|
using AOC2021.Tests.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AOC2021.Test
|
||||||
|
{
|
||||||
|
public class AOCTester
|
||||||
|
{
|
||||||
|
public TestResponse Test(TestRequest request)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Testing " + request.Day);
|
||||||
|
var response = new TestResponse() { Answer = new Models.Answer() };
|
||||||
|
var day = GetAOCDay(request.Day);
|
||||||
|
|
||||||
|
var test = GetTextInput(request.Day, "test");
|
||||||
|
var input = GetTextInput(request.Day, "input");
|
||||||
|
|
||||||
|
Console.WriteLine($"Testing {request.Day} Part A, Test data");
|
||||||
|
if (!string.IsNullOrEmpty(request.Answer.Day_A_Test))
|
||||||
|
response.Answer.Day_A_Test = day.ExecuteDay(new AOCRequest() { Input = test, Version = AOCVersion.A }).Answer;
|
||||||
|
Console.WriteLine($"Testing {request.Day} Part A, Input data");
|
||||||
|
if (!string.IsNullOrEmpty(request.Answer.Day_A_Input))
|
||||||
|
response.Answer.Day_A_Input = day.ExecuteDay(new AOCRequest() { Input = input, Version = AOCVersion.A }).Answer;
|
||||||
|
|
||||||
|
Console.WriteLine($"Testing {request.Day} Part B, Test data");
|
||||||
|
if (!string.IsNullOrEmpty(request.Answer.Day_B_Test))
|
||||||
|
response.Answer.Day_B_Test = day.ExecuteDay(new AOCRequest() { Input = test, Version = AOCVersion.B }).Answer;
|
||||||
|
Console.WriteLine($"Testing {request.Day} Part B, Input data");
|
||||||
|
if (!string.IsNullOrEmpty(request.Answer.Day_B_Input))
|
||||||
|
response.Answer.Day_B_Input = day.ExecuteDay(new AOCRequest() { Input = input, Version = AOCVersion.B }).Answer;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AOCDay GetAOCDay(string route)
|
||||||
|
{
|
||||||
|
AOCDay day = null;
|
||||||
|
var type = typeof(AOCDay);
|
||||||
|
var types = AppDomain.CurrentDomain.GetAssemblies()
|
||||||
|
.SelectMany(s => s.GetTypes())
|
||||||
|
.Where(p => type.IsAssignableFrom(p) && !p.IsInterface && !p.IsAbstract);
|
||||||
|
foreach (var x in types)
|
||||||
|
{
|
||||||
|
if (x.Name.ToLower() == route.ToLower())
|
||||||
|
{
|
||||||
|
day = (AOCDay)(IAOCService)Activator.CreateInstance(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (AOCDay)day;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetTextInput(string day, string type)
|
||||||
|
{
|
||||||
|
foreach (var file in Directory.GetFiles("Input"))
|
||||||
|
{
|
||||||
|
var constructedFileName = $"Input\\{day}_{type}.txt";
|
||||||
|
if (file.ToLower().Equals(constructedFileName.ToLower()))
|
||||||
|
{
|
||||||
|
return File.ReadAllText(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
AOC2021.Test/DayTest.cs
Normal file
34
AOC2021.Test/DayTest.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using AOC2021.Test;
|
||||||
|
using AOC2021.Tests.Models;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using AOC2021.Models;
|
||||||
|
using AOC2021.Test.Models;
|
||||||
|
|
||||||
|
namespace AOC2021.Tests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class DayTest
|
||||||
|
{
|
||||||
|
private AOCTester _tester;
|
||||||
|
public DayTest()
|
||||||
|
{
|
||||||
|
_tester = new AOCTester();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Day1()
|
||||||
|
{
|
||||||
|
var request = new TestRequest() { Day = "day1", Answer = new Answer() { Day_A_Test = "7", Day_A_Input = "1759", Day_B_Test = "5", Day_B_Input = "1805" } };
|
||||||
|
var result = _tester.Test(request);
|
||||||
|
Assert.IsTrue(request.Answer.Equals(result.Answer));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Day2()
|
||||||
|
{
|
||||||
|
var request = new TestRequest() { Day = "day2", Answer = new Answer() { Day_A_Test = "150", Day_A_Input = "1762050", Day_B_Test = "900", Day_B_Input = "1855892637" } };
|
||||||
|
var result = _tester.Test(request);
|
||||||
|
Assert.IsTrue(request.Answer.Equals(result.Answer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2000
AOC2021.Test/Input/Day1_input.txt
Normal file
2000
AOC2021.Test/Input/Day1_input.txt
Normal file
File diff suppressed because it is too large
Load Diff
10
AOC2021.Test/Input/Day1_test.txt
Normal file
10
AOC2021.Test/Input/Day1_test.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
199
|
||||||
|
200
|
||||||
|
208
|
||||||
|
210
|
||||||
|
200
|
||||||
|
207
|
||||||
|
240
|
||||||
|
269
|
||||||
|
260
|
||||||
|
263
|
2000
AOC2021.Test/Input/Day2_input.txt
Normal file
2000
AOC2021.Test/Input/Day2_input.txt
Normal file
File diff suppressed because it is too large
Load Diff
6
AOC2021.Test/Input/Day2_test.txt
Normal file
6
AOC2021.Test/Input/Day2_test.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
forward 5
|
||||||
|
down 5
|
||||||
|
forward 8
|
||||||
|
up 3
|
||||||
|
down 8
|
||||||
|
forward 2
|
43
AOC2021.Test/Models/Answer.cs
Normal file
43
AOC2021.Test/Models/Answer.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace AOC2021.Test.Models
|
||||||
|
{
|
||||||
|
public class Answer
|
||||||
|
{
|
||||||
|
|
||||||
|
public string Day_A_Test { get; set; }
|
||||||
|
public string Day_A_Input { get; set; }
|
||||||
|
public string Day_B_Test { get; set; }
|
||||||
|
public string Day_B_Input { get; set; }
|
||||||
|
|
||||||
|
public override bool Equals(Object obj)
|
||||||
|
{
|
||||||
|
//Check for null and compare run-time types.
|
||||||
|
if ((obj == null) || !this.GetType().Equals(obj.GetType()))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Answer a = (Answer)obj;
|
||||||
|
string failedAnswer = string.Empty;
|
||||||
|
if (!Day_A_Input.Equals(a.Day_A_Input))
|
||||||
|
failedAnswer = $"Failed Day A Input ({Day_A_Input}) vs ({a.Day_A_Input})";
|
||||||
|
if (!Day_A_Test.Equals(a.Day_A_Test))
|
||||||
|
failedAnswer = $"Failed Day A Test ({Day_A_Test}) vs ({a.Day_A_Test})";
|
||||||
|
|
||||||
|
if (!Day_B_Input.Equals(a.Day_B_Input))
|
||||||
|
failedAnswer = $"Failed Day B Input ({Day_B_Input}) vs ({a.Day_B_Input})";
|
||||||
|
if (!Day_B_Test.Equals(a.Day_B_Test))
|
||||||
|
failedAnswer = $"Failed Day B Test ({Day_B_Test}) vs ({a.Day_B_Test})";
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(failedAnswer))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Console.WriteLine(failedAnswer);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
AOC2021.Test/Models/TestRequest.cs
Normal file
12
AOC2021.Test/Models/TestRequest.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using AOC2021.Models;
|
||||||
|
using AOC2021.Test.Models;
|
||||||
|
|
||||||
|
namespace AOC2021.Tests.Models
|
||||||
|
{
|
||||||
|
public class TestRequest
|
||||||
|
{
|
||||||
|
public Answer Answer { get; set; }
|
||||||
|
public AOCVersion Version { get; set; }
|
||||||
|
public string Day { get; set; }
|
||||||
|
}
|
||||||
|
}
|
13
AOC2021.Test/Models/TestResponse.cs
Normal file
13
AOC2021.Test/Models/TestResponse.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
|
||||||
|
using AOC2021.Models;
|
||||||
|
using AOC2021.Test.Models;
|
||||||
|
|
||||||
|
namespace AOC2021.Tests.Models
|
||||||
|
{
|
||||||
|
public class TestResponse
|
||||||
|
{
|
||||||
|
public AOCVersion Version { get; set; }
|
||||||
|
public Answer Answer { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 16
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 16.0.31515.178
|
VisualStudioVersion = 16.0.31515.178
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOC2021", "AOC2021\AOC2021.csproj", "{1C97C7BD-E112-4CC4-B870-BCEE6146C707}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AOC2021", "AOC2021\AOC2021.csproj", "{1C97C7BD-E112-4CC4-B870-BCEE6146C707}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOC2021.Test", "AOC2021.Test\AOC2021.Test.csproj", "{00B6E578-8E4E-4722-A601-A8CEE90704E1}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -15,6 +17,10 @@ Global
|
|||||||
{1C97C7BD-E112-4CC4-B870-BCEE6146C707}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{1C97C7BD-E112-4CC4-B870-BCEE6146C707}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{1C97C7BD-E112-4CC4-B870-BCEE6146C707}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{1C97C7BD-E112-4CC4-B870-BCEE6146C707}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{1C97C7BD-E112-4CC4-B870-BCEE6146C707}.Release|Any CPU.Build.0 = Release|Any CPU
|
{1C97C7BD-E112-4CC4-B870-BCEE6146C707}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{00B6E578-8E4E-4722-A601-A8CEE90704E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{00B6E578-8E4E-4722-A601-A8CEE90704E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{00B6E578-8E4E-4722-A601-A8CEE90704E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{00B6E578-8E4E-4722-A601-A8CEE90704E1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -19,7 +19,9 @@ namespace AOC2021.Controllers
|
|||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Consumes("text/plain")]
|
[Consumes("text/plain")]
|
||||||
[Route("day1")][Route("day2")]
|
[Route("day1")]
|
||||||
|
[Route("day2")]
|
||||||
|
[Route("day3")]
|
||||||
public AOCResponse Day(AOCVersion version, [FromBody] string input, bool IgnoreLogMessages = false)
|
public AOCResponse Day(AOCVersion version, [FromBody] string input, bool IgnoreLogMessages = false)
|
||||||
{
|
{
|
||||||
AOCRequest request = new AOCRequest() { Input = input, Version = version, IgnoreLogMessages = IgnoreLogMessages };
|
AOCRequest request = new AOCRequest() { Input = input, Version = version, IgnoreLogMessages = IgnoreLogMessages };
|
||||||
|
@ -11,7 +11,7 @@ namespace AOC2021.Days
|
|||||||
{
|
{
|
||||||
protected override AOCResponse ExecutePartA()
|
protected override AOCResponse ExecutePartA()
|
||||||
{
|
{
|
||||||
var input = this._request.Input.Split("\n");
|
var input = GetSplitInput();
|
||||||
int increase = 0;
|
int increase = 0;
|
||||||
for (int i = 0; i < input.Length-1; i++)
|
for (int i = 0; i < input.Length-1; i++)
|
||||||
{
|
{
|
||||||
@ -22,7 +22,6 @@ namespace AOC2021.Days
|
|||||||
increase++;
|
increase++;
|
||||||
Log("Increase");
|
Log("Increase");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
this._response.Answer = increase.ToString();
|
this._response.Answer = increase.ToString();
|
||||||
return this._response;
|
return this._response;
|
||||||
@ -30,7 +29,7 @@ namespace AOC2021.Days
|
|||||||
|
|
||||||
protected override AOCResponse ExecutePartB()
|
protected override AOCResponse ExecutePartB()
|
||||||
{
|
{
|
||||||
var input = this._request.Input.Split("\n");
|
var input = GetSplitInput();
|
||||||
var list = new List<int>();
|
var list = new List<int>();
|
||||||
for (int i = 0; i < input.Length-2; i++)
|
for (int i = 0; i < input.Length-2; i++)
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
namespace AOC2021.Days
|
using AOC2021.Models;
|
||||||
|
|
||||||
|
namespace AOC2021.Days
|
||||||
{
|
{
|
||||||
public class Day3
|
public class Day3 : AOCDay
|
||||||
{
|
{
|
||||||
|
protected override AOCResponse ExecutePartA()
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override AOCResponse ExecutePartB()
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ namespace AOC2021.Models
|
|||||||
|
|
||||||
protected void Log(string message, params object[] args)
|
protected void Log(string message, params object[] args)
|
||||||
{
|
{
|
||||||
if (!this._request.IgnoreLogMessages)
|
if (_logger != null && !this._request.IgnoreLogMessages)
|
||||||
_logger.LogInformation(message, args);
|
_logger.LogInformation(message, args);
|
||||||
_debugMessages.Add(string.Format(message, args));
|
_debugMessages.Add(string.Format(message, args));
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,10 @@
|
|||||||
using AOC2021.Helper;
|
using AOC2021.Helper;
|
||||||
using AOC2021.Models;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.HttpsPolicy;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AOC2021
|
namespace AOC2021
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user