generated from Templates/Dotnet_Library
feat: initial implementation of input provider, ref: A24-7
This commit is contained in:
parent
d2b1d4bcfa
commit
d15b0b65da
16
LevelInputProvider.Tests/LevelInputProviderTest.cs
Normal file
16
LevelInputProvider.Tests/LevelInputProviderTest.cs
Normal 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]);
|
||||||
|
}
|
||||||
|
}
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -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}!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
35
LevelInputProvider/LevelInputProvider.cs
Normal file
35
LevelInputProvider/LevelInputProvider.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -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>
|
||||||
|
1000
LevelInputProvider/inputs/2024/1/input.txt
Normal file
1000
LevelInputProvider/inputs/2024/1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
1000
LevelInputProvider/inputs/2024/2/input.txt
Normal file
1000
LevelInputProvider/inputs/2024/2/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
2
Makefile
2
Makefile
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user