66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
using CounterDrone.Core.Algorithms;
|
|
using CounterDrone.Core.Models;
|
|
using Xunit;
|
|
|
|
namespace CounterDrone.Core.Tests
|
|
{
|
|
public class KinematicsTests
|
|
{
|
|
[Fact]
|
|
public void WindToVector_East_CorrectDirection()
|
|
{
|
|
var (x, y, z) = Kinematics.WindToVector(WindDirection.E, 10f);
|
|
Assert.True(x > 9f, "东风 → X 正方向");
|
|
Assert.True(System.Math.Abs(z) < 1f, "东风 → Z 接近 0");
|
|
Assert.Equal(0f, y, 3);
|
|
}
|
|
|
|
[Fact]
|
|
public void WindToVector_North_CorrectDirection()
|
|
{
|
|
var (x, y, z) = Kinematics.WindToVector(WindDirection.N, 10f);
|
|
Assert.True(System.Math.Abs(x) < 1f);
|
|
Assert.True(z > 9f, "北风 → Z 正方向");
|
|
}
|
|
|
|
[Fact]
|
|
public void CalculateLaunchAngle_ReturnsValidAngle()
|
|
{
|
|
var angle = Kinematics.CalculateLaunchAngle(5000f, 500f, 300f);
|
|
Assert.True(angle > 0);
|
|
Assert.True(angle < System.Math.PI / 2); // < 90°
|
|
}
|
|
|
|
[Fact]
|
|
public void CalculateLaunchAngle_CloseRange_UsesHeightConstraint()
|
|
{
|
|
// 近距离,高度约束应主导
|
|
var angle = Kinematics.CalculateLaunchAngle(1000f, 300f, 300f);
|
|
Assert.True(angle > 0.05f, "近距离也有合理发射角");
|
|
}
|
|
|
|
[Fact]
|
|
public void ParabolicPosition_T0_IsAtStart()
|
|
{
|
|
var (x, y, z) = Kinematics.ParabolicPosition(0, 0, 0, 0.5f, 0, 500f, 0);
|
|
Assert.Equal(0f, x, 1);
|
|
Assert.Equal(0f, y, 1);
|
|
Assert.Equal(0f, z, 1);
|
|
}
|
|
|
|
[Fact]
|
|
public void PointInPolygon_Inside_ReturnsTrue()
|
|
{
|
|
var vertices = new (float X, float Z)[] { (0, 0), (10, 0), (10, 10), (0, 10) };
|
|
Assert.True(Kinematics.PointInPolygon(5, 5, vertices));
|
|
}
|
|
|
|
[Fact]
|
|
public void PointInPolygon_Outside_ReturnsFalse()
|
|
{
|
|
var vertices = new (float X, float Z)[] { (0, 0), (10, 0), (10, 10), (0, 10) };
|
|
Assert.False(Kinematics.PointInPolygon(20, 5, vertices));
|
|
}
|
|
}
|
|
}
|