Files
RobustToolbox/Robust.Shared.Tests/Collections/RingBufferListTest.cs
T
PJB3005 788e9386fd Split up test project
Robust.UnitTesting was both ALL tests for RT, and also API surface for content tests.

Tests are now split into separate projects as appropriate, and the API side has also been split off.
2025-12-16 01:36:53 +01:00

96 lines
2.2 KiB
C#

using NUnit.Framework;
using Robust.Shared.Collections;
namespace Robust.Shared.Tests.Collections;
[Parallelizable(ParallelScope.All | ParallelScope.Fixtures)]
[TestFixture, TestOf(typeof(RingBufferList<>))]
internal sealed class RingBufferListTest
{
[Test]
public void TestBasicAdd()
{
var list = new RingBufferList<int>();
list.Add(1);
list.Add(2);
list.Add(3);
Assert.That(list, Is.EquivalentTo(new[] {1, 2, 3}));
}
[Test]
public void TestBasicAddAfterWrap()
{
var list = new RingBufferList<int>(6);
list.Add(1);
list.Add(2);
list.Add(3);
list.RemoveAt(0);
list.Add(4);
list.Add(5);
list.Add(6);
Assert.Multiple(() =>
{
// Ensure wrapping properly happened and we didn't expand.
// (one slot is wasted by nature of implementation)
Assert.That(list.Capacity, Is.EqualTo(6));
Assert.That(list, Is.EquivalentTo(new[] { 2, 3, 4, 5, 6 }));
});
}
[Test]
public void TestMiddleRemoveAtScenario1()
{
var list = new RingBufferList<int>(6);
list.Add(-1);
list.Add(-1);
list.Add(-1);
list.Add(-1);
list.Add(1);
list.RemoveAt(0);
list.RemoveAt(0);
list.RemoveAt(0);
list.RemoveAt(0);
list.Add(2);
list.Add(3);
list.Add(4);
list.Add(5);
list.Remove(4);
Assert.That(list, Is.EquivalentTo(new[] {1, 2, 3, 5}));
}
[Test]
public void TestMiddleRemoveAtScenario2()
{
var list = new RingBufferList<int>(6);
list.Add(-1);
list.Add(-1);
list.Add(1);
list.RemoveAt(0);
list.RemoveAt(0);
list.Add(2);
list.Add(3);
list.Add(4);
list.Add(5);
list.Remove(3);
Assert.That(list, Is.EquivalentTo(new[] {1, 2, 4, 5}));
}
[Test]
public void TestMiddleRemoveAtScenario3()
{
var list = new RingBufferList<int>(6);
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(4);
list.Add(5);
list.Remove(4);
Assert.That(list, Is.EquivalentTo(new[] {1, 2, 3, 5}));
}
}