204 lines
7.7 KiB
C#
204 lines
7.7 KiB
C#
using Xunit;
|
|
using ThreatSource.Indicator;
|
|
using ThreatSource.Simulation;
|
|
using ThreatSource.Utils;
|
|
using ThreatSource.Tests.Simulation;
|
|
using ThreatSource.Equipment;
|
|
|
|
namespace ThreatSource.Tests.Indicator
|
|
{
|
|
public class LaserDesignatorCodeTests
|
|
{
|
|
private readonly SimulationManager _simulationManager;
|
|
private readonly TestSimulationAdapter _testAdapter;
|
|
private readonly LaserDesignator _laserDesignator;
|
|
private readonly LaserDesignatorConfig _config;
|
|
private readonly Tank _tank;
|
|
|
|
public LaserDesignatorCodeTests()
|
|
{
|
|
_simulationManager = new SimulationManager();
|
|
_testAdapter = new TestSimulationAdapter(_simulationManager);
|
|
_simulationManager.SetSimulationAdapter(_testAdapter);
|
|
|
|
_config = new LaserDesignatorConfig
|
|
{
|
|
Power = 1000,
|
|
DivergenceAngle = 0.001
|
|
};
|
|
|
|
var tankInitialMotion = new KinematicState
|
|
{
|
|
Position = new Vector3D(100, 0, 0),
|
|
Orientation = new Orientation(0, 0, 0),
|
|
Speed = 0
|
|
};
|
|
|
|
var tankProperties = new EquipmentProperties
|
|
{
|
|
RadarCrossSection = 1.0,
|
|
InfraredRadiationIntensity = 10.0,
|
|
UltravioletRadiationIntensity = 10.0,
|
|
MillimeterWaveRadiationIntensity = 10.0
|
|
};
|
|
|
|
_tank = new Tank("target1", tankProperties, tankInitialMotion, _simulationManager);
|
|
_simulationManager.RegisterEntity("target1", _tank);
|
|
|
|
var designatorInitialMotion = new KinematicState
|
|
{
|
|
Position = new Vector3D(0, 0, 0),
|
|
Orientation = new Orientation(0, 0, 0),
|
|
Speed = 0
|
|
};
|
|
|
|
_laserDesignator = new LaserDesignator(
|
|
"laser1",
|
|
"target1",
|
|
"missile1",
|
|
_config,
|
|
designatorInitialMotion,
|
|
_simulationManager
|
|
);
|
|
_simulationManager.RegisterEntity("laser1", _laserDesignator);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetLaserCode_SetsCodeCorrectly()
|
|
{
|
|
// Arrange
|
|
_laserDesignator.Activate();
|
|
|
|
// Act
|
|
_laserDesignator.config.LaserCodeConfig = new LaserCodeConfig
|
|
{
|
|
IsCodeEnabled = true,
|
|
Code = new LaserCode
|
|
{
|
|
CodeType = LaserCodeType.PRF,
|
|
CodeValue = 1234
|
|
}
|
|
};
|
|
_laserDesignator.Update(0.1);
|
|
|
|
// Assert
|
|
var events = _testAdapter.GetPublishedEvents<LaserIlluminationUpdateEvent>();
|
|
Assert.NotEmpty(events);
|
|
|
|
var lastEvent = events[events.Count - 1];
|
|
Assert.NotNull(lastEvent.LaserCodeConfig);
|
|
Assert.True(lastEvent.LaserCodeConfig.IsCodeEnabled);
|
|
Assert.Equal(LaserCodeType.PRF, lastEvent.LaserCodeConfig.Code.CodeType);
|
|
Assert.Equal(1234, lastEvent.LaserCodeConfig.Code.CodeValue);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddCodeParameter_AddsParameterCorrectly()
|
|
{
|
|
// Arrange
|
|
_laserDesignator.Activate();
|
|
_laserDesignator.config.LaserCodeConfig = new LaserCodeConfig
|
|
{
|
|
IsCodeEnabled = true,
|
|
Code = new LaserCode
|
|
{
|
|
CodeType = LaserCodeType.PPM,
|
|
CodeValue = 5678
|
|
}
|
|
};
|
|
|
|
// Act
|
|
_laserDesignator.AddCodeParameter("PulseWidth", 0.001);
|
|
_laserDesignator.Update(0.1);
|
|
|
|
// Assert
|
|
var events = _testAdapter.GetPublishedEvents<LaserIlluminationUpdateEvent>();
|
|
Assert.NotEmpty(events);
|
|
|
|
var lastEvent = events[events.Count - 1];
|
|
Assert.NotNull(lastEvent.LaserCodeConfig);
|
|
Assert.True(lastEvent.LaserCodeConfig.IsCodeEnabled);
|
|
Assert.Equal(LaserCodeType.PPM, lastEvent.LaserCodeConfig.Code.CodeType);
|
|
Assert.Equal(5678, lastEvent.LaserCodeConfig.Code.CodeValue);
|
|
Assert.True(lastEvent.LaserCodeConfig.Code.Parameters.ContainsKey("PulseWidth"));
|
|
Assert.Equal(0.001, lastEvent.LaserCodeConfig.Code.Parameters["PulseWidth"]);
|
|
}
|
|
|
|
[Fact]
|
|
public void EnableCode_EnablesAndDisablesCodeCorrectly()
|
|
{
|
|
// Arrange
|
|
_laserDesignator.Activate();
|
|
_laserDesignator.config.LaserCodeConfig = new LaserCodeConfig
|
|
{
|
|
IsCodeEnabled = true,
|
|
Code = new LaserCode
|
|
{
|
|
CodeType = LaserCodeType.PRF,
|
|
CodeValue = 1234
|
|
}
|
|
};
|
|
|
|
// Act - Disable code
|
|
_laserDesignator.config.LaserCodeConfig.IsCodeEnabled = false;
|
|
_laserDesignator.Update(0.1);
|
|
|
|
// Assert - Code should be disabled
|
|
var eventsAfterDisable = _testAdapter.GetPublishedEvents<LaserIlluminationUpdateEvent>();
|
|
Assert.NotEmpty(eventsAfterDisable);
|
|
var lastEventAfterDisable = eventsAfterDisable[eventsAfterDisable.Count - 1];
|
|
Assert.NotNull(lastEventAfterDisable.LaserCodeConfig);
|
|
Assert.False(lastEventAfterDisable.LaserCodeConfig.IsCodeEnabled);
|
|
|
|
// Act - Enable code again
|
|
_laserDesignator.config.LaserCodeConfig.IsCodeEnabled = true;
|
|
_laserDesignator.Update(0.1);
|
|
|
|
// Assert - Code should be enabled
|
|
var eventsAfterEnable = _testAdapter.GetPublishedEvents<LaserIlluminationUpdateEvent>();
|
|
Assert.NotEmpty(eventsAfterEnable);
|
|
var lastEventAfterEnable = eventsAfterEnable[eventsAfterEnable.Count - 1];
|
|
Assert.NotNull(lastEventAfterEnable.LaserCodeConfig);
|
|
Assert.True(lastEventAfterEnable.LaserCodeConfig.IsCodeEnabled);
|
|
}
|
|
|
|
[Fact]
|
|
public void LaserIlluminationEvents_IncludeCodeInformation()
|
|
{
|
|
// Arrange
|
|
_laserDesignator.config.LaserCodeConfig = new LaserCodeConfig
|
|
{
|
|
IsCodeEnabled = true,
|
|
Code = new LaserCode
|
|
{
|
|
CodeType = LaserCodeType.PRF,
|
|
CodeValue = 1234
|
|
}
|
|
};
|
|
|
|
// Act - Start illumination
|
|
_laserDesignator.Activate();
|
|
|
|
// Assert - Start event should include code
|
|
var startEvents = _testAdapter.GetPublishedEvents<LaserIlluminationUpdateEvent>();
|
|
Assert.NotEmpty(startEvents);
|
|
var startEvent = startEvents[startEvents.Count - 1];
|
|
Assert.NotNull(startEvent.LaserCodeConfig);
|
|
Assert.True(startEvent.LaserCodeConfig.IsCodeEnabled);
|
|
Assert.Equal(LaserCodeType.PRF, startEvent.LaserCodeConfig.Code.CodeType);
|
|
Assert.Equal(1234, startEvent.LaserCodeConfig.Code.CodeValue);
|
|
|
|
// Act - Update illumination
|
|
_laserDesignator.Update(0.1);
|
|
|
|
// Assert - Update event should include code
|
|
var updateEvents = _testAdapter.GetPublishedEvents<LaserIlluminationUpdateEvent>();
|
|
Assert.NotEmpty(updateEvents);
|
|
var updateEvent = updateEvents[updateEvents.Count - 1];
|
|
Assert.NotNull(updateEvent.LaserCodeConfig);
|
|
Assert.True(updateEvent.LaserCodeConfig.IsCodeEnabled);
|
|
Assert.Equal(LaserCodeType.PRF, updateEvent.LaserCodeConfig.Code.CodeType);
|
|
Assert.Equal(1234, updateEvent.LaserCodeConfig.Code.CodeValue);
|
|
}
|
|
}
|
|
} |