Skip to content

Commit 4f21a30

Browse files
committed
Add SimpleList<T>.RemoveLastSize
1 parent 48950be commit 4f21a30

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Source/ac-library-csharp/Internal/SimpleList.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public void RemoveLast()
6666
ThrowIndexOutOfRangeException();
6767
}
6868
[MethodImpl(256)]
69+
public void RemoveLast(int size)
70+
{
71+
if ((Count -= size) < 0)
72+
ThrowIndexOutOfRangeException();
73+
}
74+
[MethodImpl(256)]
6975
public SimpleList<T> Reverse()
7076
{
7177
Array.Reverse(data, 0, Count);

Test/ac-library-csharp.Test/Internal/SimpleListTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ public void AddAndRemove()
4646
list.Should().Equal(1, 2, 3, 4, 5, 7);
4747
}
4848

49+
[Fact]
50+
public void RemoveLastSize()
51+
{
52+
var list = new SimpleList<int>
53+
{
54+
1,2,3,4,5,6
55+
};
56+
list.Should().Equal(1, 2, 3, 4, 5, 6);
57+
list.RemoveLast(2);
58+
list.Should().Equal(1, 2, 3, 4);
59+
list.RemoveLast(4);
60+
list.Should().BeEmpty();
61+
}
62+
4963
[Fact]
5064
public void Reverse()
5165
{

0 commit comments

Comments
 (0)