Пример #1
0
        // Asserts if every turns results in returned false from the property GameEnded except for the last
        // turn where the game is decided by a win or draw.
        private static void AssertForGameEnded(int[] madeTurns)
        {
            var ticTacToeBoxModel = new TicTacToeBoxModel();
            int lastIndex         = madeTurns.Length - 1;

            for (int i = 0, length = lastIndex; i < length; i++)
            {
                ticTacToeBoxModel.MakeTurn(madeTurns[i]);
                Assert.False(ticTacToeBoxModel.GameEnded);
            }

            ticTacToeBoxModel.MakeTurn(madeTurns[lastIndex]);
            Assert.True(ticTacToeBoxModel.GameEnded);
        }
Пример #2
0
        public void Reset_ShouldReturnCorrectOutcomeFor3PartiesThroughResets()
        {
            int[]       fieldNbr;
            GameState[] madeTurns;
            var         logicModel = new TicTacToeBoxModel();

            // 1. case is an undone game party

            // [|] [|] [o]
            // [x] [o] [x]
            // [|] [x] [|]
            fieldNbr  = new int[] { 5, 4, 7, 2, 3 };
            madeTurns = new GameState[]
            {
                GameState.TurnPlayerTwo,
                GameState.TurnPlayerOne,
                GameState.TurnPlayerTwo,
                GameState.TurnPlayerOne,
                GameState.TurnPlayerTwo
            };

            IterCasesWithReset();

            // 2. case is a game ending in draw

            // [x] [o] [x]
            // [o] [x] [x]
            // [o] [x] [o]
            fieldNbr  = new int[] { 0, 1, 4, 8, 5, 3, 2, 6, 7 };
            madeTurns = StatesForDraw;

            IterCasesWithReset();

            // 3. case is a game ending with 1. players winning

            // [o] [x] [o]
            // [o] [x] [x]
            // [x] [x] [o]

            fieldNbr  = new int[] { 4, 8, 5, 3, 7, 1, 6, 0, 2 };
            madeTurns = new GameState[]
            {
                GameState.TurnPlayerTwo, GameState.TurnPlayerOne, GameState.TurnPlayerTwo,
                GameState.TurnPlayerOne, GameState.TurnPlayerTwo, GameState.TurnPlayerOne,
                GameState.TurnPlayerTwo, GameState.TurnPlayerOne, GameState.PlayerOneWins
            };

            IterCasesWithReset();

            void IterCasesWithReset()
            {
                for (int i = 0, length = fieldNbr.Length; i < length; i++)
                {
                    logicModel.MakeTurn(fieldNbr[i]);
                    Assert.Equal(logicModel.CurrentState, madeTurns[i]);
                }

                logicModel.Reset();
            }
        }
Пример #3
0
        // Used for theories to check if exceptions are thrown for turn sequences which
        // contain invalid turns
        // parameter madeTurns are the sequence which contains at least one invalid turn
        private static void IterCasesForExcep(int[] madeTurns)
        {
            var ticTacToeBox = new TicTacToeBoxModel();

            foreach (int fieldNumber in madeTurns)
            {
                ticTacToeBox.MakeTurn(fieldNumber);
            }
        }
Пример #4
0
        // Used for most theories.
        // Parameter input sequence of field numbers for the turns
        // Parameter expectedOutput sequence which contains the expected state
        // for the next turn for the receptive field number provide by the parameter input
        private static void IterCases(int[] input, GameState[] expectedOutput)
        {
            var ticTacToeBox = new TicTacToeBoxModel();

            for (int i = 0, length = input.Length; i < length; i++)
            {
                ticTacToeBox.MakeTurn(input[i]);
                Assert.Equal(ticTacToeBox.CurrentState, expectedOutput[i]);
            }
        }
Пример #5
0
        public void LastTakeFieldNbr_ShouldReturnTakenFieldNbr(int[] madeTurns)
        {
            // Should return -1 if game starts because no turn was made.
            var ticTacToeBoxModel = new TicTacToeBoxModel();

            Assert.Equal(ticTacToeBoxModel.LastTakeFieldNbr, -1);

            foreach (int fieldNbr in madeTurns)
            {
                ticTacToeBoxModel.MakeTurn(fieldNbr);
                Assert.Equal(ticTacToeBoxModel.LastTakeFieldNbr, fieldNbr);
            }
        }