Train game with tests

This commit is contained in:
mattbloke99
2022-01-02 14:21:30 +00:00
parent 70684435fe
commit 83458c428e
5 changed files with 211 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
using Train;
using Xunit;
namespace TrainTests
{
public class TrainGameTests
{
[Fact]
public void MiniumRandomNumber()
{
TrainGame game = new TrainGame();
Assert.True(game.GenerateRandomNumber(10, 10) >= 10);
}
[Fact]
public void MaximumRandomNumber()
{
TrainGame game = new TrainGame();
Assert.True(game.GenerateRandomNumber(10, 10) <= 110);
}
[Fact]
public void IsInputYesWhenY()
{
Assert.True(TrainGame.IsInputYes("y"));
}
[Fact]
public void IsInputYesWhenNotY()
{
Assert.False(TrainGame.IsInputYes("a"));
}
[Fact]
public void CarDurationTest()
{
Assert.Equal(1, TrainGame.CalculateCarJourneyDuration(30, 1, 15) );
}
[Fact]
public void IsWithinAllowedDifference()
{
Assert.True(TrainGame.IsWithinAllowedDifference(5,5));
}
[Fact]
public void IsNotWithinAllowedDifference()
{
Assert.False(TrainGame.IsWithinAllowedDifference(6, 5));
}
}
}

View File

@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Train\Train\TrainGame.csproj" />
</ItemGroup>
</Project>