93 lines
3.7 KiB
C#
93 lines
3.7 KiB
C#
using System.Collections.Generic;
|
||
using GeometryTD.CustomUtility;
|
||
using GeometryTD.Definition;
|
||
using NUnit.Framework;
|
||
|
||
namespace GeometryTD.Tests.EditMode
|
||
{
|
||
public sealed class ItemDescUtilityTests
|
||
{
|
||
[Test]
|
||
public void BuildMuzzleDesc_Appends_Broken_Status_When_Endurance_Is_Zero()
|
||
{
|
||
string description = ItemDescUtility.BuildMuzzleDesc(new MuzzleCompItemData
|
||
{
|
||
AttackDamage = new[] { 10 },
|
||
DamageRandomRate = 0.1f,
|
||
AttackMethodType = AttackMethodType.NormalBullet,
|
||
Endurance = 0f
|
||
});
|
||
|
||
StringAssert.Contains("当前耐久:0", description);
|
||
StringAssert.Contains("状态:已损坏,无法参战。", description);
|
||
}
|
||
|
||
[Test]
|
||
public void BuildTowerDesc_Appends_Broken_Status_And_Restriction_When_Component_Is_Broken()
|
||
{
|
||
TowerItemData tower = CreateTower();
|
||
Dictionary<long, MuzzleCompItemData> muzzleMap = new Dictionary<long, MuzzleCompItemData>
|
||
{
|
||
[10001] = new MuzzleCompItemData { InstanceId = 10001, Endurance = 0f }
|
||
};
|
||
Dictionary<long, BearingCompItemData> bearingMap = new Dictionary<long, BearingCompItemData>
|
||
{
|
||
[20001] = new BearingCompItemData { InstanceId = 20001, Endurance = 100f }
|
||
};
|
||
Dictionary<long, BaseCompItemData> baseMap = new Dictionary<long, BaseCompItemData>
|
||
{
|
||
[30001] = new BaseCompItemData { InstanceId = 30001, Endurance = 100f }
|
||
};
|
||
|
||
string description = ItemDescUtility.BuildTowerDesc(tower, muzzleMap, bearingMap, baseMap);
|
||
|
||
StringAssert.Contains("状态:已损坏", description);
|
||
StringAssert.Contains("参战限制:枪口组件耐久为 0,无法参战。", description);
|
||
}
|
||
|
||
[Test]
|
||
public void BuildTowerDesc_Does_Not_Append_Broken_Status_When_Tower_Is_Valid()
|
||
{
|
||
TowerItemData tower = CreateTower();
|
||
Dictionary<long, MuzzleCompItemData> muzzleMap = new Dictionary<long, MuzzleCompItemData>
|
||
{
|
||
[10001] = new MuzzleCompItemData { InstanceId = 10001, Endurance = 100f }
|
||
};
|
||
Dictionary<long, BearingCompItemData> bearingMap = new Dictionary<long, BearingCompItemData>
|
||
{
|
||
[20001] = new BearingCompItemData { InstanceId = 20001, Endurance = 100f }
|
||
};
|
||
Dictionary<long, BaseCompItemData> baseMap = new Dictionary<long, BaseCompItemData>
|
||
{
|
||
[30001] = new BaseCompItemData { InstanceId = 30001, Endurance = 100f }
|
||
};
|
||
|
||
string description = ItemDescUtility.BuildTowerDesc(tower, muzzleMap, bearingMap, baseMap);
|
||
|
||
StringAssert.DoesNotContain("状态:已损坏", description);
|
||
StringAssert.DoesNotContain("参战限制:", description);
|
||
}
|
||
|
||
private static TowerItemData CreateTower()
|
||
{
|
||
return new TowerItemData
|
||
{
|
||
InstanceId = 90001,
|
||
MuzzleComponentInstanceId = 10001,
|
||
BearingComponentInstanceId = 20001,
|
||
BaseComponentInstanceId = 30001,
|
||
Stats = new TowerStatsData
|
||
{
|
||
AttackDamage = new[] { 10 },
|
||
DamageRandomRate = 0.1f,
|
||
AttackMethodType = AttackMethodType.NormalBullet,
|
||
RotateSpeed = new[] { 1f },
|
||
AttackRange = new[] { 2f },
|
||
AttackSpeed = new[] { 1f },
|
||
AttackPropertyType = AttackPropertyType.Physics
|
||
}
|
||
};
|
||
}
|
||
}
|
||
}
|