Files
zeling_v2/Assets/Tests/EditMode/Enemies/GroundNavigatorLogicTests.cs
T

49 lines
1.9 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 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));
// 边界含等号。刻意选二进制可精确表示的值(1.25-1.0 恰为 0.25)
// 否则如 1.2f-1.0f=0.20000005 会因浮点误差略大于 0.2f,测的就不是边界语义而是浮点噪声。
[Test]
public void Arrived_ExactlyAtStopDistance_True()
=> Assert.IsTrue(GroundNavigator.Arrived(1.0f, 1.25f, 0.25f));
[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);
}
}