CounterDroneBackend/test/unit/CounterDrone.Core.Tests/MunitionEntityTests.cs

59 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using CounterDrone.Core.Models;
using CounterDrone.Core.Simulation;
using Xunit;
namespace CounterDrone.Core.Tests
{
public class MunitionEntityTests
{
[Fact]
public void GroundBased_DoesNotArriveImmediately()
{
// 500 m/s, 5000m 距离, 300m 释放高度 — 可以到达
var m = new MunitionEntity("m1", PlatformType.GroundBased,
AerosolType.InertGas,
startX: 0, startY: 0, startZ: 0,
targetX: 5000, targetY: 300, targetZ: 0,
muzzleVelocity: 500f, releaseAltitude: 300f);
m.Update(0.05f);
Assert.False(m.HasArrived, "炮弹不能第一帧就到达");
}
[Fact]
public void GroundBased_ArrivesAfterPeakAndDescent()
{
var m = new MunitionEntity("m1", PlatformType.GroundBased,
AerosolType.InertGas,
startX: 0, startY: 0, startZ: 0,
targetX: 5000, targetY: 300, targetZ: 0,
muzzleVelocity: 500f, releaseAltitude: 300f);
// 500m/s 到 5000m约需 10-15 秒
for (int i = 0; i < 500; i++)
{
m.Update(0.05f);
if (m.HasArrived) break;
}
Assert.True(m.HasArrived, "炮弹应在飞行后到达释放高度");
// 到达时高度应接近释放高度
Assert.True(System.Math.Abs(m.PosY - 300f) < 5f, $"PosY={m.PosY} 应接近 300");
}
[Fact]
public void GroundBased_MovesForwardOverTime()
{
var m = new MunitionEntity("m1", PlatformType.GroundBased,
AerosolType.InertGas,
startX: 0, startY: 0, startZ: 0,
targetX: 1000, targetY: 300, targetZ: 0,
muzzleVelocity: 500f, releaseAltitude: 300f);
m.Update(1f);
var dist = System.Math.Sqrt(m.PosX * m.PosX + m.PosZ * m.PosZ);
Assert.True(dist > 100f, "1秒后炮弹应水平移动 > 100m");
}
}
}