249 lines
9.3 KiB
C#
249 lines
9.3 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||
using ThreatSource.Sensor;
|
||
using ThreatSource.Jammer;
|
||
using ThreatSource.Simulation;
|
||
using ThreatSource.Tests.Simulation;
|
||
using ThreatSource.Utils;
|
||
using ThreatSource.Missile;
|
||
using ThreatSource.Equipment;
|
||
|
||
namespace ThreatSource.Tests.Jamming
|
||
{
|
||
[TestClass]
|
||
public class InfraredDetectorJammingTests
|
||
{
|
||
private SimulationManager _simulationManager = null!;
|
||
private TestSimulationAdapter _testAdapter = null!;
|
||
private InfraredDetector _infraredDetector = null!;
|
||
private TerminalSensitiveSubmunition _submunition = null!;
|
||
|
||
[TestInitialize]
|
||
public void Setup()
|
||
{
|
||
// 初始化模拟管理器和测试适配器
|
||
_simulationManager = new SimulationManager();
|
||
_testAdapter = new TestSimulationAdapter(_simulationManager);
|
||
_simulationManager.SetSimulationAdapter(_testAdapter);
|
||
|
||
// 创建末敏子弹
|
||
var initialParams = new MotionParameters
|
||
{
|
||
Position = new Vector3D(0, 100, 0),
|
||
Orientation = new Orientation(0, -Math.PI/2, 0),
|
||
InitialSpeed = 100
|
||
};
|
||
|
||
var missileProperties = new MissileProperties();
|
||
var submunitionConfig = new TerminalSensitiveSubmunitionConfig();
|
||
|
||
_submunition = new TerminalSensitiveSubmunition(
|
||
"submunition1",
|
||
"parent1",
|
||
missileProperties,
|
||
initialParams,
|
||
submunitionConfig,
|
||
_simulationManager
|
||
);
|
||
_simulationManager.RegisterEntity("submunition1", _submunition);
|
||
|
||
var infraredDetectorConfig = new InfraredDetectorConfig
|
||
{
|
||
MaxDetectionRange = 1000,
|
||
Band = InfraredBand.Medium,
|
||
FieldOfView = 30,
|
||
JammingResistanceThreshold = 1e-3
|
||
};
|
||
|
||
// 创建红外探测器
|
||
_infraredDetector = new InfraredDetector(
|
||
"infraredDetector1",
|
||
_submunition,
|
||
infraredDetectorConfig,
|
||
_simulationManager
|
||
);
|
||
|
||
// 激活红外探测器
|
||
_infraredDetector.Activate();
|
||
}
|
||
|
||
[TestMethod]
|
||
public void InfraredJamming_TargetsDetector_DetectorIsJammed()
|
||
{
|
||
// Arrange
|
||
// 创建干扰事件
|
||
var jammingEvent = new InfraredJammingEvent
|
||
{
|
||
JammingPower = 500.0,
|
||
Wavelength = 4,
|
||
JammingSourcePosition = new Vector3D(10, 10, 0), // 更靠近探测器,且角度更小
|
||
JammingDirection = new Vector3D(0, 1, 0), // 45度角指向探测器
|
||
JammingAngleRange = Math.PI / 4,
|
||
JammingMode = JammingMode.Noise,
|
||
Duration = null
|
||
};
|
||
|
||
// Act
|
||
_simulationManager.PublishEvent(jammingEvent);
|
||
_infraredDetector.Update(0.1);
|
||
|
||
// Assert
|
||
Assert.IsTrue(_infraredDetector.IsJammed, "红外探测器应该处于被干扰状态");
|
||
}
|
||
|
||
[TestMethod]
|
||
public void InfraredJamming_OutsideAngleRange_DetectorNotJammed()
|
||
{
|
||
// Arrange
|
||
// 创建角度范围外的干扰事件
|
||
var jammingEvent = new InfraredJammingEvent
|
||
{
|
||
JammingPower = 500.0,
|
||
Wavelength = 4,
|
||
JammingSourcePosition = new Vector3D(0, 150, 0), // 位于上方
|
||
JammingDirection = new Vector3D(0, 0, 1), // 指向前方,不是指向探测器
|
||
JammingAngleRange = 0.1, // 很小的角度范围
|
||
JammingMode = JammingMode.Noise
|
||
};
|
||
|
||
// Act
|
||
_simulationManager.PublishEvent(jammingEvent);
|
||
_infraredDetector.Update(0.1);
|
||
|
||
// Assert
|
||
Assert.IsFalse(_infraredDetector.IsJammed, "探测器不应该被干扰,因为干扰源不在角度范围内");
|
||
}
|
||
|
||
[TestMethod]
|
||
public void InfraredJamming_LowPower_DetectorNotJammed()
|
||
{
|
||
// Arrange
|
||
// 创建低功率干扰事件
|
||
var jammingEvent = new InfraredJammingEvent
|
||
{
|
||
JammingPower = 10.0, // 低于阈值
|
||
Wavelength = 4,
|
||
JammingSourcePosition = new Vector3D(50, 100, 0),
|
||
JammingDirection = new Vector3D(-1, 0, 0),
|
||
JammingAngleRange = Math.PI / 4,
|
||
JammingMode = JammingMode.Noise
|
||
};
|
||
|
||
// Act
|
||
_simulationManager.PublishEvent(jammingEvent);
|
||
_infraredDetector.Update(0.1);
|
||
|
||
// Assert
|
||
Assert.IsFalse(_infraredDetector.IsJammed, "探测器不应该被干扰,因为干扰功率低于阈值");
|
||
}
|
||
|
||
[TestMethod]
|
||
public void InfraredJamming_ClearedAfterDuration_DetectorNotJammed()
|
||
{
|
||
// Arrange
|
||
// 创建有限时间的干扰事件
|
||
var jammingEvent = new InfraredJammingEvent
|
||
{
|
||
JammingPower = 500.0,
|
||
Wavelength = 4,
|
||
JammingSourcePosition = new Vector3D(10, 10, 0),
|
||
JammingDirection = new Vector3D(0, 1, 0),
|
||
JammingAngleRange = Math.PI / 4,
|
||
JammingMode = JammingMode.Noise,
|
||
Duration = 0.5
|
||
};
|
||
|
||
// Act - 应用干扰
|
||
_simulationManager.PublishEvent(jammingEvent);
|
||
_infraredDetector.Update(0.1);
|
||
|
||
// Assert - 确认已被干扰
|
||
Assert.IsTrue(_infraredDetector.IsJammed, "红外探测器应该处于被干扰状态");
|
||
|
||
// Act - 等待干扰过期
|
||
for (int i = 0; i < 10; i++)
|
||
{
|
||
_infraredDetector.Update(0.1); // 总共更新1秒,超过干扰持续时间
|
||
}
|
||
|
||
// Assert - 确认干扰已清除
|
||
Assert.IsFalse(_infraredDetector.IsJammed, "干扰持续时间结束后,红外探测器应该恢复正常");
|
||
}
|
||
|
||
[TestMethod]
|
||
public void InfraredJamming_ManualClear_DetectorNotJammed()
|
||
{
|
||
// Arrange
|
||
// 创建持续干扰事件
|
||
var jammingEvent = new InfraredJammingEvent
|
||
{
|
||
JammingPower = 500.0,
|
||
Wavelength = 4,
|
||
JammingSourcePosition = new Vector3D(10, 10, 0),
|
||
JammingDirection = new Vector3D(0, 1, 0),
|
||
JammingAngleRange = Math.PI / 4,
|
||
JammingMode = JammingMode.Noise,
|
||
Duration = null
|
||
};
|
||
|
||
// Act - 应用干扰
|
||
_simulationManager.PublishEvent(jammingEvent);
|
||
_infraredDetector.Update(0.1);
|
||
|
||
// Assert - 确认已被干扰
|
||
Assert.IsTrue(_infraredDetector.IsJammed, "红外探测器应该处于被干扰状态");
|
||
|
||
// Act - 手动清除干扰
|
||
_infraredDetector.ClearJamming(JammingType.Infrared);
|
||
_infraredDetector.Update(0.1);
|
||
|
||
// Assert - 确认干扰已清除
|
||
Assert.IsFalse(_infraredDetector.IsJammed, "手动清除后,红外探测器应该恢复正常");
|
||
}
|
||
|
||
[TestMethod]
|
||
public void InfraredJamming_SensorDataDisabledDuringJamming()
|
||
{
|
||
// Arrange
|
||
// 添加一个模拟目标以产生传感器数据
|
||
var targetInitialMotion = new MotionParameters
|
||
{
|
||
Position = new Vector3D(0, 0, 500),
|
||
Orientation = new Orientation(0, 0, 0),
|
||
InitialSpeed = 0
|
||
};
|
||
var targetProperties = new EquipmentProperties
|
||
{
|
||
RadarCrossSection = 1.0,
|
||
InfraredRadiationIntensity = 10.0,
|
||
UltravioletRadiationIntensity = 10.0,
|
||
MillimeterWaveRadiationIntensity = 10.0
|
||
};
|
||
var target = new Tank("target1", targetProperties, targetInitialMotion, _simulationManager);
|
||
_simulationManager.RegisterEntity("target1", target);
|
||
|
||
// 首先更新一次以获取初始数据
|
||
_infraredDetector.Update(0.1);
|
||
var initialData = (InfraredSensorData)_infraredDetector.GetSensorData();
|
||
|
||
// 创建干扰事件
|
||
var jammingEvent = new InfraredJammingEvent
|
||
{
|
||
JammingPower = 500.0,
|
||
Wavelength = 4,
|
||
JammingSourcePosition = new Vector3D(50, 100, 0),
|
||
JammingDirection = new Vector3D(-1, 0, 0),
|
||
JammingAngleRange = Math.PI / 4,
|
||
JammingMode = JammingMode.Noise
|
||
};
|
||
|
||
// Act - 应用干扰
|
||
_simulationManager.PublishEvent(jammingEvent);
|
||
_infraredDetector.Update(0.1);
|
||
var jammedData = (InfraredSensorData)_infraredDetector.GetSensorData();
|
||
|
||
// Assert
|
||
Assert.IsTrue(_infraredDetector.IsJammed, "红外探测器应该处于被干扰状态");
|
||
Assert.IsFalse(jammedData.IsTargetDetected, "被干扰时,探测器不应该检测到目标");
|
||
}
|
||
}
|
||
} |