Exemple #1
0
        public void GameLogicAllZombieTest()
        {
            int        size   = 5;
            GameOfLife target = new GameOfLife(size);

            CellUpdate[] cellUpdates = new CellUpdate[size * size];
            int          c           = 0;

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    cellUpdates[c] = new CellUpdate(i, j, null);
                    c++;
                }
            }
            target.ChangeCellStates(cellUpdates);

            int?[,] Grid = target.GetGrid();
            c            = 0; // Reset count
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    Assert.AreEqual(null, Grid[i, j], "Failed at " + i + "," + j);
                    c++;
                }
            }
        }
Exemple #2
0
        public void GameLogicTest()
        {
            int        size   = 5;
            GameOfLife target = new GameOfLife(size);

            CellUpdate[] cellUpdates = new CellUpdate[size * size];
            int?[]       states      = { 1, 1, 0, 1, 0, null, 0, 1, 1, 1, null, 1, null, 0, null, 1, 1, null, 1, 1, null, null, 0, null, 1 };
            int          c           = 0;

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    cellUpdates[c] = new CellUpdate(i, j, states[c]);
                    c++;
                }
            }
            target.ChangeCellStates(cellUpdates);
            target.NextDay();

            int?[,] Grid = target.GetGrid();
            // 2: Alive or zombie
            // 3: Dead or zombie
            int?[] nextDayStates = { 3, 3, 0, 1, 1, null, 0, 3, 2, 2, null, 2, null, 0, null, 2, 2, null, 2, 2, null, null, 0, null, 2 };
            c = 0; // Reset count
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    if (nextDayStates[c] == 3)
                    {
                        Assert.IsTrue(Grid[i, j] == 0 || Grid[i, j] == null, "Failed at " + i + "," + j);
                    }
                    else if (nextDayStates[c] == 2)
                    {
                        Assert.IsTrue(Grid[i, j] == 1 || Grid[i, j] == null, "Failed at " + i + "," + j);
                    }
                    else
                    {
                        Assert.AreEqual(nextDayStates[c], Grid[i, j], "Failed at " + i + "," + j);
                    }
                    c++;
                }
            }
        }