using NUnit.Framework; using BaseGames.AI; namespace BaseGames.Tests.EditMode.AI { // 顶层测试定义,供反射注册表发现 [AiDefinition("__test_grunt")] internal sealed class TestGruntAi : AiScript { protected override void Build(BrainBuilder b) { b.Entry("A"); b.State("A").To("B").When(c => c.Sensor.SeesPlayer(), "SeesPlayer"); // 回边不可省:本夹具经 GetOrBuildGraph 走生产的 Build(), // 它会校验「非终态必须有出口」——夹具也得是一张能自洽运转的图 b.State("B").To("A").When(c => !c.Sensor.SeesPlayer(), "LostPlayer"); } } public class AiDefinitionRegistryTests { [Test] public void Has_FindsRegisteredDefinition() { Assert.IsTrue(AiDefinitionRegistry.Has("__test_grunt")); } [Test] public void GetGraph_ResolvesById() { var g = AiDefinitionRegistry.GetGraph("__test_grunt"); Assert.AreEqual("A", g.EntryState); } [Test] public void GetGraph_SameId_ReturnsSharedInstance() { Assert.AreSame( AiDefinitionRegistry.GetGraph("__test_grunt"), AiDefinitionRegistry.GetGraph("__test_grunt")); } [Test] public void GetGraph_UnknownId_Throws() { Assert.Throws( () => AiDefinitionRegistry.GetGraph("__nope__")); } } }