using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
using Robust.UnitTesting.Server;
namespace Robust.UnitTesting.Shared.Map;
[TestFixture]
internal sealed class MapGridMap_Tests
{
///
/// Asserts FindGrids only returns the map once.
///
[Test]
public void FindGrids()
{
var sim = RobustServerSimulation.NewSimulation().InitializeInstance();
var entManager = sim.Resolve();
var mapSystem = entManager.System();
var mapId = sim.CreateMap().MapId;
List> grids = [];
mapSystem.FindGridsIntersecting(mapId, Box2.UnitCentered, ref grids);
Assert.That(grids, Is.Empty);
entManager.AddComponent(mapSystem.GetMapOrInvalid(mapId));
mapSystem.FindGridsIntersecting(mapId, Box2.UnitCentered, ref grids);
Assert.That(grids, Has.Count.EqualTo(1));
}
///
/// Asserts that adding to an existing map with a grid on it doesn't explode.
///
[Test]
public void AddGridCompToMap()
{
var sim = RobustServerSimulation.NewSimulation().InitializeInstance();
var entManager = sim.Resolve();
var mapSystem = entManager.System();
var mapId = sim.CreateMap().MapId;
mapSystem.CreateGridEntity(mapId);
Assert.DoesNotThrow(() =>
{
entManager.AddComponent(mapSystem.GetMapOrInvalid(mapId));
entManager.TickUpdate(0.016f, false);
});
mapSystem.DeleteMap(mapId);
}
}