Skip to content

Commit

Permalink
Migrated tests and updated references.
Browse files Browse the repository at this point in the history
  • Loading branch information
electricessence committed Jul 4, 2021
1 parent 90b89e4 commit 5ff631d
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 2 deletions.
31 changes: 31 additions & 0 deletions Open.Collections.Numeric.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31410.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Open.Collections.Numeric", "source\Open.Collections.Numeric.csproj", "{9D657730-F7E8-4816-B3B1-507CD4EB2ECA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Open.Collections.Numeric.Tests", "tests\Open.Collections.Numeric.Tests.csproj", "{99A27628-3474-42FD-BFD1-9F64C40412D9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9D657730-F7E8-4816-B3B1-507CD4EB2ECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D657730-F7E8-4816-B3B1-507CD4EB2ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D657730-F7E8-4816-B3B1-507CD4EB2ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D657730-F7E8-4816-B3B1-507CD4EB2ECA}.Release|Any CPU.Build.0 = Release|Any CPU
{99A27628-3474-42FD-BFD1-9F64C40412D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99A27628-3474-42FD-BFD1-9F64C40412D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99A27628-3474-42FD-BFD1-9F64C40412D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99A27628-3474-42FD-BFD1-9F64C40412D9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {161319D6-1653-4E21-8CF8-12CF03149775}
EndGlobalSection
EndGlobal
File renamed without changes.
56 changes: 56 additions & 0 deletions source/Open.Collections.Numeric.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>electricessence</Authors>
<Description>
Useful set of extensions for processing collections of numerical data.

Part of the "Open" set of libraries.
</Description>
<PackageTags>collections;numeric;double;extensions;threadsafe;thread-safe</PackageTags>
<Copyright>© electricessence (Oren F.) All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/Open-NET-Libraries/Open.Collections.Numeric/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Open-NET-Libraries/Open.Collections.Numeric/</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>1.5.5</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageIcon>logo.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<None Remove=".git" />
<None Remove=".gitignore" />
<None Include="logo.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<None Remove=".git" />
<None Remove=".gitignore" />
<None Remove="LICENSE.md" />
<None Remove="README.md" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Open.Collections" Version="2.11.1" />
<PackageReference Include="Open.Numeric" Version="2.3.1" />
<PackageReference Include="Open.Threading" Version="1.6.1" />
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions PossibleAddends.cs → source/PossibleAddends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public IEnumerable<IReadOnlyList<int>> GetUniqueAddends(int sum, int count)

protected override void OnDispose()
{
foreach(var c in Cache.Values)
foreach (var c in Cache.Values)
{
foreach (var s in c.Values)
{
if(s is IDisposable d) d.Dispose();
if (s is IDisposable d) d.Dispose();
}
}
Cache.Clear();
Expand Down
File renamed without changes
26 changes: 26 additions & 0 deletions tests/Open.Collections.Numeric.Tests.csproj
Original file line number Diff line number Diff line change
@@ -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.10.0" />
<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.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\source\Open.Collections.Numeric.csproj" />
</ItemGroup>

</Project>
139 changes: 139 additions & 0 deletions tests/SumCombinationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using Open.Collections.Numeric;
using System.Linq;
using Xunit;

namespace Open.Collections.Tests
{
public class SumCombinationTests
{
readonly PossibleAddends SC = new();

[Fact]
public void NoAddendsLessThan2()
{
for (int i = 0; i < 2; i++)
{
Assert.Empty(SC.UniqueAddendsFor(7, i));
Assert.Empty(PossibleAddends.GetUniqueAddendsBuffered(7, i));
}
}

[Fact]
public void NoAddendsWithLowSum()
{
for (int i = 0; i < 4; i++)
{
Assert.Empty(SC.UniqueAddendsFor(2, i));
Assert.Empty(PossibleAddends.GetUniqueAddendsBuffered(2, i));
}
}

[Fact]
public void AddendsFor2()
{
{
var result = SC.UniqueAddendsFor(3, 2);
Assert.Equal(1, result.Count);
Assert.Equal(new int[] { 1, 2 }, result[0]);
Assert.Equal(result, PossibleAddends.GetUniqueAddendsEnumerable(3, 2));
}
{
var result = SC.UniqueAddendsFor(4, 2);
Assert.Equal(1, result.Count);
Assert.Equal(new int[] { 1, 3 }, result[0]);
Assert.Equal(result, PossibleAddends.GetUniqueAddendsEnumerable(4, 2));
}
{
var result = SC.UniqueAddendsFor(5, 2);
Assert.Equal(2, result.Count);
Assert.Equal(new int[] { 1, 4 }, result[0]);
Assert.Equal(new int[] { 2, 3 }, result[1]);
Assert.Equal(result, PossibleAddends.GetUniqueAddendsEnumerable(5, 2));
}
{
var result = SC.UniqueAddendsFor(6, 2);
Assert.Equal(2, result.Count);
Assert.Equal(new int[] { 1, 5 }, result[0]);
Assert.Equal(new int[] { 2, 4 }, result[1]);
Assert.Equal(result, PossibleAddends.GetUniqueAddendsEnumerable(6, 2));
}
{
var result = SC.UniqueAddendsFor(7, 2);
Assert.Equal(3, result.Count);
Assert.Equal(new int[] { 1, 6 }, result[0]);
Assert.Equal(new int[] { 2, 5 }, result[1]);
Assert.Equal(new int[] { 3, 4 }, result[2]);
Assert.Equal(result, PossibleAddends.GetUniqueAddendsEnumerable(7, 2));
}
}


[Fact]
public void AddendsFor3()
{
{
for (int i = 0; i < 6; i++)
{
var result = SC.UniqueAddendsFor(i, 3);
Assert.Empty(result);
Assert.Empty(PossibleAddends.GetUniqueAddendsBuffered(i, 3));
}
}
{
var result = SC.UniqueAddendsFor(6, 3);
Assert.Equal(1, result.Count);
Assert.Equal(new int[] { 1, 2, 3 }, result[0]);
Assert.Equal(result, PossibleAddends.GetUniqueAddendsEnumerable(6, 3));
}
{
var result = SC.UniqueAddendsFor(7, 3);
Assert.Equal(1, result.Count);
Assert.Equal(new int[] { 1, 2, 4 }, result[0]);
Assert.Equal(result, PossibleAddends.GetUniqueAddendsEnumerable(7, 3));
}
{
var result = SC.UniqueAddendsFor(8, 3);
Assert.Equal(2, result.Count);
Assert.Equal(new int[] { 1, 2, 5 }, result[0]);
Assert.Equal(new int[] { 1, 3, 4 }, result[1]);
Assert.Equal(result, PossibleAddends.GetUniqueAddendsEnumerable(8, 3));
}
{
var result = SC.UniqueAddendsFor(9, 3);
Assert.Equal(3, result.Count);
Assert.Equal(new int[] { 1, 2, 6 }, result[0]);
Assert.Equal(new int[] { 1, 3, 5 }, result[1]);
Assert.Equal(new int[] { 2, 3, 4 }, result[2]);
Assert.Equal(result, PossibleAddends.GetUniqueAddendsEnumerable(9, 3));
}
{
var result = SC.UniqueAddendsFor(10, 3);
Assert.Equal(4, result.Count);
Assert.Equal(new int[] { 1, 2, 7 }, result[0]);
Assert.Equal(new int[] { 1, 3, 6 }, result[1]);
Assert.Equal(new int[] { 1, 4, 5 }, result[2]);
Assert.Equal(new int[] { 2, 3, 5 }, result[3]);
Assert.Equal(result, PossibleAddends.GetUniqueAddendsEnumerable(10, 3));
}

{
var result = SC.UniqueAddendsFor(15, 3);
Assert.Equal(12, result.Count);
Assert.Equal(new int[] { 1, 2, 12 }, result[0]);
Assert.Equal(new int[] { 1, 3, 11 }, result[1]);
Assert.Equal(new int[] { 1, 4, 10 }, result[2]);
Assert.Equal(new int[] { 2, 3, 10 }, result[3]);
Assert.Equal(new int[] { 1, 5, 9 }, result[4]);
Assert.Equal(new int[] { 2, 4, 9 }, result[5]);
Assert.Equal(new int[] { 1, 6, 8 }, result[6]);
Assert.Equal(new int[] { 2, 5, 8 }, result[7]);
Assert.Equal(new int[] { 3, 4, 8 }, result[8]);
Assert.Equal(new int[] { 2, 6, 7 }, result[9]);
Assert.Equal(new int[] { 3, 5, 7 }, result[10]);
Assert.Equal(new int[] { 4, 5, 6 }, result[11]);
Assert.Equal(result, PossibleAddends.GetUniqueAddendsEnumerable(15, 3));
}
}

}
}

0 comments on commit 5ff631d

Please sign in to comment.