134 lines
4.2 KiB
C#
134 lines
4.2 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using ThreatSource.Equipment;
|
|
using ThreatSource.Simulation;
|
|
using ThreatSource.Utils;
|
|
|
|
namespace ThreatSource.Tests.Target
|
|
{
|
|
[TestClass]
|
|
public class TankTests
|
|
{
|
|
private readonly Tank _tank;
|
|
private readonly SimulationManager _simulationManager;
|
|
private const double BaseTargetDefaultInfraredSignature = 2500.0; // 匹配系统默认值
|
|
private const double BaseTargetDefaultRCS = 15.0; // 匹配系统默认值
|
|
|
|
public TankTests()
|
|
{
|
|
_simulationManager = new SimulationManager();
|
|
|
|
// 创建初始运动参数
|
|
var motionParameters = new MotionParameters
|
|
{
|
|
Position = new Vector3D(100, 0, 0),
|
|
Orientation = new Orientation(0, 0, 0),
|
|
InitialSpeed = 10
|
|
};
|
|
|
|
// 使用默认值初始化
|
|
var tankProperties = new EquipmentProperties();
|
|
_tank = new Tank("tank1", tankProperties, motionParameters, _simulationManager);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Constructor_InitializesPropertiesCorrectly()
|
|
{
|
|
// Arrange & Act
|
|
var motionParameters = new MotionParameters
|
|
{
|
|
Position = new Vector3D(200, 0, 0),
|
|
Orientation = new Orientation(0, 0, 0),
|
|
InitialSpeed = 10
|
|
};
|
|
|
|
var tankProperties = new EquipmentProperties
|
|
{
|
|
RadarCrossSection = 1.0,
|
|
InfraredRadiationIntensity = 10.0,
|
|
UltravioletRadiationIntensity = 10.0,
|
|
MillimeterWaveRadiationIntensity = 10.0
|
|
};
|
|
var tank = new Tank("tank2", tankProperties, motionParameters, _simulationManager);
|
|
// Assert
|
|
Assert.IsNotNull(tank);
|
|
Assert.AreEqual("tank2", tank.Id);
|
|
Assert.IsNotNull(tank.Position);
|
|
Assert.IsNotNull(tank.Velocity);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Update_UpdatesPositionBasedOnVelocity()
|
|
{
|
|
// Arrange
|
|
var initialPosition = _tank.Position;
|
|
var deltaTime = 1.0f;
|
|
|
|
// Act
|
|
_tank.Update(deltaTime);
|
|
|
|
// Assert
|
|
Assert.AreEqual(initialPosition.X + _tank.Velocity.X * deltaTime, _tank.Position.X);
|
|
Assert.AreEqual(initialPosition.Y + _tank.Velocity.Y * deltaTime, _tank.Position.Y);
|
|
Assert.AreEqual(initialPosition.Z + _tank.Velocity.Z * deltaTime, _tank.Position.Z);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TakeDamage_ReducesHealthCorrectly()
|
|
{
|
|
// Arrange
|
|
double initialHealth = _tank.Health;
|
|
double damageAmount = 25.0;
|
|
|
|
// Act
|
|
_tank.TakeDamage(damageAmount);
|
|
|
|
// Assert
|
|
Assert.AreEqual(initialHealth - damageAmount, _tank.Health);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TakeDamage_PublishesDestroyedEventWhenHealthReachesZero()
|
|
{
|
|
// Arrange
|
|
bool eventReceived = false;
|
|
_simulationManager.SubscribeToEvent<TargetDestroyedEvent>(evt =>
|
|
{
|
|
eventReceived = true;
|
|
Assert.AreEqual(_tank.Id, evt.TargetId);
|
|
});
|
|
|
|
// Act
|
|
_tank.TakeDamage(_tank.Health); // 造成足够的伤害以摧毁坦克
|
|
|
|
// Assert
|
|
Assert.IsTrue(eventReceived);
|
|
Assert.AreEqual(0, _tank.Health);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetRadarCrossSection_ReturnsExpectedValue()
|
|
{
|
|
// Arrange
|
|
var observerPosition = new Vector3D(0, 0, 0);
|
|
|
|
// Act
|
|
double rcs = _tank.Properties.RadarCrossSection;
|
|
|
|
// Assert
|
|
Assert.AreEqual(BaseTargetDefaultRCS, rcs);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetInfraredSignature_ReturnsExpectedValue()
|
|
{
|
|
// Arrange
|
|
var observerPosition = new Vector3D(0, 0, 0);
|
|
|
|
// Act
|
|
double signature = _tank.Properties.InfraredRadiationIntensity;
|
|
|
|
// Assert
|
|
Assert.AreEqual(BaseTargetDefaultInfraredSignature, signature);
|
|
}
|
|
}
|
|
} |