public void TestExitLast() { var chain = new LinkedAgentChain(); var firstAgent = new DummyAgent() { Progress = 2 }; var firstPointer = chain.Enter(firstAgent); var lastAgent = new DummyAgent() { Progress = 0 }; var lastPointer = chain.Enter(lastAgent); chain.Exit(lastPointer); Assert.AreSame(firstPointer, chain.First); Assert.AreSame(firstPointer, chain.Last); Assert.IsNull(lastPointer.Previous); Assert.IsNull(lastPointer.Next); Assert.IsNull(firstPointer.Previous); Assert.IsNull(firstPointer.Next); Assert.IsNull(lastPointer.Chain); }
public void TestExitSingle() { var chain = new LinkedAgentChain(); var dummyAgent = new DummyAgent() { Progress = 0 }; var pointer = chain.Enter(dummyAgent); chain.Exit(pointer); Assert.IsNull(pointer.Chain); Assert.IsNull(pointer.Next); Assert.IsNull(pointer.Previous); Assert.IsNull(chain.First); Assert.IsNull(chain.Last); }
public void TestFull() { var chain = new LinkedAgentChain(); var agents = new List <DummyAgent>(); var pointers = new List <LinkedAgentPointer>(); for (int i = 0; i < 10; i++) { foreach (var agent in agents) { agent.Progress++; } var newAgent = new DummyAgent() { Progress = 0 }; agents.Add(newAgent); pointers.Add(chain.Enter(newAgent)); if (i == 0) { Assert.AreEqual(pointers[i], chain.First); Assert.AreEqual(pointers[i], chain.Last); Assert.IsNull(pointers[i].Next); Assert.IsNull(pointers[i].Previous); } else { Assert.AreEqual(pointers[i], chain.Last); Assert.AreEqual(pointers[0], chain.First); Assert.AreEqual(pointers[i - 1], pointers[i].Next); Assert.AreEqual(pointers[i], pointers[i - 1].Previous); Assert.IsNull(pointers[i].Previous); for (int j = 1; j < i; j++) { Assert.AreEqual(pointers[j - 1], pointers[j].Next); Assert.AreEqual(pointers[j], pointers[j - 1].Previous); } } } for (int i = 0; i < 10; i++) { Assert.AreEqual(pointers[i], chain.First); chain.Exit(pointers[i]); Assert.IsNull(pointers[i].Chain); Assert.IsNull(pointers[i].Next); Assert.IsNull(pointers[i].Previous); if (i == 9) { Assert.IsNull(chain.First); Assert.IsNull(chain.Last); } else if (i == 8) { Assert.AreEqual(chain.First, chain.Last); } } }