using System.Collections.Generic;
using AcDream.Core.Physics;
using Xunit;
namespace AcDream.Core.Tests.Physics;
///
/// D8 (2026-06-24): verify that
/// evicts every cached cell belonging to the given landblock prefix and leaves
/// cells belonging to other landblocks untouched — symmetric with
/// (#146).
///
public class RemoveCellsForLandblockTests
{
///
/// Build the absolute minimum that satisfies the
/// required init property. BSP is left null because the test exercises
/// only the cache-eviction key logic, not BSP traversal.
///
private static CellPhysics BuildMinimalCell() => new()
{
Resolved = new Dictionary(),
};
[Fact]
public void RemoveCellsForLandblock_EvictsOnlyMatchingPrefix()
{
var cache = new PhysicsDataCache();
// Two cells from landblock 0xAAAA0000 and one from 0xBBBB0000.
cache.RegisterCellStructForTest(0xAAAA0100u, BuildMinimalCell());
cache.RegisterCellStructForTest(0xAAAA0200u, BuildMinimalCell());
cache.RegisterCellStructForTest(0xBBBB0100u, BuildMinimalCell());
cache.RemoveCellsForLandblock(0xAAAA0000u);
// Both AAAA cells must be gone.
Assert.Null(cache.GetCellStruct(0xAAAA0100u));
Assert.Null(cache.GetCellStruct(0xAAAA0200u));
// The BBBB cell must survive.
Assert.NotNull(cache.GetCellStruct(0xBBBB0100u));
}
[Fact]
public void RemoveCellsForLandblock_EmptyCache_DoesNotThrow()
{
// Must be a no-op on an empty cache.
var cache = new PhysicsDataCache();
cache.RemoveCellsForLandblock(0xAAAA0000u);
Assert.Equal(0, cache.CellStructCount);
}
[Fact]
public void RemoveCellsForLandblock_NoMatchingCells_LeavesOthersIntact()
{
var cache = new PhysicsDataCache();
cache.RegisterCellStructForTest(0xBBBB0100u, BuildMinimalCell());
// Evicting a prefix that has no cached entries should not disturb others.
cache.RemoveCellsForLandblock(0xAAAA0000u);
Assert.NotNull(cache.GetCellStruct(0xBBBB0100u));
Assert.Equal(1, cache.CellStructCount);
}
}