feat: solved day one puzzle
This commit is contained in:
@@ -1 +1,2 @@
|
||||
global using Xunit;
|
||||
global using Xunit;
|
||||
global using FluentAssertions;
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace Trebuchet.Tests;
|
||||
|
||||
public class PartOnePuzzleSolverTests
|
||||
{
|
||||
private readonly PartOnePuzzleSolver _sut = new();
|
||||
|
||||
[Theory]
|
||||
[InlineData("1abc2", 12)]
|
||||
[InlineData("pqr3stu8vwx", 38)]
|
||||
[InlineData("a1b2c3d4e5f", 15)]
|
||||
[InlineData("treb7uchet", 77)]
|
||||
public void GetCalibrationValue_GivenAStringContainingDigits_ItShouldReturnSumOrFirstAndLastDigit(string input, int expected)
|
||||
{
|
||||
var result = _sut.GetCalibrationValue(input);
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(new string[] { "1abc2", "pqr3stu8vwx", "a1b2c3d4e5f", "treb7uchet" }, 142)]
|
||||
public void SumCalibrationValues_GivenAnArrayOfStrings_ItShouldReturnTheSumOfAllCalibrationValues(string[] input, int expected)
|
||||
{
|
||||
var result = _sut.SumCalibrationValues(input);
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SumCalibrationValues_GivenAFile_ItShouldReturnTheSumOfAllCalibrationValues()
|
||||
{
|
||||
var input = await File.ReadAllLinesAsync("INPUT.txt");
|
||||
var result = _sut.SumCalibrationValues(input);
|
||||
result.Should().Be(53194);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
namespace Trebuchet.Tests;
|
||||
|
||||
public class PartTwoPuzzleSolverTests
|
||||
{
|
||||
private readonly PartTwoPuzzleSolver _sut = new();
|
||||
|
||||
[Theory]
|
||||
[InlineData("two1nine", 29)]
|
||||
[InlineData("eightwothree", 83)]
|
||||
[InlineData("abcone2threexyz", 13)]
|
||||
[InlineData("xtwone3four", 24)]
|
||||
[InlineData("4nineeightseven2", 42)]
|
||||
[InlineData("zoneight234", 14)]
|
||||
[InlineData("7pqrstsixteen", 76)]
|
||||
[InlineData("99seven3vdcgvmvxtjtwodc5", 95)]
|
||||
[InlineData("gpmfhninexxgqr6", 96)]
|
||||
[InlineData("five3xjzlrmxvqznine", 59)]
|
||||
[InlineData("nine4vqxmzqxcvfhlm45", 95)]
|
||||
[InlineData("4nine7oneighthm", 48)]
|
||||
public void GetCalibrationValue_GivenAStringContainingDigits_ItShouldReturnSumOrFirstAndLastDigit(string input, int expected)
|
||||
{
|
||||
var result = _sut.GetCalibrationValue(input);
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(new string[] { "two1nine", "eightwothree", "abcone2threexyz", "xtwone3four", "4nineeightseven2", "zoneight234", "7pqrstsixteen" }, 281)]
|
||||
public void SumCalibrationValues_GivenAnArrayOfStrings_ItShouldReturnTheSumOfAllCalibrationValues(string[] input, int expected)
|
||||
{
|
||||
var result = _sut.SumCalibrationValues(input);
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SumCalibrationValues_GivenAFile_ItShouldReturnTheSumOfAllCalibrationValues()
|
||||
{
|
||||
var input = await File.ReadAllLinesAsync("INPUT.txt");
|
||||
var result = _sut.SumCalibrationValues(input);
|
||||
result.Should().BeLessThan(54249);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
@@ -26,4 +27,10 @@
|
||||
<ProjectReference Include="..\Trebuchet\Trebuchet.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\INPUT.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Trebuchet.Tests;
|
||||
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user