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"); b.State("B"); } } 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__")); } } }