Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit d05a07b

Browse files
committed
Add more tests for creating ImmutableSortedSets
1 parent b47a902 commit d05a07b

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/System.Collections.Immutable/tests/ImmutableSortedSetTest.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,51 @@ public void ToUnorderedTest()
121121
}
122122

123123
[Fact]
124-
public void ToImmutableSortedSetTest()
124+
public void ToImmutableSortedSetFromArrayTest()
125125
{
126126
var set = new[] { 1, 2, 2 }.ToImmutableSortedSet();
127127
Assert.Same(Comparer<int>.Default, set.KeyComparer);
128128
Assert.Equal(2, set.Count);
129129
}
130130

131+
[Theory]
132+
[InlineData(new int[] { }, new int[] { })]
133+
[InlineData(new int[] { 1 }, new int[] { 1 })]
134+
[InlineData(new int[] { 1, 1 }, new int[] { 1 })]
135+
[InlineData(new int[] { 1, 1, 1 }, new int[] { 1 })]
136+
[InlineData(new int[] { 1, 2, 3 }, new int[] { 1, 2, 3 })]
137+
[InlineData(new int[] { 3, 2, 1 }, new int[] { 1, 2, 3 })]
138+
[InlineData(new int[] { 1, 1, 3 }, new int[] { 1, 3 })]
139+
[InlineData(new int[] { 1, 2, 2 }, new int[] { 1, 2 })]
140+
[InlineData(new int[] { 1, 2, 2, 3, 3, 3 }, new int[] { 1, 2, 3 })]
141+
[InlineData(new int[] { 1, 2, 3, 1, 2, 3 }, new int[] { 1, 2, 3 })]
142+
[InlineData(new int[] { 1, 1, 2, 2, 2, 3, 3, 3, 3 }, new int[] { 1, 2, 3 })]
143+
public void ToImmutableSortedSetFromEnumerableTest(int[] input, int[] expectedOutput)
144+
{
145+
IEnumerable<int> enumerableInput = input.Select(i => i); // prevent querying for indexable interfaces
146+
var set = enumerableInput.ToImmutableSortedSet();
147+
Assert.Equal((IEnumerable<int>)expectedOutput, set.ToArray());
148+
}
149+
150+
[Theory]
151+
[InlineData(new int[] { }, new int[] { 1 })]
152+
[InlineData(new int[] { 1 }, new int[] { 1 })]
153+
[InlineData(new int[] { 1, 1 }, new int[] { 1 })]
154+
[InlineData(new int[] { 1, 1, 1 }, new int[] { 1 })]
155+
[InlineData(new int[] { 1, 2, 3 }, new int[] { 1, 2, 3 })]
156+
[InlineData(new int[] { 3, 2, 1 }, new int[] { 1, 2, 3 })]
157+
[InlineData(new int[] { 1, 1, 3 }, new int[] { 1, 3 })]
158+
[InlineData(new int[] { 1, 2, 2 }, new int[] { 1, 2 })]
159+
[InlineData(new int[] { 1, 2, 2, 3, 3, 3 }, new int[] { 1, 2, 3 })]
160+
[InlineData(new int[] { 1, 2, 3, 1, 2, 3 }, new int[] { 1, 2, 3 })]
161+
[InlineData(new int[] { 1, 1, 2, 2, 2, 3, 3, 3, 3 }, new int[] { 1, 2, 3 })]
162+
public void UnionWithEnumerableTest(int[] input, int[] expectedOutput)
163+
{
164+
IEnumerable<int> enumerableInput = input.Select(i => i); // prevent querying for indexable interfaces
165+
var set = ImmutableSortedSet.Create(1).Union(enumerableInput);
166+
Assert.Equal((IEnumerable<int>)expectedOutput, set.ToArray());
167+
}
168+
131169
[Fact]
132170
public void IndexOfTest()
133171
{

0 commit comments

Comments
 (0)