chore(*): Add day creation tool

This commit is contained in:
Josh Creek
2022-10-13 09:25:24 +01:00
parent 75671d13e1
commit e2a3f2417a
5 changed files with 101 additions and 0 deletions
+6
View File
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.3.32922.545
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AOC.Tests", "AOC.Tests\AOC.Tests.csproj", "{2E0193E1-5DD3-40A6-A07B-C6E58341ACA0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DayCreator", "DayCreator\DayCreator.csproj", "{BBA91797-9C84-4A8D-9C12-9AE4D3C3EF83}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
{2E0193E1-5DD3-40A6-A07B-C6E58341ACA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E0193E1-5DD3-40A6-A07B-C6E58341ACA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E0193E1-5DD3-40A6-A07B-C6E58341ACA0}.Release|Any CPU.Build.0 = Release|Any CPU
{BBA91797-9C84-4A8D-9C12-9AE4D3C3EF83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBA91797-9C84-4A8D-9C12-9AE4D3C3EF83}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBA91797-9C84-4A8D-9C12-9AE4D3C3EF83}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBA91797-9C84-4A8D-9C12-9AE4D3C3EF83}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+20
View File
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="DayX.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="DayX.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
+45
View File
@@ -0,0 +1,45 @@
using System.Reflection;
namespace AOC.Tests.YX
{
[TestFixture, Parallelizable(ParallelScope.All)]
public class DayX
{
protected string GetThisClassName() { return this.GetType().Name; }
private string[] realData;
[SetUp]
public void Setup()
{
realData = File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "YX", "Data", $"{GetThisClassName()}.dat"));
}
[TestCase("blah", 0)]
[TestCase(null, 232)] // The actual answer
public void Part1(string input, int? expected)
{
string[] lines = input != null ? new[] { input } : realData;
//if (expected != null)
//{
// Assert.That(result, Is.EqualTo(expected.Value));
//}
//Console.WriteLine($"Part 1: {result}");
}
[TestCase("blah", 1)]
[TestCase(null, 1783)] // The actual answer
public void Part2(string input, int? expected)
{
//string[] lines = input != null ? new[] { input } : realData;
//if (expected != null)
//{
// Assert.That(result, Is.EqualTo(expected.Value));
//}
//Console.WriteLine($"Part 2: {result}");
}
}
}
+30
View File
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System;
using System.IO;
using System.Text;
Console.Write("Year: ");
var year = Console.ReadLine();
Console.Write("Day: ");
var day = Console.ReadLine().PadLeft(2, '0'); ;
var currentLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
int ix = currentLocation.IndexOf("DayCreator");
var newPathBase = currentLocation.Substring(0, ix - 1);
string yearPath = Path.GetFullPath(Path.Combine(newPathBase, $@"AOC.Tests\Y{year}\"));
string dataPath = Path.GetFullPath(Path.Combine(yearPath, $@"Data\"));
string tasksPath = Path.GetFullPath(Path.Combine(yearPath, $@"Tasks\"));
// Create data file
using (FileStream fs = File.Create($"{dataPath}Day{day}.dat"));
// Create task file
using (FileStream fs = File.Create($"{tasksPath}Day{day}.txt"));
// Create code file
string text = File.ReadAllText("DayX.cs");
text = text.Replace("YX", $"Y{year}");
text = text.Replace("DayX", $"Day{day}");
File.WriteAllText($"{yearPath}Day{day}.cs", text);