Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public void PushRange(T[] items)
{
throw new ArgumentNullException(nameof(items));
}

PushRange(items, 0, items.Length);
}

Expand Down Expand Up @@ -349,7 +350,6 @@ public void PushRange(T[] items, int startIndex, int count)
if (count == 0)
return;


Node head, tail;
head = tail = new Node(items[startIndex]);
for (int i = startIndex + 1; i < startIndex + count; i++)
Expand Down Expand Up @@ -410,7 +410,7 @@ private static void ValidatePushPopRangeInput(T[] items, int startIndex, int cou
throw new ArgumentOutOfRangeException(nameof(count), SR.ConcurrentStack_PushPopRange_CountOutOfRange);
}
int length = items.Length;
if (startIndex >= length || startIndex < 0)
if (startIndex > length || startIndex < 0)
{
throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ConcurrentStack_PushPopRange_StartOutOfRange);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ public void PushRange_NoItems_NothingAdded()
Assert.True(s.IsEmpty);
}

[Fact]
public void PushRange_NoItems_NothingAdded_EmptyArrayWithRangeSpecified()
{
var s = new ConcurrentStack<int>();
Assert.True(s.IsEmpty);

s.PushRange(new int[0], 0, 0);
Assert.True(s.IsEmpty);
}

[Fact]
public void PushRange_NoItems_NothingAdded_EmptyArrayNoRangeSpecified()
{
var s = new ConcurrentStack<int>();
Assert.True(s.IsEmpty);

s.PushRange(new int[0]);
Assert.True(s.IsEmpty);
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[InlineData(8, 10)]
[InlineData(16, 100)]
Expand Down Expand Up @@ -134,6 +154,7 @@ public void PushRange_InvalidArguments_Throws()
Assert.Throws<ArgumentOutOfRangeException>(() => stack.PushRange(new int[1], 0, -1));
Assert.Throws<ArgumentOutOfRangeException>(() => stack.PushRange(new int[1], -1, 1));
Assert.Throws<ArgumentOutOfRangeException>(() => stack.PushRange(new int[1], 2, 1));
AssertExtensions.Throws<ArgumentException>(null, () => stack.PushRange(new int[0], 0, 1));
AssertExtensions.Throws<ArgumentException>(null, () => stack.PushRange(new int[1], 0, 10));
}

Expand Down