using HSchool.Content; namespace HSchool.Ai.Tests; public class ActionStepperTests { private static readonly ActionDef Lunch = new() { DefName = "EatLunch", Room = "Cafeteria", Thing = "Chair", Minutes = 15, Need = "Hunger", NeedGain = 0.5f, }; private static readonly NeedDef Hunger = new() { DefName = "Hunger", Initial = 1, Min = 0, Max = 1, }; [Fact] public void Begin_TakesTheStatedMinutes() { var started = ActionStepper.Begin(Lunch); Assert.Equal("EatLunch", started.ActionId); Assert.Equal("Chair", started.Thing); Assert.Equal(15f, started.RemainingMinutes); } [Fact] public void Advance_CompletesAfterTheStatedMinutes() { var started = ActionStepper.Begin(Lunch); var mid = ActionStepper.Advance(started, 14f, out var doneEarly); var done = ActionStepper.Advance(mid, 1f, out var completed); Assert.False(doneEarly); Assert.Equal(1f, mid.RemainingMinutes); Assert.True(completed); Assert.False(done.IsActive); } [Fact] public void ApplyNeedGain_RaisesHungerByTheStatedAmount() { Assert.Equal(0.8f, ActionStepper.ApplyNeedGain(0.3f, Lunch, Hunger)); Assert.Equal(1f, ActionStepper.ApplyNeedGain(0.8f, Lunch, Hunger)); } [Fact] public void CanOccupy_RefusesWhenEveryThingIsTaken() { Assert.True(ActionStepper.CanOccupy(available: 1, occupied: 0)); Assert.False(ActionStepper.CanOccupy(available: 1, occupied: 1)); Assert.False(ActionStepper.CanOccupy(available: 0, occupied: 0)); } [Fact] public void SameAdvances_LeaveTheSameRemainingMinutes() { var first = ActionStepper.Advance(ActionStepper.Begin(Lunch), 7.5f, out _); var second = ActionStepper.Advance(ActionStepper.Begin(Lunch), 7.5f, out _); Assert.Equal(first.RemainingMinutes, second.RemainingMinutes); Assert.Equal(first.ActionId, second.ActionId); } }