140 lines
4.2 KiB
C#
140 lines
4.2 KiB
C#
using NUnit.Framework;
|
|
using Framework.Wrapper;
|
|
using NLD.Editor.PVPDebugBattle;
|
|
|
|
public class PVPDebugBattlePresetTests
|
|
{
|
|
[Test]
|
|
public void Validate_ReturnsError_WhenSelfTeamIsEmpty()
|
|
{
|
|
var preset = CreatePreset();
|
|
preset.selfUnits.Clear();
|
|
|
|
var valid = PVPDebugBattleValidator.Validate(preset, false, out var error);
|
|
|
|
Assert.IsFalse(valid);
|
|
StringAssert.Contains("己方阵容为空", error);
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_ReturnsError_WhenCellIndexIsInvalid()
|
|
{
|
|
var preset = CreatePreset();
|
|
preset.enemyUnits[0].cellIndex = -1;
|
|
|
|
var valid = PVPDebugBattleValidator.Validate(preset, false, out var error);
|
|
|
|
Assert.IsFalse(valid);
|
|
StringAssert.Contains("敌方第1个单位 cellIndex 无效", error);
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_ReturnsError_WhenSameSideCellIndexIsDuplicated()
|
|
{
|
|
var preset = CreatePreset();
|
|
preset.selfUnits.Add(new PVPDebugBattleUnit
|
|
{
|
|
unitType = Unit.UnitType.Charactor,
|
|
unitID = 1002,
|
|
cellIndex = preset.selfUnits[0].cellIndex
|
|
});
|
|
|
|
var valid = PVPDebugBattleValidator.Validate(preset, false, out var error);
|
|
|
|
Assert.IsFalse(valid);
|
|
StringAssert.Contains("己方 cellIndex 重复", error);
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_ReturnsTrue_ForMinimalValidPreset()
|
|
{
|
|
var preset = CreatePreset();
|
|
|
|
var valid = PVPDebugBattleValidator.Validate(preset, false, out var error);
|
|
|
|
Assert.IsTrue(valid);
|
|
Assert.IsEmpty(error);
|
|
}
|
|
|
|
[Test]
|
|
public void CreateCharacter_SetsCharacterTypeAndUnitId()
|
|
{
|
|
var unit = PVPDebugBattleUnit.CreateCharacter(1001);
|
|
|
|
Assert.AreEqual(Unit.UnitType.Charactor, unit.unitType);
|
|
Assert.AreEqual(1001, unit.unitID);
|
|
Assert.AreEqual(1, unit.level);
|
|
Assert.AreEqual(1, unit.skillLevel0);
|
|
Assert.AreEqual(1, unit.skillLevel1);
|
|
Assert.AreEqual(1, unit.skillLevel2);
|
|
}
|
|
|
|
[Test]
|
|
public void CreateVehicle_SetsVehicleTypeAndUnitId()
|
|
{
|
|
var unit = PVPDebugBattleUnit.CreateVehicle(2001);
|
|
|
|
Assert.AreEqual(Unit.UnitType.Vehicle, unit.unitType);
|
|
Assert.AreEqual(2001, unit.unitID);
|
|
Assert.IsNotNull(unit.vehicleComponents);
|
|
Assert.IsNotNull(unit.paintSet);
|
|
}
|
|
|
|
[Test]
|
|
public void GetUsedCells_ExcludesCurrentUnit()
|
|
{
|
|
var units = new System.Collections.Generic.List<PVPDebugBattleUnit>
|
|
{
|
|
new PVPDebugBattleUnit { cellIndex = 5 },
|
|
new PVPDebugBattleUnit { cellIndex = 9 },
|
|
new PVPDebugBattleUnit { cellIndex = 12 }
|
|
};
|
|
|
|
var usedCells = PVPDebugBattleCellPickerUtility.GetUsedCells(units, 1);
|
|
|
|
CollectionAssert.Contains(usedCells, 5);
|
|
CollectionAssert.Contains(usedCells, 12);
|
|
CollectionAssert.DoesNotContain(usedCells, 9);
|
|
}
|
|
|
|
[Test]
|
|
public void GetFlatTopHexCenter_OffsetsOddColumns()
|
|
{
|
|
var first = PVPDebugBattleCellPickerUtility.GetFlatTopHexCenter(0, 0, 40f, 34f);
|
|
var second = PVPDebugBattleCellPickerUtility.GetFlatTopHexCenter(0, 1, 40f, 34f);
|
|
|
|
Assert.AreEqual(20f, first.x);
|
|
Assert.AreEqual(17f, first.y);
|
|
Assert.AreEqual(50f, second.x);
|
|
Assert.AreEqual(34f, second.y);
|
|
}
|
|
|
|
[Test]
|
|
public void ResolveMoveGuid_DoesNotFallbackToConfigUnitId()
|
|
{
|
|
const uint configUnitId = 100001;
|
|
const uint runtimeGuid = 1234567;
|
|
|
|
Assert.AreEqual(runtimeGuid, PVPDebugBattleContext.ResolveMoveGuid(configUnitId, runtimeGuid));
|
|
Assert.AreEqual(0, PVPDebugBattleContext.ResolveMoveGuid(configUnitId, 0));
|
|
}
|
|
|
|
private static PVPDebugBattlePreset CreatePreset()
|
|
{
|
|
var preset = UnityEngine.ScriptableObject.CreateInstance<PVPDebugBattlePreset>();
|
|
preset.selfUnits.Add(new PVPDebugBattleUnit
|
|
{
|
|
unitType = Unit.UnitType.Charactor,
|
|
unitID = 1001,
|
|
cellIndex = 1
|
|
});
|
|
preset.enemyUnits.Add(new PVPDebugBattleUnit
|
|
{
|
|
unitType = Unit.UnitType.Charactor,
|
|
unitID = 2001,
|
|
cellIndex = 2
|
|
});
|
|
return preset;
|
|
}
|
|
}
|