ModernUO/Projects/Server.Tests/Tests/Maps/MultiEnumeratorTests.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

379 lines
10 KiB
C#

using System;
using System.Collections.Generic;
using Server.Items;
using Xunit;
namespace Server.Tests.Maps;
[Collection("Sequential Server Tests")]
public class MultiEnumeratorTests
{
[Fact]
public void MultiEnumerator_FiltersByBoundsAndOrder()
{
var map = Map.Felucca;
var rect = new Rectangle2D(100, 100, 32, 32);
var multis = new TestMulti[3];
try
{
multis[0] = CreateMulti(map, new Point3D(105, 105, 0));
multis[1] = CreateMulti(map, new Point3D(130, 130, 0));
multis[2] = CreateMulti(map, new Point3D(90, 90, 0));
var found = new List<BaseMulti>();
foreach (var multi in map.GetMultisInBounds<BaseMulti>(rect))
{
found.Add(multi);
}
Assert.Equal(2, found.Count);
Assert.All(found, multi => Assert.True(rect.Contains(multi.Location)));
Assert.Equal(new[] { multis[0], multis[1] }, found);
}
finally
{
DeleteAll(multis);
}
}
[Fact]
public void MultiEnumerator_DeletedMultisAreSkipped()
{
var map = Map.Felucca;
var rect = new Rectangle2D(200, 200, 16, 16);
var multis = new TestMulti[3];
try
{
multis[0] = CreateMulti(map, new Point3D(205, 205, 0));
multis[1] = CreateMulti(map, new Point3D(206, 205, 0));
multis[2] = CreateMulti(map, new Point3D(207, 205, 0));
multis[1].Delete();
var found = new List<BaseMulti>();
foreach (var multi in map.GetMultisInBounds<BaseMulti>(rect))
{
found.Add(multi);
}
Assert.Equal(new[] { multis[0], multis[2] }, found);
}
finally
{
DeleteAll(multis);
}
}
[Fact]
public void MultiEnumerator_RespectsMakeBoundsInclusiveFlag()
{
var map = Map.Felucca;
var rect = new Rectangle2D(300, 300, 1, 1);
var multis = new TestMulti[1];
try
{
multis[0] = CreateMulti(map, new Point3D(301, 301, 0));
var enumerator = map.GetMultisInBounds<BaseMulti>(rect, makeBoundsInclusive: true).GetEnumerator();
Assert.True(enumerator.MoveNext());
Assert.Equal(multis[0], enumerator.Current);
}
finally
{
DeleteAll(multis);
}
}
[Fact]
public void MultiEnumerator_ThrowsOnVersionChange()
{
var map = Map.Felucca;
var rect = new Rectangle2D(400, 400, 16, 16);
var multis = new[]
{
CreateMulti(map, new Point3D(405, 405, 0)),
CreateMulti(map, new Point3D(406, 405, 0))
};
try
{
var enumerator = map.GetMultisInBounds<BaseMulti>(rect).GetEnumerator();
Assert.True(enumerator.MoveNext());
multis[1].Delete();
// Ref structs cannot be captured in lambdas, so we test the exception directly
var exceptionThrown = false;
try
{
enumerator.MoveNext();
}
catch (InvalidOperationException)
{
exceptionThrown = true;
}
Assert.True(exceptionThrown, "Expected InvalidOperationException when collection version changes");
}
finally
{
DeleteAll(multis);
}
}
[Fact]
public void MultiEnumerator_StepsAcrossSectors()
{
var map = Map.Felucca;
var rect = new Rectangle2D(500, 500, Map.SectorSize * 2, Map.SectorSize * 2);
var multis = new[]
{
CreateMulti(map, new Point3D(rect.X + 1, rect.Y + 1, 0)),
CreateMulti(map, new Point3D(rect.X + Map.SectorSize + 1, rect.Y + 1, 0)),
CreateMulti(map, new Point3D(rect.X + Map.SectorSize + 1, rect.Y + Map.SectorSize + 1, 0))
};
try
{
var result = new List<BaseMulti>();
foreach (var multi in map.GetMultisInBounds<BaseMulti>(rect))
{
result.Add(multi);
}
Assert.Equal(multis, result);
}
finally
{
DeleteAll(multis);
}
}
[Fact]
public void MultiEnumerator_MapBoundsAreClamped()
{
var map = Map.Felucca;
var width = map.Width;
var height = map.Height;
var rect = new Rectangle2D(width - Map.SectorSize - 2, height - Map.SectorSize - 2, Map.SectorSize * 2, Map.SectorSize * 2);
var multis = new[]
{
CreateMulti(map, new Point3D(width - 2, height - 2, 0))
};
try
{
var enumerator = map.GetMultisInBounds<BaseMulti>(rect).GetEnumerator();
Assert.True(enumerator.MoveNext());
Assert.Equal(multis[0], enumerator.Current);
Assert.False(enumerator.MoveNext());
}
finally
{
DeleteAll(multis);
}
}
[Fact]
public void MultiEnumerator_GetMultisInRange()
{
var map = Map.Felucca;
var center = new Point3D(600, 600, 0);
var range = 5;
var multis = new TestMulti[3];
try
{
multis[0] = CreateMulti(map, new Point3D(602, 602, 0)); // Within range
multis[1] = CreateMulti(map, new Point3D(598, 598, 0)); // Within range
multis[2] = CreateMulti(map, new Point3D(610, 610, 0)); // Outside range
var found = new List<BaseMulti>();
foreach (var multi in map.GetMultisInRange<BaseMulti>(center, range))
{
found.Add(multi);
}
Assert.Equal(2, found.Count);
Assert.Contains(multis[0], found);
Assert.Contains(multis[1], found);
Assert.DoesNotContain(multis[2], found);
}
finally
{
DeleteAll(multis);
}
}
[Fact]
public void MultiSectorEnumerator_FiltersToSingleSector()
{
var map = Map.Felucca;
var location = new Point3D(700, 700, 0);
var multis = new TestMulti[2];
try
{
multis[0] = CreateMulti(map, location);
multis[1] = CreateMulti(map, new Point3D(location.X + 1, location.Y, 0));
var found = new List<BaseMulti>();
foreach (var multi in map.GetMultisInSector<BaseMulti>(location))
{
found.Add(multi);
}
// Both should be in the same sector
Assert.Equal(2, found.Count);
Assert.Contains(multis[0], found);
Assert.Contains(multis[1], found);
}
finally
{
DeleteAll(multis);
}
}
[Fact]
public void MultiSectorEnumerator_MapNullYieldsEmpty()
{
var enumerator = new Map.MultiSectorEnumerable<BaseMulti>(null, new Point2D(0, 0)).GetEnumerator();
Assert.False(enumerator.MoveNext());
}
[Fact]
public void MultiEnumerator_ZeroRangeReturnsOnlyCenter()
{
var map = Map.Felucca;
var center = new Point3D(800, 800, 0);
const int range = 0;
var multis = new TestMulti[2];
try
{
multis[0] = CreateMulti(map, center); // Exact center
multis[1] = CreateMulti(map, new Point3D(801, 800, 0)); // 1 tile away
var found = new List<BaseMulti>();
foreach (var multi in map.GetMultisInRange<BaseMulti>(center, range))
{
found.Add(multi);
}
Assert.Single(found);
Assert.Equal(multis[0], found[0]);
}
finally
{
DeleteAll(multis);
}
}
[Fact]
public void MultiEnumerator_NegativeRangeCreates1x1Bounds()
{
var map = Map.Felucca;
var center = new Point3D(850, 850, 0);
const int range = -5;
var multis = new TestMulti[2];
try
{
multis[0] = CreateMulti(map, center);
multis[1] = CreateMulti(map, new Point3D(851, 850, 0)); // 1 tile away
var found = new List<BaseMulti>();
foreach (var multi in map.GetMultisInRange<BaseMulti>(center, range))
{
found.Add(multi);
}
// With negative range creating a 1x1 bounds, only exact center matches
Assert.Single(found);
Assert.Equal(multis[0], found[0]);
}
finally
{
DeleteAll(multis);
}
}
[Fact]
public void MultiEnumerator_NestedQueryDoesNotDisturbOuterDeduplication()
{
var map = Map.Felucca;
// Components reach two tiles either side, so at x = 1024 the multi spans sectors 63 and 64
var spanning = new SpanningMulti();
try
{
spanning.MoveToWorld(new Point3D(1024, 1000, 0), map);
var found = new List<BaseMulti>();
foreach (var multi in map.GetMultisInBounds<BaseMulti>(new Rectangle2D(1000, 990, 48, 20)))
{
found.Add(multi);
foreach (var _ in map.GetMultisInBounds<BaseMulti>(new Rectangle2D(3000, 3000, 4, 4)))
{
}
}
Assert.Equal([spanning], found);
}
finally
{
spanning.Delete();
}
}
private static TestMulti CreateMulti(Map map, Point3D location)
{
var multi = new TestMulti();
multi.MoveToWorld(location, map);
return multi;
}
private static void DeleteAll(TestMulti[] multis)
{
for (var i = 0; i < multis.Length; i++)
{
multis[i]?.Delete();
}
}
// Test implementation of BaseMulti
private class TestMulti : BaseMulti
{
public TestMulti() : base(0x1)
{
}
}
private class SpanningMulti : BaseMulti
{
// Entries after the first need non-zero flags or MultiComponentList drops them
private static readonly MultiComponentList _components = new(
[
new MultiTileEntry(0x1, -2, 0, 0, TileFlag.Background),
new MultiTileEntry(0x1, 2, 0, 0, TileFlag.Background)
]
);
public SpanningMulti() : base(0x1)
{
}
public override MultiComponentList Components => _components;
}
}