47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using NUnit.Framework;
|
|
using BaseGames.Enemies.Navigation;
|
|
|
|
namespace BaseGames.Tests.EditMode.Enemies
|
|
{
|
|
/// <summary>GroundNavigator 的方向/到达判定纯函数(无场景依赖)。</summary>
|
|
public class GroundNavigatorLogicTests
|
|
{
|
|
[Test]
|
|
public void Arrived_WhenWithinStopDistance()
|
|
=> Assert.IsTrue(GroundNavigator.Arrived(1.0f, 1.1f, 0.2f));
|
|
|
|
[Test]
|
|
public void Arrived_ExactlyAtStopDistance_True()
|
|
=> Assert.IsTrue(GroundNavigator.Arrived(1.0f, 1.2f, 0.2f));
|
|
|
|
[Test]
|
|
public void NotArrived_WhenOutsideStopDistance()
|
|
=> Assert.IsFalse(GroundNavigator.Arrived(1.0f, 1.5f, 0.2f));
|
|
|
|
[Test]
|
|
public void Arrived_IgnoresDirection()
|
|
{
|
|
Assert.IsTrue(GroundNavigator.Arrived(1.0f, 0.9f, 0.2f)); // 目标在左侧
|
|
Assert.IsFalse(GroundNavigator.Arrived(1.0f, 0.5f, 0.2f));
|
|
}
|
|
|
|
[Test]
|
|
public void WanderX_PositiveSign_LandsWithinForwardRange()
|
|
{
|
|
Assert.AreEqual(11.5f, GroundNavigator.WanderX(10f, 1.5f, 5f, +1f, 0f), 1e-4f); // t=0 → 最近端
|
|
Assert.AreEqual(15f, GroundNavigator.WanderX(10f, 1.5f, 5f, +1f, 1f), 1e-4f); // t=1 → 最远端
|
|
}
|
|
|
|
[Test]
|
|
public void WanderX_NegativeSign_LandsWithinBackwardRange()
|
|
{
|
|
Assert.AreEqual(8.5f, GroundNavigator.WanderX(10f, 1.5f, 5f, -1f, 0f), 1e-4f);
|
|
Assert.AreEqual(5f, GroundNavigator.WanderX(10f, 1.5f, 5f, -1f, 1f), 1e-4f);
|
|
}
|
|
|
|
[Test]
|
|
public void WanderX_MidT_Interpolates()
|
|
=> Assert.AreEqual(13.25f, GroundNavigator.WanderX(10f, 1.5f, 5f, +1f, 0.5f), 1e-4f);
|
|
}
|
|
}
|