Enhance protocol and simulation features with activity tracking and behavior definitions
- Updated protocol documentation to include new `activity` and `activityLabel` fields in the person card response, reflecting real-time activity status. - Introduced `BehaviorDef` to define behavior rules, including need thresholds and lesson skill gains, enhancing AI decision-making. - Revised the `DefCatalog` to incorporate behavior definitions and updated validation logic to ensure proper behavior handling. - Enhanced the simulation to manage presence and activity states, allowing for more dynamic interactions within the school environment. - Updated tests to validate the new activity tracking and behavior functionalities, ensuring robust performance and reliability. - Improved localization strings to support new activity and behavior features, enhancing user experience.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user