示例#1
0
    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]));
        }
    }
示例#2
0
    public void MoveArmy(int armyId, Pos toPos)
    {
        var army = GetArmy(armyId);

        if (army != null)
        {
            manager.MoveArmy(army, toPos);
        }
    }
示例#3
0
    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));
    }
示例#4
0
    public void TestMovementParam(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);

        Assert.IsTrue((manager.ArmyAt(source) != null) == source.Equals(dest)); // source != dest implies that army will no longer be at source.
        Assert.AreSame(army, manager.ArmyAt(dest));
        Assert.AreEqual(dest, manager.ArmyPosition(army));
    }