feat: add SyncList.RemoveAll (#1881)

* Added SyncList.RemoveAll and unit test.

* Added RemoveAllNone unit test for SyncList

* SyncList.RemoveAll cleanup

* RemoveAll no longer calls collections .Add

Unit tests for SyncList.RemoveAll now check clientSyncList.
This commit is contained in:
Devon Merner 2020-05-11 04:27:32 -04:00 committed by GitHub
parent e9ea117e61
commit eb7c87d15a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -356,6 +356,21 @@ public void RemoveAt(int index)
AddOperation(Operation.OP_REMOVEAT, index, oldItem, default);
}
public int RemoveAll(Predicate<T> match)
{
List<T> toRemove = new List<T>();
for (int i = 0; i < objects.Count; ++i)
if (match(objects[i]))
toRemove.Add(objects[i]);
foreach (T entry in toRemove)
{
Remove(entry);
}
return toRemove.Count;
}
public T this[int i]
{
get => objects[i];

View File

@ -107,6 +107,22 @@ public void TestSetNull()
Assert.That(clientSyncList, Is.EquivalentTo(new[] { "Hello", "yay", "!" }));
}
[Test]
public void TestRemoveAll()
{
serverSyncList.RemoveAll(entry => entry.Contains("l"));
SerializeDeltaTo(serverSyncList, clientSyncList);
Assert.That(clientSyncList, Is.EquivalentTo(new[] { "!" }));
}
[Test]
public void TestRemoveAllNone()
{
serverSyncList.RemoveAll(entry => entry == "yay");
SerializeDeltaTo(serverSyncList, clientSyncList);
Assert.That(clientSyncList, Is.EquivalentTo(new[] { "Hello", "World", "!" }));
}
[Test]
public void TestRemoveAt()
{