diff --git a/VECTO.sln b/VECTO.sln index f5711881ad3282eba061c8874b009d735de4e8b8..0be99a097fe047f0efef8818c4fc43b10cc02b74 100644 --- a/VECTO.sln +++ b/VECTO.sln @@ -103,6 +103,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "VectoMockup", "VectoMockup" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VectoMockupTest", "VectoMockup\VectoMockupTest\VectoMockupTest.csproj", "{EC0D4019-BBE6-431C-90E1-BD4AAEC0BF88}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoCommonTests", "VectoCommon\VectoCommonTests\VectoCommonTests.csproj", "{57FB17D2-F715-4FDF-9BC1-0820D36D5650}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -393,6 +395,18 @@ Global {EC0D4019-BBE6-431C-90E1-BD4AAEC0BF88}.MockupRelease|Any CPU.ActiveCfg = Release|Any CPU {EC0D4019-BBE6-431C-90E1-BD4AAEC0BF88}.Release|Any CPU.ActiveCfg = Release|Any CPU {EC0D4019-BBE6-431C-90E1-BD4AAEC0BF88}.Release|Any CPU.Build.0 = Release|Any CPU + {57FB17D2-F715-4FDF-9BC1-0820D36D5650}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {57FB17D2-F715-4FDF-9BC1-0820D36D5650}.Debug|Any CPU.Build.0 = Debug|Any CPU + {57FB17D2-F715-4FDF-9BC1-0820D36D5650}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU + {57FB17D2-F715-4FDF-9BC1-0820D36D5650}.Deploy|Any CPU.Build.0 = Debug|Any CPU + {57FB17D2-F715-4FDF-9BC1-0820D36D5650}.MockupDebug|Any CPU.ActiveCfg = Debug|Any CPU + {57FB17D2-F715-4FDF-9BC1-0820D36D5650}.MockupDebug|Any CPU.Build.0 = Debug|Any CPU + {57FB17D2-F715-4FDF-9BC1-0820D36D5650}.MockupDeploy|Any CPU.ActiveCfg = Debug|Any CPU + {57FB17D2-F715-4FDF-9BC1-0820D36D5650}.MockupDeploy|Any CPU.Build.0 = Debug|Any CPU + {57FB17D2-F715-4FDF-9BC1-0820D36D5650}.MockupRelease|Any CPU.ActiveCfg = Release|Any CPU + {57FB17D2-F715-4FDF-9BC1-0820D36D5650}.MockupRelease|Any CPU.Build.0 = Release|Any CPU + {57FB17D2-F715-4FDF-9BC1-0820D36D5650}.Release|Any CPU.ActiveCfg = Release|Any CPU + {57FB17D2-F715-4FDF-9BC1-0820D36D5650}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -416,6 +430,7 @@ Global {4977BE2A-CB80-4FC0-8D1A-30EC094011B4} = {351FF7E8-B56B-445E-8E98-A61E07C990DA} {D78AD145-DD1F-45E7-89DA-4BF58F8F2D3E} = {351FF7E8-B56B-445E-8E98-A61E07C990DA} {EC0D4019-BBE6-431C-90E1-BD4AAEC0BF88} = {927F1B17-8075-4185-A324-92971D2FB020} + {57FB17D2-F715-4FDF-9BC1-0820D36D5650} = {73A5BF70-6168-456F-95E5-A1402BFA488C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B38F3172-132E-43F7-9C4B-5FDC3A28C051} diff --git a/VectoCommon/VectoCommonTests/EnumerableExtensionMethodsTest.cs b/VectoCommon/VectoCommonTests/EnumerableExtensionMethodsTest.cs new file mode 100644 index 0000000000000000000000000000000000000000..8d3f6a9d5cef2661200243ec6211bc1f4994c2b8 --- /dev/null +++ b/VectoCommon/VectoCommonTests/EnumerableExtensionMethodsTest.cs @@ -0,0 +1,81 @@ +namespace VectoCommonTests +{ + using NUnit.Framework; + using System; + using System.Collections.Generic; + using TUGraz.VectoCommon.Models; + using TUGraz.VectoCommon.Utils; + + public class EnumerableExtensionMethodsTest + { + [Test] + [TestCase(1, 2, 3, 4, 4)] + [TestCase(1, 2, 3, -1, 3)] + [TestCase(-1, -2, -3, -4, -1)] + public void MaxBy_Returns_MaxValue(int value1, int value2, int value3, int value4, double result) + { + List<int> sut = new List<int>() { value1, value2, value3, value4 }; + Assert.That(sut.MaxBy(x => x), Is.EqualTo(result)); + } + + [Test] + public void MaxBy_Returns_Null_WhenCollection_Empty() + { + List<HybridResultEntry> sut = new List<HybridResultEntry>(); + + var result = sut.MaxBy(x => x.U); + + Assert.IsNull(result); + } + + [Test] + public void MaxBy_Throws_InvalidOperationException_WhenCollectionDefaultNotNull() + { + Dictionary<int, HybridResultEntry> sut = new Dictionary<int, HybridResultEntry>(); + + Assert.Throws<InvalidOperationException>(() => sut.MaxBy(x => x.Value.Cost)); + } + + [Test] + public void MinBy_Returns_Null_WhenCollection_Empty() + { + List<HybridResultEntry> sut = new List<HybridResultEntry>(); + + var result = sut.MinBy(x => x.U); + + Assert.IsNull(result); + } + + [Test] + public void MinBy_Throws_InvalidOperationException_WhenCollectionDefaultNotNull() + { + Dictionary<int, HybridResultEntry> sut = new Dictionary<int, HybridResultEntry>(); + + Assert.Throws<InvalidOperationException>(() => sut.MinBy(x => x.Value.Cost)); + } + + [Test] + public void MinBy_Returns_MinValue() + { + List<int> sut = new List<int>() { 1, 2, 3, -1 }; + Assert.That(sut.MinBy(x => x), Is.EqualTo(-1)); + + sut = new List<int>() { -1, -2, -3, -4 }; + Assert.That(sut.MinBy(x => x), Is.EqualTo(-4)); + + sut = new List<int>() { 1, 2, 3, 4 }; + Assert.That(sut.MinBy(x => x), Is.EqualTo(1)); + } + + + [Test] + [TestCase(1, 2, 3, 4, 1)] + [TestCase(1, 2, 3, -1, -1)] + [TestCase(-1, -2, -3, -4, -4)] + public void MinBy_Returns_MinValue_HybridResult(int value1, int value2, int value3, int value4, double result) + { + List<int> sut = new List<int>() { value1, value2, value3, value4 }; + Assert.That(sut.MinBy(x => x), Is.EqualTo(result)); + } + } +} \ No newline at end of file diff --git a/VectoCommon/VectoCommonTests/VectoCommonTests.csproj b/VectoCommon/VectoCommonTests/VectoCommonTests.csproj new file mode 100644 index 0000000000000000000000000000000000000000..12404a9df2f603f9a1b7943330ac776f85525479 --- /dev/null +++ b/VectoCommon/VectoCommonTests/VectoCommonTests.csproj @@ -0,0 +1,20 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFrameworks>net48;net6.0</TargetFrameworks> + <IsPackable>false</IsPackable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> + <PackageReference Include="NUnit" Version="3.13.3" /> + <PackageReference Include="NUnit3TestAdapter" Version="4.2.1" /> + <PackageReference Include="NUnit.Analyzers" Version="3.3.0" /> + <PackageReference Include="coverlet.collector" Version="3.1.2" /> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\VectoCommon\VectoCommon.csproj" /> + </ItemGroup> + +</Project>