Skip to content

Commit 439bd13

Browse files
authored
Fix StructuralSparseArray clear function and add basic test (#273)
Co-authored-by: DESKTOP-O6U9TBJ\Lilith <as>
1 parent 719dff2 commit 439bd13

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using Arch.Buffer;
2+
3+
namespace Arch.Tests;
4+
5+
[TestFixture]
6+
public sealed partial class StructuralSparseArrayTest
7+
{
8+
private static void TestEquivalent(StructuralSparseArray test, HashSet<int> control)
9+
{
10+
// Brute force test every index
11+
for (int i = 0; i < 128; i++)
12+
{
13+
bool contains = control.Contains(i);
14+
Assert.That(test.Contains(i), Is.EqualTo(contains));
15+
}
16+
}
17+
18+
[Test]
19+
public void ClearAndAccessMany()
20+
{
21+
var test = new StructuralSparseArray(new(1, 0));
22+
var control = new HashSet<int>();
23+
24+
for (int i = 0; i < 10; i++)
25+
{
26+
control.Add(52 + i);
27+
test.Add(52 + i);
28+
29+
TestEquivalent(test, control);
30+
31+
control.Add(3 + i);
32+
test.Add(3 + i);
33+
34+
TestEquivalent(test, control);
35+
36+
control.Clear();
37+
test.Clear();
38+
39+
TestEquivalent(test, control);
40+
41+
control.Add(3);
42+
test.Add(3);
43+
44+
TestEquivalent(test, control);
45+
46+
control.Add(3);
47+
test.Add(3);
48+
49+
TestEquivalent(test, control);
50+
51+
control.Clear();
52+
test.Clear();
53+
54+
TestEquivalent(test, control);
55+
}
56+
}
57+
}

src/Arch/Buffer/StructuralSparseSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public bool Contains(int index)
103103
/// </summary>
104104
public void Clear()
105105
{
106-
Array.Fill(Entities, -1, 0, Size);
106+
Array.Fill(Entities, -1, 0, Entities.Length);
107107
Size = 0;
108108
}
109109
}

0 commit comments

Comments
 (0)