Exemple #1
0
        public void TestDisplayBoard()
        {
            string expected = string.Format("---{0}---{0}---{0}", Environment.NewLine);

            GenericGameState  state  = new GenericGameState();
            ConsoleGameDrawer drawer = new ConsoleGameDrawer();

            Game3x3 game = new Game3x3(state, drawer, null, null);

            Assert.AreEqual(expected, game.GameDrawer.DrawBoardToString(game), "Expected board is different to actual");
        }
Exemple #2
0
        public void TestGetNextMove()
        {
            GenericGameState state   = new GenericGameState();
            ComputerPlayer   player1 = new ComputerPlayer("Jim", SpaceState.X);
            ComputerPlayer   player2 = new ComputerPlayer("Denise", SpaceState.X);

            Game3x3 game = new Game3x3(state, null, player1, player2);
            Space   s    = player1.NextMove(game);

            Assert.IsNotNull(s, "Should have returned an actual space");
        }
Exemple #3
0
        public void TestGameHasStarted()
        {
            GenericGameState  state  = new GenericGameState();
            ConsoleGameDrawer drawer = new ConsoleGameDrawer();

            Game3x3 game = new Game3x3(state, drawer, null, null);
            Space   s    = game.SpaceAt(2, 0);

            Assert.IsFalse(game.HasStarted());
            s.State = SpaceState.O;
            Assert.IsTrue(game.HasStarted());
        }
Exemple #4
0
        public void TestNextMoveGameFinished()
        {
            GenericGameState state   = new GenericGameState();
            ComputerPlayer   player1 = new ComputerPlayer("Jim", SpaceState.X);
            ComputerPlayer   player2 = new ComputerPlayer("Denise", SpaceState.X);

            Game3x3 game = new Game3x3(state, null, player1, player2);

            finishGame(game);

            Assert.IsNull(player1.NextMove(game), "Should return null as there are no spaces");
        }
Exemple #5
0
        public void TestBoardUpdates()
        {
            string expected = string.Format("--X{0}-O-{0}X--{0}", Environment.NewLine);

            GenericGameState  state  = new GenericGameState();
            ConsoleGameDrawer drawer = new ConsoleGameDrawer();

            Game3x3 game = new Game3x3(state, drawer, null, null);

            Assert.AreNotEqual(expected, game.GameDrawer.DrawBoardToString(game), "Expected board is the same as actual, shouldn't be");
            game.SpaceAt(2, 0).State = SpaceState.X;
            game.SpaceAt(1, 1).State = SpaceState.O;
            game.SpaceAt(0, 2).State = SpaceState.X;
            Assert.AreEqual(expected, game.GameDrawer.DrawBoardToString(game), "Expected board is different to actual");
        }
Exemple #6
0
        public void TestGameHasFinished()
        {
            GenericGameState  state  = new GenericGameState();
            ConsoleGameDrawer drawer = new ConsoleGameDrawer();

            Game3x3 game = new Game3x3(state, drawer, null, null);

            Assert.IsFalse(game.HasFinished());
            foreach (Space s in game.Spaces)
            {
                s.State = SpaceState.X;
            }

            Assert.IsTrue(game.HasFinished());
        }
Exemple #7
0
        public void TestWinDetection()
        {
            string expected = string.Format("--X{0}-OX{0}O-X{0}", Environment.NewLine);

            GenericGameState  state  = new GenericGameState();
            ConsoleGameDrawer drawer = new ConsoleGameDrawer();

            Game3x3 game = new Game3x3(state, drawer, null, null);

            Assert.AreNotEqual(expected, game.GameDrawer.DrawBoardToString(game), "Expected board is the same as actual, shouldn't be");
            game.SpaceAt(2, 0).State = SpaceState.X;
            game.SpaceAt(1, 1).State = SpaceState.O;
            game.SpaceAt(0, 2).State = SpaceState.O;
            game.SpaceAt(2, 1).State = SpaceState.X;
            Assert.IsFalse(game.WinDetected(), "Should have not detected a winning row");
            game.SpaceAt(2, 2).State = SpaceState.X;
            Assert.IsTrue(game.WinDetected(), "Should have detected the winning row");
        }