55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using CounterDrone.Core.Algorithms;
|
|
using CounterDrone.Core.Models;
|
|
using Xunit;
|
|
|
|
namespace CounterDrone.Core.Tests
|
|
{
|
|
public class InterceptCalculatorAirTests
|
|
{
|
|
private static List<Waypoint> R(float x0, float x1, float y, float kph)
|
|
=> new() {
|
|
new() { PosX = x0, PosY = y, PosZ = 0, Speed = kph },
|
|
new() { PosX = x1, PosY = y, PosZ = 0, Speed = kph },
|
|
};
|
|
|
|
[Fact]
|
|
public void Smoke_ReturnsPositive()
|
|
{
|
|
// 无人机 200km/h, 0→20km, Y=500
|
|
// 平台(2000,1000,0), cruise=80, R+exp=35
|
|
var route = R(0, 20000, 500, 200);
|
|
var unit = new Vector3(2000, 1000, 0);
|
|
var (arc, _) = InterceptCalculator.ComputeHorizontal(
|
|
route, 0, 200, 35, unit, 80, 1000, 500);
|
|
|
|
Assert.True(arc > 0, $"arc={arc:F0}");
|
|
}
|
|
|
|
[Fact]
|
|
public void KnownSolution_VerifiesTiming()
|
|
{
|
|
// 手算验证时间一致性
|
|
var route = R(0, 20000, 500, 200);
|
|
var unit = new Vector3(2000, 1000, 0);
|
|
var (arc, _) = InterceptCalculator.ComputeHorizontal(
|
|
route, 0, 200, 35, unit, 80, 1000, 500);
|
|
|
|
if (arc > 0)
|
|
{
|
|
float vd = 200f / 3.6f;
|
|
float tf = MathF.Sqrt(2f * 500f / 9.81f); // ~10.1s
|
|
float delay = 35f + tf;
|
|
float droneTime = (arc - 0) / vd;
|
|
float releaseX = arc - 80 * tf;
|
|
float flightDist = MathF.Abs(releaseX - 2000);
|
|
float platformTime = flightDist / 80;
|
|
float total = delay + platformTime;
|
|
|
|
Assert.True(MathF.Abs(droneTime - total) < 1f,
|
|
$"drone={droneTime:F1} total={total:F1} arc={arc:F0} releaseX={releaseX:F0}");
|
|
}
|
|
}
|
|
}
|
|
}
|