Skip to content

Commit 0ca9b9e

Browse files
Fixed issue with expanded comination set.
1 parent d6c78d3 commit 0ca9b9e

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

source/Extensions.Combinations.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ static IEnumerable<T[]> CombinationsCore<T>(IReadOnlyList<T> source, int length,
2323
if (count == 1) yield break;
2424
}
2525

26-
var pool = count > 128 ? ArrayPool<int>.Shared : null;
27-
var indexes = pool?.Rent(count) ?? new int[count];
26+
var pool = length > 128 ? ArrayPool<int>.Shared : null;
27+
var indexes = pool?.Rent(length) ?? new int[length];
2828
try
2929
{
3030
for (var i = 0; i < length; i++) indexes[i] = 0;

source/Open.Collections.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PackageProjectUrl>https://github.com/Open-NET-Libraries/Open.Collections/</PackageProjectUrl>
1818
<RepositoryUrl>https://github.com/Open-NET-Libraries/Open.Collections/</RepositoryUrl>
1919
<RepositoryType>git</RepositoryType>
20-
<Version>2.12.7</Version>
20+
<Version>2.12.8</Version>
2121
<PackageReleaseNotes></PackageReleaseNotes>
2222
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2323
<PublishRepositoryUrl>true</PublishRepositoryUrl>

testing/Open.Collections.Tests/CombinationTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class CombinationTests
88
{
99
static ImmutableArray<int> Set1 = ImmutableArray.Create(1, 2);
1010
static ImmutableArray<char> Set2 = ImmutableArray.Create('A', 'C', 'E');
11+
static ImmutableArray<int> Set3 = ImmutableArray.Create(0, 1);
1112

1213
[Fact]
1314
public void TestCombination1()
@@ -67,5 +68,30 @@ public void TestCombination2Distinct()
6768
Assert.Equal(expected, actual);
6869
}
6970

71+
72+
[Fact]
73+
public void TestCombination3()
74+
{
75+
var expected = new int[][] {
76+
new int[] { 0, 0, 0, 0 },
77+
new int[] { 0, 0, 0, 1 },
78+
new int[] { 0, 0, 1, 0 },
79+
new int[] { 0, 0, 1, 1 },
80+
new int[] { 0, 1, 0, 0 },
81+
new int[] { 0, 1, 0, 1 },
82+
new int[] { 0, 1, 1, 0 },
83+
new int[] { 0, 1, 1, 1 },
84+
new int[] { 1, 0, 0, 0 },
85+
new int[] { 1, 0, 0, 1 },
86+
new int[] { 1, 0, 1, 0 },
87+
new int[] { 1, 0, 1, 1 },
88+
new int[] { 1, 1, 0, 0 },
89+
new int[] { 1, 1, 0, 1 },
90+
new int[] { 1, 1, 1, 0 },
91+
new int[] { 1, 1, 1, 1 },
92+
};
93+
var actual = Set3.Combinations(4).ToArray();
94+
Assert.Equal(expected, actual);
95+
}
7096
}
7197
}

0 commit comments

Comments
 (0)