71 lines
2.8 KiB
C#
71 lines
2.8 KiB
C#
using NUnit.Framework;
|
|
using ProjectM.Client;
|
|
|
|
namespace ProjectM.Tests
|
|
{
|
|
/// <summary>
|
|
/// Pure tests for <see cref="HudVisualMath"/> — the low-health screen vignette ramp + hurt-flash decay that
|
|
/// drive the HUD damage overlay. Verifies the curve is 0 above the threshold, 1 at empty, monotonic between,
|
|
/// and that the flash decays to zero without going negative.
|
|
/// </summary>
|
|
public class HudVisualMathTests
|
|
{
|
|
const float Eps = 1e-4f;
|
|
|
|
[Test]
|
|
public void Vignette_ZeroAtFullHealth_AndAtThreshold()
|
|
{
|
|
Assert.AreEqual(0f, HudVisualMath.VignetteIntensity(1f), Eps);
|
|
Assert.AreEqual(0f, HudVisualMath.VignetteIntensity(HudVisualMath.LowHealthThreshold), Eps);
|
|
Assert.AreEqual(0f, HudVisualMath.VignetteIntensity(0.9f), Eps);
|
|
}
|
|
|
|
[Test]
|
|
public void Vignette_OneAtEmpty_HalfAtMidband()
|
|
{
|
|
Assert.AreEqual(1f, HudVisualMath.VignetteIntensity(0f), Eps);
|
|
// Half of the [0, threshold] band → ~0.5 intensity.
|
|
Assert.AreEqual(0.5f, HudVisualMath.VignetteIntensity(HudVisualMath.LowHealthThreshold * 0.5f), Eps);
|
|
}
|
|
|
|
[Test]
|
|
public void Vignette_IsMonotonicDecreasingInHealth()
|
|
{
|
|
float prev = HudVisualMath.VignetteIntensity(0f);
|
|
for (float f = 0.05f; f <= 0.4f; f += 0.05f)
|
|
{
|
|
float cur = HudVisualMath.VignetteIntensity(f);
|
|
Assert.LessOrEqual(cur, prev + Eps, "intensity must not rise as health rises");
|
|
prev = cur;
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void VignetteOpacity_ScalesByMax()
|
|
{
|
|
Assert.AreEqual(HudVisualMath.MaxVignetteOpacity, HudVisualMath.VignetteOpacity(0f), Eps);
|
|
Assert.AreEqual(0f, HudVisualMath.VignetteOpacity(1f), Eps);
|
|
}
|
|
|
|
[Test]
|
|
public void Flash_DecaysToZero_NeverNegative()
|
|
{
|
|
Assert.AreEqual(0f, HudVisualMath.DecayFlash(HudVisualMath.HurtFlashKick, HudVisualMath.HurtFlashDuration), Eps);
|
|
// Half the duration → roughly half the kick remains.
|
|
Assert.AreEqual(HudVisualMath.HurtFlashKick * 0.5f,
|
|
HudVisualMath.DecayFlash(HudVisualMath.HurtFlashKick, HudVisualMath.HurtFlashDuration * 0.5f), Eps);
|
|
Assert.AreEqual(0f, HudVisualMath.DecayFlash(0.1f, 10f), Eps, "over-long dt clamps to 0, not negative");
|
|
}
|
|
|
|
[Test]
|
|
public void CombinedOpacity_ClampsToOne()
|
|
{
|
|
Assert.AreEqual(1f, HudVisualMath.CombinedOpacity(0f, 1f), Eps);
|
|
Assert.AreEqual(0f, HudVisualMath.CombinedOpacity(1f, 0f), Eps);
|
|
float mid = HudVisualMath.CombinedOpacity(0.175f, 0.2f);
|
|
Assert.Greater(mid, 0f);
|
|
Assert.LessOrEqual(mid, 1f);
|
|
}
|
|
}
|
|
}
|