-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4316076
commit e30636c
Showing
18 changed files
with
914 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp2.0;netcoreapp2.1;netcoreapp3.0;net471;net47;net461;net46</TargetFrameworks> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.0" /> | ||
<PackageReference Include="xunit" Version="2.4.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="1.1.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\AoCHelper\AoCHelper.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ItemsToCopy Include="$(MSBuildThisFileDirectory)\Inputs\*.in" /> | ||
</ItemGroup> | ||
|
||
<Target Name="CopyInputFilesToOutputDir" AfterTargets="Build"> | ||
<Copy SourceFiles="@(ItemsToCopy)" DestinationFolder="$(OutputPath)\\Inputs" /> | ||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 2 3 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
using AoCHelper.Helpers; | ||
using System; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace AoCHelper.Test | ||
{ | ||
public class NumericExtensionsTest | ||
{ | ||
[Fact] | ||
public void ClampInt() | ||
{ | ||
const int min = 3; | ||
const int max = 5; | ||
|
||
Dictionary<int, int> numberExpectedClampedValuePair = new Dictionary<int, int>() | ||
{ | ||
[int.MinValue] = min, | ||
[0] = min, | ||
[1] = min, | ||
[3] = 3, | ||
[4] = 4, | ||
[5] = 5, | ||
[7] = max, | ||
[int.MaxValue] = max | ||
}; | ||
|
||
foreach (var pair in numberExpectedClampedValuePair) | ||
{ | ||
Assert.Equal(pair.Value, pair.Key.Clamp(min, max)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ClampShort() | ||
{ | ||
const short min = 3; | ||
const short max = 5; | ||
|
||
Dictionary<short, short> numberExpectedClampedValuePair = new Dictionary<short, short>() | ||
{ | ||
[short.MinValue] = min, | ||
[0] = min, | ||
[1] = min, | ||
[3] = 3, | ||
[4] = 4, | ||
[5] = 5, | ||
[7] = max, | ||
[short.MaxValue] = max | ||
}; | ||
|
||
foreach (var pair in numberExpectedClampedValuePair) | ||
{ | ||
Assert.Equal(pair.Value, pair.Key.Clamp(min, max)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ClampLong() | ||
{ | ||
const long min = 3; | ||
const long max = 5; | ||
|
||
Dictionary<long, long> numberExpectedClampedValuePair = new Dictionary<long, long>() | ||
{ | ||
[long.MinValue] = min, | ||
[0] = min, | ||
[1] = min, | ||
[3] = 3, | ||
[4] = 4, | ||
[5] = 5, | ||
[7] = max, | ||
[long.MaxValue] = max | ||
}; | ||
|
||
foreach (var pair in numberExpectedClampedValuePair) | ||
{ | ||
Assert.Equal(pair.Value, pair.Key.Clamp(min, max)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ClampFloat() | ||
{ | ||
const float min = 3; | ||
const float max = 5; | ||
|
||
Dictionary<float, float> numberExpectedClampedValuePair = new Dictionary<float, float>() | ||
{ | ||
[float.MinValue] = min, | ||
[0] = min, | ||
[1] = min, | ||
[3] = 3, | ||
[4] = 4, | ||
[5] = 5, | ||
[7] = max, | ||
[float.MaxValue] = max | ||
}; | ||
|
||
foreach (var pair in numberExpectedClampedValuePair) | ||
{ | ||
Assert.Equal(pair.Value, pair.Key.Clamp(min, max)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ClampDouble() | ||
{ | ||
const double min = 3.01; | ||
const double max = 4.99; | ||
|
||
Dictionary<double, double> numberExpectedClampedValuePair = new Dictionary<double, double>() | ||
{ | ||
[double.MinValue] = min, | ||
[0] = min, | ||
[1] = min, | ||
[3.02] = 3.02, | ||
[4] = 4, | ||
[4.98] = 4.98, | ||
[5] = max, | ||
[double.MaxValue] = max | ||
}; | ||
|
||
foreach (var pair in numberExpectedClampedValuePair) | ||
{ | ||
Assert.Equal(pair.Value, pair.Key.Clamp(min, max)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ClampDateTime() | ||
{ | ||
DateTime min = new DateTime(2019, 10, 25); | ||
DateTime max = new DateTime(2019, 10, 30); | ||
|
||
Dictionary<DateTime, DateTime> numberExpectedClampedValuePair = new Dictionary<DateTime, DateTime>() | ||
{ | ||
[DateTime.MinValue] = min, | ||
[new DateTime(2019, 10, 24, 23, 0, 0)] = min, | ||
[new DateTime(2019, 10, 25, 1, 0, 0)] = new DateTime(2019, 10, 25, 1, 0, 0), | ||
[new DateTime(2019, 10, 30, 0, 0, 1)] = max, | ||
[DateTime.MaxValue] = max | ||
}; | ||
|
||
foreach (var pair in numberExpectedClampedValuePair) | ||
{ | ||
Assert.Equal(pair.Value, pair.Key.Clamp(min, max)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using AoCHelper.Helpers; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace AoCHelper.Test | ||
{ | ||
public class RangeHelpersTest | ||
{ | ||
[Fact] | ||
public void GenerateRangeTest() | ||
{ | ||
const int min = -50; | ||
const int max = +27; | ||
|
||
var result = RangeHelpers.GenerateRange(min, max); | ||
|
||
Assert.Equal(min, result.First()); | ||
Assert.Equal(max, result.Last()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Xunit; | ||
|
||
namespace AoCHelper.Test | ||
{ | ||
public class SolverTest | ||
{ | ||
private readonly ProblemSolver _solver; | ||
|
||
public SolverTest() | ||
{ | ||
_solver = new ProblemSolver(); | ||
} | ||
|
||
private abstract class ProblemFixture : BaseProblem | ||
{ | ||
public override void Solve_1() => Solve(); | ||
|
||
public override void Solve_2() => Solve(); | ||
|
||
private void Solve() | ||
{ | ||
if (!File.Exists(FilePath)) | ||
{ | ||
throw new FileNotFoundException(FilePath); | ||
} | ||
} | ||
} | ||
|
||
private class Problem01 : ProblemFixture | ||
{ | ||
} | ||
|
||
private class NonDetectedProblem : ProblemFixture | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void Solve() | ||
{ | ||
_solver.Solve<Problem01>(); | ||
_solver.SolveWithMetrics<Problem01>(); | ||
|
||
Assert.Equal(2, _solver.LoadAllProblems(Assembly.GetExecutingAssembly()).Count()); | ||
} | ||
|
||
[Fact] | ||
public void ShouldNotSolve() | ||
{ | ||
Assert.Throws<FileNotFoundException>(() => _solver.Solve<NonDetectedProblem>()); | ||
Assert.Throws<FileNotFoundException>(() => _solver.SolveWithMetrics<NonDetectedProblem>()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="AoCHelper.targets" /> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.1;netstandard2.0;net46</TargetFrameworks> | ||
<Title>AoCHelper</Title> | ||
<PackageId>AoCHelper</PackageId> | ||
<Version>0.1</Version> | ||
<PackageTags>AoC, AdventOfCode, Advent, Code</PackageTags> | ||
<Tags>$(PackageTags)</Tags> | ||
<Authors>Eduardo Cáceres</Authors> | ||
<Description> | ||
Library that provides infrastructure for you to solve AoC problems, so that you don't have to prepare (almost) anything! | ||
</Description> | ||
<PackageLicenseUrl>https://github.com/eduherminio/AoCHelper/blob/master/LICENSE</PackageLicenseUrl> | ||
<PackageProjectUrl>https://github.com/eduherminio/AoCHelper</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/eduherminio/AoCHelper</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>AoCHelper</AssemblyName> | ||
<PublishDir>PublishOutput\</PublishDir> | ||
<NugetPackagesDir>$(MSBuildProjectDirectory)\..\..\Artifacts\</NugetPackagesDir> | ||
</PropertyGroup> | ||
|
||
<Target Name="PushNugetPackage" Condition="$(VersionTag) != '' AND $(ApiKey) != ''"> | ||
<Message Text="***Preparing to push Nuget Package...***" Importance="high"></Message> | ||
<CallTarget Targets="PrepareNugetPackage" ContinueOnError="false"></CallTarget> | ||
<CallTarget Targets="TestNugetPackageLocally"></CallTarget> | ||
<CallTarget Targets="PushToNuget"></CallTarget> | ||
</Target> | ||
|
||
<!--Dependency rather than direct call to ensure path update. --> | ||
<!--See https://stackoverflow.com/questions/7534390/msbuild-property-scope --> | ||
<Target Name="PrepareNugetPackage" DependsOnTargets="EnsureTrailingSlash"> | ||
<Message Text="***Preparing Nuget Package***" Importance="high"></Message> | ||
<CallTarget Targets="Cleaning"></CallTarget> | ||
<Exec Command="dotnet build /t:ReplaceVersion /p:VersionTag=$(VersionTag) /p:TargetFramework=netstandard2.0"></Exec> | ||
<CallTarget Targets="FreshBuilding" ContinueOnError="false"></CallTarget> | ||
<CallTarget Targets="Tests" ContinueOnError="false"></CallTarget> | ||
<CallTarget Targets="DotnetPublish" ContinueOnError="false"></CallTarget> | ||
<CallTarget Targets="DotnetPack" ContinueOnError="false"></CallTarget> | ||
</Target> | ||
|
||
<Target Name="EnsureTrailingSlash"> | ||
<PropertyGroup> | ||
<!--Ensure paths have a trailing slash, so they can be concatenated--> | ||
<PublishDir Condition="!HasTrailingSlash('$(PublishDir)')">$(PublishDir)\</PublishDir> | ||
<NugetPackagesDir Condition="!HasTrailingSlash('$(NugetPackagesDir)')">$(NugetPackagesDir)\</NugetPackagesDir> | ||
</PropertyGroup> | ||
</Target> | ||
|
||
<Target Name="Cleaning"> | ||
<Message Text="***Cleaning***" Importance="high"></Message> | ||
<Exec Command="dotnet clean" /> | ||
<RemoveDir Directories=".\bin" Condition="Exists('.\bin')"></RemoveDir> | ||
<RemoveDir Directories=".\obj" Condition="Exists('.\obj')"></RemoveDir> | ||
<RemoveDir Directories=".\$(PublishDir)" Condition="Exists('.\$(PublishDir)')"></RemoveDir> | ||
<Exec Command="dotnet restore --force"></Exec> | ||
</Target> | ||
|
||
<Target Name="FreshBuilding"> | ||
<Message Text="***Fresh-building***" Importance="high"></Message> | ||
<Exec Command="dotnet restore" /> | ||
<Exec Command="dotnet build --configuration Release --force --no-incremental " ContinueOnError="false"></Exec> | ||
</Target> | ||
|
||
<Target Name="Tests"> | ||
<Message Text="***Running $(AssemblyName) tests***" Importance="high"></Message> | ||
<Exec Command="dotnet test ../AoCHelper.Test/AoCHelper.Test.csproj -c Release" ContinueOnError="false" /> | ||
</Target> | ||
|
||
<Target Name ="DotnetPublish"> | ||
<PropertyGroup> | ||
<RootPath>$(PublishDir)\$(AssemblyName).$(Version)\</RootPath> | ||
</PropertyGroup> | ||
<Message Text="***Publishing package***" Importance="high"></Message> | ||
<Exec Command="dotnet publish -c Release -f netstandard2.1 -o $(RootPath)\netstandard2.1\"></Exec> | ||
<Exec Command="dotnet publish -c Release -f netstandard2.0 -o $(RootPath)\netstandard2.0\"></Exec> | ||
<Exec Command="dotnet publish -c Release -f net46 -o $(RootPath)\net46\"></Exec> | ||
</Target> | ||
|
||
<Target Name ="DotnetPack"> | ||
<Message Text="***Generating Nuget Package***" Importance="high"></Message> | ||
<Exec Command ="dotnet pack -c Release AoCHelper.csproj --no-build -o $(NugetPackagesDir)"></Exec> | ||
</Target> | ||
|
||
<Target Name="ReplaceVersion" Condition="$(VersionTag) != '' AND $(TargetFramework)=='netstandard2.0'" DependsOnTargets="Build"> | ||
<Message Text="***Replacing current version $(Version) by new version $(VersionTag)***" Importance="high"></Message> | ||
<PropertyGroup> | ||
<ExistingVersionRegex><Version>.*</Version</ExistingVersionRegex> | ||
<NewVersionRegex><Version>$(VersionTag)</Version</NewVersionRegex> | ||
<ExistingReference>Include="$(AssemblyName)" Version=".*"</ExistingReference> | ||
<NewReference>Include="$(AssemblyName)" Version="$(VersionTag)"</NewReference> | ||
</PropertyGroup> | ||
<ReplaceFileText InputFilename="AoCHelper.csproj" OutputFilename="AoCHelper.csproj" | ||
MatchExpression="$(ExistingVersionRegex)" ReplacementText="$(NewVersionRegex)" /> | ||
</Target> | ||
|
||
<!--ApiKey cannot be inferred from a SetApiKey previously made outside of the build script--> | ||
<Target Name="PushToNuget" Condition="$(ApiKey) != '' AND $(VersionTag) != '' " DependsOnTargets="TestNugetPackageLocally"> | ||
<PropertyGroup> | ||
<NugetPackageName>$(AssemblyName).$(VersionTag).nupkg</NugetPackageName> | ||
</PropertyGroup> | ||
<Message Text="***Pushing $(NugetPackageName) to Nuget***" Importance="high"></Message> | ||
<Exec Command="nuget push $(NugetPackagesDir)$(NugetPackageName) -ApiKey $(ApiKey) -Source https://api.nuget.org/v3/index.json -Verbosity detailed" | ||
Condition="Exists('$(NugetPackagesDir)$(NugetPackageName)')" ContinueOnError="false"></Exec> | ||
<Message Text="***$(NugetPackageName) has been successfully pushed to Nuget***" Importance="high"></Message> | ||
</Target> | ||
</Project> |
Oops, something went wrong.