public void TestUndoCycle() // Tests a particularly insidious case of UndoMove wherein one Undo forces another in a cycle. { const int NumArmies = 5; var manager = new ArmyManager(); var player = new Player(manager, new Color(0, 0, 0)); var armies = new List <Army>(); for (int i = 0; i < NumArmies; i++) { var army = new Army(100); armies.Add(army); player.AddArmy(army, new Pos(i, i)); } for (int i = NumArmies - 1; i >= 0; i--) { manager.MoveArmy(armies[i], new Pos(i + 1, i + 1)); } manager.MoveArmy(armies[NumArmies - 1], new Pos(0, 0)); manager.UndoMove(armies[NumArmies - 1]); for (int i = 0; i < NumArmies; i++) { Assert.AreEqual(new Pos(i, i), manager.ArmyPosition(armies[i])); } }
public void UndoMove(int armyId) { var army = GetArmy(armyId); if (army != null) { manager.UndoMove(army); } }
public void TestUndoParam(Pos source, Pos dest) { var manager = new ArmyManager(); var player = new Player(manager, new Color(0, 0, 0)); var army = new Army(100); player.AddArmy(army, source); manager.MoveArmy(army, dest); manager.UndoMove(army); Assert.AreSame(army, manager.ArmyAt(source)); Assert.AreEqual(source, manager.ArmyPosition(army)); }