Esempio n. 1
0
        public void SetTurn_MaxValue_Expect_Truncation(int turnIndex, int expectedBits)
        {
            int boardHistory = 0;

            boardHistory = BoardHistoryUtils.SetTurn(boardHistory, turnIndex, ~0 - 1);

            Assert.AreEqual(expectedBits, boardHistory);
        }
Esempio n. 2
0
        public void ValidateBoardHistory_QuickWinPlayerTwoTurns_Expect_WinPlayerTwo()
        {
            int boardHistory = 0;

            for (int i = 0; i < s_quickWinPlayerTwoTurns.Length; i++)
            {
                boardHistory = BoardHistoryUtils.SetTurn(boardHistory, i, s_quickWinPlayerTwoTurns[i]);
            }

            BoardHistoryUtils.ValidateBoardHistory(boardHistory, out _, out _, out _, out var boardResult);

            Assert.AreEqual(BoardResult.WinPlayerTwo, boardResult);
        }
Esempio n. 3
0
        public void ValidateBoardHistory_DrawTurns_Expect_Draw()
        {
            int boardHistory = 0;

            for (int i = 0; i < s_drawTurns.Length; i++)
            {
                boardHistory = BoardHistoryUtils.SetTurn(boardHistory, i, s_drawTurns[i]);
            }

            BoardHistoryUtils.ValidateBoardHistory(boardHistory, out _, out _, out _, out var boardResult);

            Assert.AreEqual(BoardResult.Draw, boardResult);
        }
Esempio n. 4
0
        public void ValidateBoardHistory_TurnsHistoryAfterEndingState_Expect_Error()
        {
            int boardHistory = 0;

            for (int i = 0; i < s_quickWinPlayerOneTurns.Length; i++)
            {
                boardHistory = BoardHistoryUtils.SetTurn(boardHistory, i, s_quickWinPlayerOneTurns[i]);
            }

            boardHistory = BoardHistoryUtils.SetTurn(boardHistory, s_quickWinPlayerOneTurns.Length + 1, 0);

            var ex = Assert.Throws <ArgumentException>(() => BoardHistoryUtils.ValidateBoardHistory(boardHistory, out _, out _, out _, out _));

            Assert.AreEqual("Turn history exists after a ending state was reached", ex.Message);
        }
Esempio n. 5
0
        // [TestCase(8)] Can't sequence break on final turn
        public void ValidateBoardHistory_SequenceBreakState_Expect_Error(int sequenceBreakTurnIndex)
        {
            int boardHistory = 0;

            for (int i = 0; i <= sequenceBreakTurnIndex + 1; i++)
            {
                if (i != sequenceBreakTurnIndex)
                {
                    boardHistory = BoardHistoryUtils.SetTurn(boardHistory, i, s_drawTurns[i]);
                }
            }

            var ex = Assert.Throws <ArgumentException>(() => BoardHistoryUtils.ValidateBoardHistory(boardHistory, out _, out _, out _, out _));

            Assert.AreEqual("Sequence of turns is invalid", ex.Message);
        }
Esempio n. 6
0
        // [TestCase(8)] Optimizations always truncate this turn into a valid range
        public void ValidateBoardHistory_DeltaIndexOutOfBoundsState_Expect_Error(int outOfBoundsTurnIndex)
        {
            int boardHistory = 0;

            for (int i = 0; i <= outOfBoundsTurnIndex; i++)
            {
                if (i == outOfBoundsTurnIndex)
                {
                    boardHistory = BoardHistoryUtils.SetTurn(boardHistory, i, 9 - i);
                }
                else
                {
                    boardHistory = BoardHistoryUtils.SetTurn(boardHistory, i, s_drawTurns[i]);
                }
            }

            var ex = Assert.Throws <ArgumentException>(() => BoardHistoryUtils.ValidateBoardHistory(boardHistory, out _, out _, out _, out _));

            Assert.AreEqual("Turn delta index is out of bounds", ex.Message);
        }