Skip to content

Fix StructuralSparseArray Clear function and add basic test #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
57 changes: 57 additions & 0 deletions src/Arch.Tests/StructuralSparseArrayTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Arch.Buffer;

namespace Arch.Tests;

[TestFixture]
public sealed partial class StructuralSparseArrayTest
{
private static void TestEquivalent(StructuralSparseArray test, HashSet<int> control)
{
// Brute force test every index
for (int i = 0; i < 128; i++)
{
bool contains = control.Contains(i);
Assert.That(test.Contains(i), Is.EqualTo(contains));
}
}

[Test]
public void ClearAndAccessMany()
{
var test = new StructuralSparseArray(new(1, 0));
var control = new HashSet<int>();

for (int i = 0; i < 10; i++)
{
control.Add(52 + i);
test.Add(52 + i);

TestEquivalent(test, control);

control.Add(3 + i);
test.Add(3 + i);

TestEquivalent(test, control);

control.Clear();
test.Clear();

TestEquivalent(test, control);

control.Add(3);
test.Add(3);

TestEquivalent(test, control);

control.Add(3);
test.Add(3);

TestEquivalent(test, control);

control.Clear();
test.Clear();

TestEquivalent(test, control);
}
}
}
2 changes: 1 addition & 1 deletion src/Arch/Buffer/StructuralSparseSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public bool Contains(int index)
/// </summary>
public void Clear()
{
Array.Fill(Entities, -1, 0, Size);
Array.Fill(Entities, -1, 0, Entities.Length);
Size = 0;
}
}
Expand Down
Loading