mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 07:10:42 -08:00
Create reverser that reverses an array at a given position.
This commit is contained in:
26
73_Reverse/csharp/Reverse/Reverse.Tests/Reverse.Tests.csproj
Normal file
26
73_Reverse/csharp/Reverse/Reverse.Tests/Reverse.Tests.csproj
Normal file
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
|
||||
<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="3.0.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Reverse\Reverse.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
41
73_Reverse/csharp/Reverse/Reverse.Tests/ReverserTests.cs
Normal file
41
73_Reverse/csharp/Reverse/Reverse.Tests/ReverserTests.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Reverse.Tests
|
||||
{
|
||||
public class ReverserTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(new int[] { 1 }, new int[] { 1 })]
|
||||
[InlineData(new int[] { 1, 2 }, new int[] { 2, 1 })]
|
||||
[InlineData(new int[] { 1, 2, 3 }, new int[] { 3, 2, 1 })]
|
||||
public void ReverserReversesTheArray(int[] input, int[] output)
|
||||
{
|
||||
Reverser.Reverse(input, input.Length);
|
||||
|
||||
Assert.True(input.SequenceEqual(output));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReverserReversesTheArrayAtTheSpecifiedIndex()
|
||||
{
|
||||
var input = new int[] { 1, 2, 3, 4 };
|
||||
var output = new int[] { 2, 1, 3, 4 };
|
||||
|
||||
Reverser.Reverse(input, 2);
|
||||
|
||||
Assert.True(input.SequenceEqual(output));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReversingAtIndexOneDoesNotChangeTheArray()
|
||||
{
|
||||
var input = new int[] { 1, 2 };
|
||||
var output = new int[] { 1, 2 };
|
||||
|
||||
Reverser.Reverse(input, 1);
|
||||
|
||||
Assert.True(input.SequenceEqual(output));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user