public void TestRegisteredAgentGroupId() { var agentGo = new GameObject("TestAgent"); agentGo.AddComponent <TestAgent>(); var agent = agentGo.GetComponent <TestAgent>(); // test register SimpleMultiAgentGroup agentGroup1 = new SimpleMultiAgentGroup(); agentGroup1.RegisterAgent(agent); Assert.AreEqual(agentGroup1.GetId(), agent._GroupId); Assert.IsNotNull(agent._OnAgentDisabledActions); // should not be able to registered to multiple groups SimpleMultiAgentGroup agentGroup2 = new SimpleMultiAgentGroup(); Assert.Throws <UnityAgentsException>( () => agentGroup2.RegisterAgent(agent)); Assert.AreEqual(agentGroup1.GetId(), agent._GroupId); // test unregister agentGroup1.UnregisterAgent(agent); Assert.AreEqual(0, agent._GroupId); Assert.IsNull(agent._OnAgentDisabledActions); // test register to another group after unregister agentGroup2.RegisterAgent(agent); Assert.AreEqual(agentGroup2.GetId(), agent._GroupId); Assert.IsNotNull(agent._OnAgentDisabledActions); }
public void TestGroupIdCounter() { SimpleMultiAgentGroup group1 = new SimpleMultiAgentGroup(); SimpleMultiAgentGroup group2 = new SimpleMultiAgentGroup(); // id should be unique Assert.AreNotEqual(group1.GetId(), group2.GetId()); }