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

Commit 45bff38

Browse files
committed
Add more tests for RemoveRange
We were lacking sufficient coverage for the overload that takes an ImmutableArray<T>. This essentially duplicates the RemoveRangeEnumerableTest but with an ImmutableArray<T> instead of IEnumerable<T> argument.
1 parent 28949a4 commit 45bff38

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,8 @@ public void RemoveRange()
826826
{
827827
Assert.Throws<ArgumentOutOfRangeException>(() => s_empty.RemoveRange(0, 0));
828828
Assert.Throws<NullReferenceException>(() => s_emptyDefault.RemoveRange(0, 0));
829+
Assert.Throws<ArgumentOutOfRangeException>(() => s_emptyDefault.RemoveRange(-1, 0));
830+
Assert.Throws<NullReferenceException>(() => s_emptyDefault.RemoveRange(0, -1));
829831
Assert.Throws<ArgumentOutOfRangeException>(() => s_oneElement.RemoveRange(1, 0));
830832
Assert.Throws<ArgumentOutOfRangeException>(() => s_empty.RemoveRange(-1, 0));
831833
Assert.Throws<ArgumentOutOfRangeException>(() => s_oneElement.RemoveRange(0, 2));
@@ -913,6 +915,35 @@ public void RemoveRangeEnumerableTest()
913915
Assert.Equal(new[] { 1, 3 }, listWithDuplicates.RemoveRange(new[] { 2, 2, 2 }));
914916
}
915917

918+
[Fact]
919+
public void RemoveRangeImmutableArrayTest()
920+
{
921+
var list = ImmutableArray.Create(1, 2, 3);
922+
923+
ImmutableArray<int> removed2 = list.RemoveRange(ImmutableArray.Create(2));
924+
Assert.Equal(2, removed2.Length);
925+
Assert.Equal(new[] { 1, 3 }, removed2);
926+
927+
ImmutableArray<int> removed13 = list.RemoveRange(ImmutableArray.Create(1, 3, 5));
928+
Assert.Equal(1, removed13.Length);
929+
Assert.Equal(new[] { 2 }, removed13);
930+
931+
Assert.Equal(new[] { 1, 3, 6, 8, 9 }, ImmutableArray.CreateRange(Enumerable.Range(1, 10)).RemoveRange(ImmutableArray.Create(2, 4, 5, 7, 10)));
932+
Assert.Equal(new[] { 3, 6, 8, 9 }, ImmutableArray.CreateRange(Enumerable.Range(1, 10)).RemoveRange(ImmutableArray.Create(1, 2, 4, 5, 7, 10)));
933+
934+
Assert.Equal(list, list.RemoveRange(ImmutableArray.Create(5)));
935+
Assert.Equal(ImmutableArray.Create<int>(), ImmutableArray.Create<int>().RemoveRange(ImmutableArray.Create(1)));
936+
937+
var listWithDuplicates = ImmutableArray.Create(1, 2, 2, 3);
938+
Assert.Equal(new[] { 1, 2, 3 }, listWithDuplicates.RemoveRange(ImmutableArray.Create(2)));
939+
Assert.Equal(new[] { 1, 3 }, listWithDuplicates.RemoveRange(ImmutableArray.Create(2, 2)));
940+
Assert.Equal(new[] { 1, 3 }, listWithDuplicates.RemoveRange(ImmutableArray.Create(2, 2, 2)));
941+
942+
Assert.Equal(new[] { 2, 3 }, list.RemoveRange(ImmutableArray.Create(42), EverythingEqual<int>.Default));
943+
Assert.Equal(new[] { 3 }, list.RemoveRange(ImmutableArray.Create(42, 42), EverythingEqual<int>.Default));
944+
Assert.Equal(new int[0], list.RemoveRange(ImmutableArray.Create(42, 42, 42), EverythingEqual<int>.Default));
945+
}
946+
916947
[Fact]
917948
public void Replace()
918949
{

0 commit comments

Comments
 (0)