-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cover MergeSortingStrategy and QuickSortingStrategy with unit tests.
- Loading branch information
1 parent
1351933
commit ba948b0
Showing
6 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Behavioral/DesignPatterns.Strategy.UnitTests/DesignPatterns.Strategy.UnitTests.csproj
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,36 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AutoFixture" Version="4.18.1" /> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="Moq" Version="4.20.70" /> | ||
<PackageReference Include="Shouldly" Version="4.2.1" /> | ||
<PackageReference Include="xunit" Version="2.6.5" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.msbuild" Version="6.0.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DesignPatterns.Strategy\DesignPatterns.Strategy.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
43 changes: 43 additions & 0 deletions
43
Behavioral/DesignPatterns.Strategy.UnitTests/MergeSortingStrategyTests.cs
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,43 @@ | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace DesignPatterns.Strategy.UnitTests; | ||
|
||
public class MergeSortingStrategyTests | ||
{ | ||
[Fact] | ||
public void GivenUnsortedNumbers_WhenSort_ThenResultAsExpected() | ||
{ | ||
var unsortedList = new List<int> { 34, 7, 23, 32, 5, 62, 12, 19, 4, 47 }; | ||
var strategy = new MergeSortingStrategy(); | ||
strategy.Sort(unsortedList); | ||
unsortedList.ShouldBe([4, 5, 7, 12, 19, 23, 32, 34, 47, 62]); | ||
} | ||
|
||
[Fact] | ||
public void GivenSortedNumbers_WhenSort_ThenResultAsExpected() | ||
{ | ||
var sortedList = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; | ||
var strategy = new MergeSortingStrategy(); | ||
strategy.Sort(sortedList); | ||
sortedList.ShouldBe([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | ||
} | ||
|
||
[Fact] | ||
public void GivenReverseSortedNumbers_WhenSort_ThenResultAsExpected() | ||
{ | ||
var reverseSortedList = new List<int> { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; | ||
var strategy = new MergeSortingStrategy(); | ||
strategy.Sort(reverseSortedList); | ||
reverseSortedList.ShouldBe([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | ||
} | ||
|
||
[Fact] | ||
public void GivenNoNumbers_WhenSort_ThenResultAsExpected() | ||
{ | ||
var emptyList = new List<int>(); | ||
var strategy = new MergeSortingStrategy(); | ||
strategy.Sort(emptyList); | ||
emptyList.ShouldBe(new List<int>()); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Behavioral/DesignPatterns.Strategy.UnitTests/QuickSortingStrategyTests.cs
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,43 @@ | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace DesignPatterns.Strategy.UnitTests; | ||
|
||
public class QuickSortingStrategyTests | ||
{ | ||
[Fact] | ||
public void GivenUnsortedNumbers_WhenSort_ThenResultAsExpected() | ||
{ | ||
var unsortedList = new List<int> { 34, 7, 23, 32, 5, 62, 12, 19, 4, 47 }; | ||
var strategy = new QuickSortingStrategy(); | ||
strategy.Sort(unsortedList); | ||
unsortedList.ShouldBe([4, 5, 7, 12, 19, 23, 32, 34, 47, 62]); | ||
} | ||
|
||
[Fact] | ||
public void GivenSortedNumbers_WhenSort_ThenResultAsExpected() | ||
{ | ||
var sortedList = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; | ||
var strategy = new QuickSortingStrategy(); | ||
strategy.Sort(sortedList); | ||
sortedList.ShouldBe([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | ||
} | ||
|
||
[Fact] | ||
public void GivenReverseSortedNumbers_WhenSort_ThenResultAsExpected() | ||
{ | ||
var reverseSortedList = new List<int> { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; | ||
var strategy = new QuickSortingStrategy(); | ||
strategy.Sort(reverseSortedList); | ||
reverseSortedList.ShouldBe([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | ||
} | ||
|
||
[Fact] | ||
public void GivenNoNumbers_WhenSort_ThenResultAsExpected() | ||
{ | ||
var emptyList = new List<int>(); | ||
var strategy = new QuickSortingStrategy(); | ||
strategy.Sort(emptyList); | ||
emptyList.ShouldBe(new List<int>()); | ||
} | ||
} |
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
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