ModernUO/Projects/Server.Tests/Tests/Maps/CanFitItemTests.cs
Kamron Batman 9a25054809
test: remove trivial, duplicate and content-value tests (#2721)
## Summary
Many tests proved a specific change when it landed but don't need to run on every CI build forever. This removes **202 test methods and 9 files: 313 test cases, 2,247 → 1,934**. UOContent.Tests drops from about 14s to about 5s locally.

Removed:
- **Tautologies.** Asserting a constant, a constructor readback or a trivial getter, or testing BCL behavior.
- **Exact duplicates** of a surviving test on the same code path.
- **Obsolete regressions** whose failure can no longer be expressed.
- **Game-content values** shard owners customize (era drop rates, loot and skill tables, single-creature tuning). Each customization would otherwise force a test fix.

## How it was decided
1. Every test was classified, with a reason, by a per-shard sweep over all 287 test files.
2. Each proposed deletion was then checked by a second, adversarial reviewer against the surviving tests and the production code.
3. Anything that was the only coverage of a separate code path was **kept**, even where it looked like a duplicate. Examples: the unsigned `SpanReader`/`SpanWriter` methods, the at-location versus bounds enumerators, null-map enumerables, the security filters, archive-journal state transitions. About 130 proposed deletions were rejected this way.

Whole files removed:
- `FishingTests`, apart from 3 tests: the map-edge scan, serpent cleanup, and SOS chest consumption. The SOS test now stops at the first chest instead of measuring a catch rate. The multi-million-cast rate simulations are gone.
- `LordOaksTests` and `MeerEnragedTests` (single-creature tests).
- `AutoArchiveHelperTests`, `JsonDiscoverableTypeAttributeTests`, `DecimalSerializationTests` and `EnumConversionTests` (tautologies, or tests of their own local helpers).
- `NetworkStatsTests`.
- `MigratedDataLoadTests` (a subset of `AllSpawnFilesLoadTests`).
- `SpawnerFixtureCapture`: a capture tool, not a test, and its `version == 12` assert can no longer pass. The `.bin` fixtures it produced stay.

## Tests
- Server.Tests: 811 pass.
- UOContent.Tests: 1,123 pass.

A follow-up PR, stacked on this one, fixes how the remaining tests behave: shared state, CI-vacuous tests, harness duplication.
2026-10-18 20:08:19 -07:00

263 lines
7.9 KiB
C#

using Server.Items;
using Xunit;
namespace Server.Tests.Maps;
/// <summary>
/// Tests for CanFitItem which allows Surface+Impassable tiles (tables, furniture) as valid surfaces.
/// </summary>
[Collection("Sequential Server Tests")]
public class CanFitItemTests
{
private void SkipIfNoTileData()
{
Skip.If(!ServerFixture.TileDataLoaded, "TileData not loaded - client files required");
}
[Fact]
public void CanFitItem_InternalMapReturnsFalse()
{
var result = Map.Internal.CanFitItem(100, 100, 0, 1);
Assert.False(result);
}
[Fact]
public void CanFitItem_InvalidCoordinatesReturnsFalse()
{
var map = Map.Felucca;
Assert.False(map.CanFitItem(-1, 100, 0, 1));
Assert.False(map.CanFitItem(100, -1, 0, 1));
Assert.False(map.CanFitItem(map.Width + 1, 100, 0, 1));
Assert.False(map.CanFitItem(100, map.Height + 1, 0, 1));
}
private const int TestLandX = 1500;
private const int TestLandY = 1600;
[Fact]
public void CanFitItem_LandSurfaceReturnsTrue()
{
var map = Map.Felucca;
var avgZ = map.GetAverageZ(TestLandX, TestLandY);
var result = map.CanFitItem(TestLandX, TestLandY, avgZ, 1);
Assert.True(result, $"Expected land at Z={avgZ} to be valid surface for items");
}
[Fact]
public void CanFitItem_AboveLandWithNoSurfaceReturnsFalse()
{
var map = Map.Felucca;
var avgZ = map.GetAverageZ(TestLandX, TestLandY);
// Try to place item 50 units above land with no surface there
var result = map.CanFitItem(TestLandX, TestLandY, avgZ + 50, 1);
Assert.False(result, "No surface 50 units above land");
}
[SkippableFact]
public void CanFitItem_SurfaceImpassableMultiIsValidSurface()
{
SkipIfNoTileData();
Skip.If(ServerFixture.SurfaceImpassableTileId == 0, "No Surface+Impassable tile found in TileData");
var map = Map.Felucca;
const int x = 1700;
const int y = 1700;
TestMulti multi = null;
try
{
// Get the actual tile height from TileData
var tileData = TileData.ItemTable[ServerFixture.SurfaceImpassableTileId];
var tileHeight = tileData.CalcHeight;
const int tileZ = 10;
// Create a multi with a Surface+Impassable tile (like a table) at Z=10
multi = CreateSurfaceImpassableMulti(map, new Point3D(x, y, 0), surfaceZ: tileZ);
// CanFitItem should treat Surface+Impassable as a valid surface
var surfaceTop = tileZ + tileHeight;
var result = map.CanFitItem(x, y, surfaceTop, 1);
Assert.True(result, $"Surface+Impassable tile should be valid surface for items at Z={surfaceTop}");
}
finally
{
multi?.Delete();
}
}
[SkippableFact]
public void CanFitItem_CanFitDoesNotAllowSurfaceImpassable()
{
SkipIfNoTileData();
Skip.If(ServerFixture.SurfaceImpassableTileId == 0, "No Surface+Impassable tile found in TileData");
var map = Map.Felucca;
const int x = 1750;
const int y = 1750;
TestMulti multi = null;
try
{
// Get the actual tile height from TileData
var tileData = TileData.ItemTable[ServerFixture.SurfaceImpassableTileId];
var tileHeight = tileData.CalcHeight;
const int tileZ = 10;
// Create a multi with a Surface+Impassable tile at Z=10
multi = CreateSurfaceImpassableMulti(map, new Point3D(x, y, 0), surfaceZ: tileZ);
var surfaceTop = tileZ + tileHeight;
// Regular CanFit should NOT treat Surface+Impassable as valid (for comparison)
var canFitResult = map.CanFit(x, y, surfaceTop, 1, requireSurface: true);
// This test documents the difference between CanFit and CanFitItem
// CanFit requires surface && !impassable
Assert.False(canFitResult, "CanFit should NOT allow Surface+Impassable as valid surface");
}
finally
{
multi?.Delete();
}
}
[SkippableFact]
public void CanFitItem_NonMovableWorldItemSurfaceWorks()
{
SkipIfNoTileData();
var map = Map.Felucca;
const int x = 1800;
const int y = 1800;
Item surfaceItem = null;
try
{
// Create a non-movable surface item (like a placed table)
surfaceItem = new Item(ServerFixture.SurfaceTileId)
{
Movable = false
};
surfaceItem.MoveToWorld(new Point3D(x, y, 10), map);
var itemTop = 10 + surfaceItem.ItemData.CalcHeight;
var result = map.CanFitItem(x, y, itemTop, 1);
Assert.True(result, $"Non-movable surface item should be valid surface at Z={itemTop}");
}
finally
{
surfaceItem?.Delete();
}
}
[SkippableFact]
public void CanFitItem_MovableWorldItemNotValidSurface()
{
SkipIfNoTileData();
var map = Map.Felucca;
const int x = 1850;
const int y = 1850;
Item movableItem = null;
try
{
// Create a movable surface item
movableItem = new Item(ServerFixture.SurfaceTileId)
{
Movable = true
};
movableItem.MoveToWorld(new Point3D(x, y, 10), map);
var itemTop = 10 + movableItem.ItemData.CalcHeight;
// Try placing at item top - should fail unless there's land there too
var avgZ = map.GetAverageZ(x, y);
// If avgZ != itemTop, there's no other surface, so it should fail
if (avgZ != itemTop)
{
var result = map.CanFitItem(x, y, itemTop, 1);
Assert.False(result, "Movable item should not count as valid surface");
}
}
finally
{
movableItem?.Delete();
}
}
[SkippableFact]
public void CanFitItem_ImpassableTileBlocksPlacement()
{
SkipIfNoTileData();
var map = Map.Felucca;
const int x = 1900;
const int y = 1900;
TestMulti multi = null;
try
{
// Create a multi with an impassable blocker at Z=10
multi = CreateImpassableMulti(map, new Point3D(x, y, 0), blockerZ: 10);
// Try to place item at Z=10 (inside the blocker)
var result = map.CanFitItem(x, y, 10, 5);
Assert.False(result, "Should not be able to place item inside impassable tile");
}
finally
{
multi?.Delete();
}
}
private TestMulti CreateSurfaceImpassableMulti(Map map, Point3D location, int surfaceZ)
{
// Use SurfaceImpassableTileId - a tile that has both Surface and Impassable flags
var multi = new TestMulti(new MultiComponentList(
[
new MultiTileEntry(
ServerFixture.SurfaceImpassableTileId,
0, 0, (short)surfaceZ,
TileFlag.Surface | TileFlag.Impassable
)
]));
multi.MoveToWorld(location, map);
return multi;
}
private TestMulti CreateImpassableMulti(Map map, Point3D location, int blockerZ)
{
var multi = new TestMulti(new MultiComponentList(
[
new MultiTileEntry(
ServerFixture.ImpassableTileId,
0, 0, (short)blockerZ,
TileFlag.Impassable
)
]));
multi.MoveToWorld(location, map);
return multi;
}
private class TestMulti : BaseMulti
{
private readonly MultiComponentList _components;
public TestMulti(MultiComponentList components) : base(0x1)
{
_components = components ?? MultiComponentList.Empty;
}
public override MultiComponentList Components => _components;
}
}