mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 15:37:51 -08:00
Train game with tests
This commit is contained in:
53
91_Train/csharp/TrainTests/TrainTests/TrainGameTests.cs
Normal file
53
91_Train/csharp/TrainTests/TrainTests/TrainGameTests.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
26
91_Train/csharp/TrainTests/TrainTests/TrainTests.csproj
Normal file
26
91_Train/csharp/TrainTests/TrainTests/TrainTests.csproj
Normal 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>
|
||||
Reference in New Issue
Block a user