63 lines
2.9 KiB
C#
63 lines
2.9 KiB
C#
using NUnit.Framework;
|
|
using ProjectM.Simulation;
|
|
using Unity.Entities;
|
|
|
|
namespace ProjectM.Tests
|
|
{
|
|
/// <summary>
|
|
/// Pins <see cref="TimedModifierUtil.Upsert"/> (Phase 1.7 C4): a repeat grant on one SourceId REFRESHES (re-stamps
|
|
/// UntilTick) rather than STACKING — exactly one row per id in BOTH the StatModifier and TimedModifier buffers —
|
|
/// and the TimedModifier-buffer <see cref="TimedModifierUtil.RemoveBySourceId(DynamicBuffer{TimedModifier}, uint)"/>
|
|
/// overload (C5) clears the paired timed row.
|
|
/// </summary>
|
|
public class TimedModifierUtilTests
|
|
{
|
|
static (int stat, int timed, uint until) Count(DynamicBuffer<StatModifier> mods, DynamicBuffer<TimedModifier> timed, uint id)
|
|
{
|
|
int s = 0; for (int i = 0; i < mods.Length; i++) if (mods[i].SourceId == id) s++;
|
|
int t = 0; uint u = 0; for (int i = 0; i < timed.Length; i++) if (timed[i].SourceId == id) { t++; u = timed[i].UntilTick; }
|
|
return (s, t, u);
|
|
}
|
|
|
|
[Test]
|
|
public void Upsert_RefreshesExactlyOneRow_InBothBuffers()
|
|
{
|
|
using var world = new World("UpsertTest");
|
|
var em = world.EntityManager;
|
|
var e = em.CreateEntity();
|
|
em.AddBuffer<StatModifier>(e);
|
|
em.AddBuffer<TimedModifier>(e);
|
|
uint id = Tuning.FrenzySourceId;
|
|
|
|
for (uint k = 1; k <= 3; k++)
|
|
TimedModifierUtil.Upsert(em.GetBuffer<StatModifier>(e), em.GetBuffer<TimedModifier>(e),
|
|
id, (byte)StatTarget.CooldownTicks, (byte)ModOp.PercentMult, -0.30f, 100u * k);
|
|
|
|
var c = Count(em.GetBuffer<StatModifier>(e), em.GetBuffer<TimedModifier>(e), id);
|
|
Assert.AreEqual(1, c.stat, "exactly one StatModifier row (refresh, never stack)");
|
|
Assert.AreEqual(1, c.timed, "exactly one TimedModifier row");
|
|
Assert.AreEqual(300u, c.until, "UntilTick re-stamped to the latest grant");
|
|
}
|
|
|
|
[Test]
|
|
public void RemoveBySourceId_TimedOverload_ClearsPairedRow()
|
|
{
|
|
using var world = new World("TimedStripTest");
|
|
var em = world.EntityManager;
|
|
var e = em.CreateEntity();
|
|
em.AddBuffer<StatModifier>(e);
|
|
em.AddBuffer<TimedModifier>(e);
|
|
uint id = Tuning.FrenzySourceId;
|
|
TimedModifierUtil.Upsert(em.GetBuffer<StatModifier>(e), em.GetBuffer<TimedModifier>(e),
|
|
id, (byte)StatTarget.CooldownTicks, (byte)ModOp.PercentMult, -0.30f, 500u);
|
|
|
|
TimedModifierUtil.RemoveBySourceId(em.GetBuffer<StatModifier>(e), id);
|
|
TimedModifierUtil.RemoveBySourceId(em.GetBuffer<TimedModifier>(e), id);
|
|
|
|
var c = Count(em.GetBuffer<StatModifier>(e), em.GetBuffer<TimedModifier>(e), id);
|
|
Assert.AreEqual(0, c.stat, "StatModifier row stripped");
|
|
Assert.AreEqual(0, c.timed, "TimedModifier row stripped");
|
|
}
|
|
}
|
|
}
|