feat: initial implementation of input provider, ref: A24-7
All checks were successful
CI / linter (9.0.X, ubuntu-latest) (push) Successful in 2m7s
SonarQube Scan / SonarQube Trigger (push) Successful in 2m7s
CI / tests_linux (9.0.X, ubuntu-latest) (push) Successful in 1m37s

This commit is contained in:
Simon Diesenreiter 2024-12-02 12:54:35 +01:00
parent d2b1d4bcfa
commit d15b0b65da
8 changed files with 2063 additions and 31 deletions

View File

@ -0,0 +1,16 @@
namespace AoCLevelInputProvider.Tests;
using AoCLevelInputProvider;
public class LevelInputProviderTest
{
[Fact]
public void Test1()
{
var lip = new LevelInputProvider();
string text = lip.WithYear(2024).WithLevel(1).Provide();
var lines = text.Split("\n");
Assert.Equal("39472 15292", lines[0]);
Assert.Equal("18560 15292", lines[999]);
}
}

View File

@ -1,14 +0,0 @@
namespace LevelInputProvider.Tests;
using LevelInputProvider;
public class UnitTest1
{
[Fact]
public void Test1()
{
var hwp = new HelloWorldProvider();
Assert.Equal("Hello, Simon!", hwp.GetHelloWorld("Simon"));
Assert.Equal("Hello world!", hwp.GetHelloWorld());
}
}

View File

@ -1,16 +0,0 @@
namespace LevelInputProvider;
public class HelloWorldProvider
{
public string GetHelloWorld(string? name = null)
{
if (string.IsNullOrEmpty(name))
{
return "Hello world!";
}
else
{
return $"Hello, {name}!";
}
}
}

View File

@ -0,0 +1,35 @@
namespace AoCLevelInputProvider;
using System.Reflection;
public class LevelInputProvider
{
private const string levelFilePathTemplate = "inputs/{0}/{1}/input.txt";
private int year;
private int level;
public LevelInputProvider()
{
this.year = 2024;
this.level = 1;
}
public LevelInputProvider WithYear(int year)
{
this.year = year;
return this;
}
public LevelInputProvider WithLevel(int level)
{
this.level = level;
return this;
}
public string Provide()
{
var basePath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(LevelInputProvider)).Location);
var textPath = Path.Combine(basePath, string.Format(levelFilePathTemplate, this.year, this.level));
return File.ReadAllText(textPath);
}
}

View File

@ -6,4 +6,15 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Content Include="inputs/**/*.*">
<Pack>true</Pack>
<IncludeInPackage>true</IncludeInPackage>
<PackageCopyToOutput>true</PackageCopyToOutput>
<CopyToOutput>true</CopyToOutput>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
</Content>
</ItemGroup>
</Project> </Project>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
.PHONY: issetup .PHONY: issetup
issetup: issetup:
@[ -f .git/hooks/commit-msg ] || [ -v SKIP_MAKE_SETUP_CHECK ] || (echo "You must run 'make setup' first to initialize the repo!" && exit 1) @[ -f .git/hooks/commit-msg ] || [ -n SKIP_MAKE_SETUP_CHECK ] || (echo "You must run 'make setup' first to initialize the repo!" && exit 1)
.PHONY: setup .PHONY: setup
setup: setup: