Ports retail CELLARRAY::add_cell (acclient_2013_pseudo_c.txt:701036): ordered list, dedup by cell_id, append at end. The order is load-bearing for the verbatim find_cell_list current-cell-first interior-wins pick (next commits) that fixes the R1 cottage membership flap. Implements ICollection<uint> (helper-facing) + IReadOnlyCollection<uint> (consumer-facing). 5 unit tests. Also lands the membership-port pseudocode (workflow step 3) + the Stage-1 plan. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using AcDream.Core.Physics;
|
|
using Xunit;
|
|
|
|
namespace AcDream.Core.Tests.Physics;
|
|
|
|
public class CellArrayTests
|
|
{
|
|
[Fact]
|
|
public void Add_PreservesInsertionOrder()
|
|
{
|
|
var a = new CellArray();
|
|
a.Add(0xA9B40170u);
|
|
a.Add(0xA9B40031u);
|
|
a.Add(0xA9B40171u);
|
|
Assert.Equal(new[] { 0xA9B40170u, 0xA9B40031u, 0xA9B40171u }, a.OrderedIds.ToArray());
|
|
}
|
|
|
|
[Fact]
|
|
public void Add_DedupsById_KeepingFirstPosition()
|
|
{
|
|
var a = new CellArray();
|
|
a.Add(0xA9B40170u);
|
|
a.Add(0xA9B40171u);
|
|
a.Add(0xA9B40170u); // duplicate of index 0 — no-op (retail add_cell)
|
|
Assert.Equal(2, a.Count);
|
|
Assert.Equal(new[] { 0xA9B40170u, 0xA9B40171u }, a.OrderedIds.ToArray());
|
|
}
|
|
|
|
[Fact]
|
|
public void Contains_TracksMembership()
|
|
{
|
|
var a = new CellArray();
|
|
a.Add(0xA9B40170u);
|
|
Assert.True(a.Contains(0xA9B40170u));
|
|
Assert.False(a.Contains(0xA9B40171u));
|
|
}
|
|
|
|
[Fact]
|
|
public void EnumeratesInInsertionOrder_AsICollection()
|
|
{
|
|
var a = new CellArray();
|
|
a.Add(3u); a.Add(1u); a.Add(2u);
|
|
ICollection<uint> c = a; // helper-facing interface
|
|
Assert.Equal(new[] { 3u, 1u, 2u }, c.ToArray());
|
|
}
|
|
|
|
[Fact]
|
|
public void IsReadOnlyCollection_ForConsumers()
|
|
{
|
|
var a = new CellArray();
|
|
a.Add(7u); a.Add(7u);
|
|
IReadOnlyCollection<uint> ro = a; // consumer-facing interface (FindCellSet out)
|
|
int count = ro.Count; // local avoids xUnit2013 (still exercises .Count)
|
|
Assert.Equal(1, count);
|
|
Assert.Equal(new[] { 7u }, ro.ToArray());
|
|
}
|
|
}
|