Beispiel #1
0
 /*********************************************************************
 * This is a constructor. It initializes the Logic class and the images
 * for cross and circle.
 * INPUT: none.
 * OUTPUT: none.
 *********************************************************************/
 public Form1()
 {
     InitializeComponent();
     logic = new Logic();
     cross = Properties.Resources.kross;
     circle = Properties.Resources.hringur;
 }
Beispiel #2
0
        public void TestDataReader()
        {
            // 1. Arrange:
            Logic logic = new Logic();
            // 2. Act:

            // 3. Assert:
            Assert.IsNotNull(logic.dataReader);
        }
Beispiel #3
0
        public void TestCurrentPlayer()
        {
            // 1. Arrange:
            Logic logic = new Logic();

            // 2. Act:

            // 3. Assert:
            Assert.AreEqual(logic.currentPlayer, Global.PLAYER1);
        }
Beispiel #4
0
        public void TestInitializedMatrix()
        {
            // 1. Arrange:
            Logic logic = new Logic();

            // 2. Act:

            // 3. Assert:
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Assert.AreEqual(logic.matrix[i][j], "E");
                }
            }
        }
Beispiel #5
0
        public void TestChangePlayer()
        {
            // 1. Arrange:
            Logic logic = new Logic();

            // 2. Act:
            logic.ChangePlayers();

            // 3. Assert:
            Assert.AreEqual(logic.currentPlayer, Global.PLAYER2);

            // 4. Act Again:
            logic.ChangePlayers();

            // 5. Assert Again:
            Assert.AreEqual(logic.currentPlayer, Global.PLAYER1);
        }
Beispiel #6
0
        public void TestTie()
        {
            // 1. Arrange:
            Logic logic = new Logic();

            // 2. Act.

            // 3. Assert:
            Assert.IsFalse(logic.Tie() );

            // 2. Act.
            logic.moveCounter = 9;

            // 3. Assert:
            Assert.IsTrue(logic.Tie() );
        }
Beispiel #7
0
        public void TestMoveCounter()
        {
            // 1. Arrange:
            Logic logic = new Logic();
            // 2. Act:

            // 3. Assert:
            Assert.IsNotNull(logic.moveCounter);
            Assert.AreEqual(logic.moveCounter, 0);
        }
Beispiel #8
0
        public void TestMarkMatrix()
        {
            // 1. Arrange:
            Logic logic = new Logic();
            int x1 = 1, y1 = 2;
            int x2 = 2, y2 = 1;

            // 2. Act:
            logic.MarkMatrix(x1, y1);
            logic.currentPlayer = Global.PLAYER2;
            logic.MarkMatrix(x2, y2);

            // 3. Assert:
            Assert.AreEqual(logic.matrix[x1][y1], "X");
            Assert.AreEqual(logic.matrix[x2][y2], "O");
            Assert.AreEqual(logic.moveCounter, 2);
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (!(x1 == i && y1 == j || x2 == i && y2 == j))
                    {
                        Assert.AreEqual(logic.matrix[i][j], "E");
                    }
                }
            }
        }
Beispiel #9
0
        public void TestIsWonInTopHorizonalPositionForX()
        {
            // 1. Arrange:
            Logic logic = new Logic();

            // 2. Act:
            logic.matrix[0][0] = "X";
            logic.matrix[0][1] = "X";
            logic.matrix[0][2] = "X";

            // 3. Assert:
            Assert.IsTrue(logic.IsWon());
        }
Beispiel #10
0
        public void TestIsWonInRightVerticalPositionForO()
        {
            // 1. Arrange:
            Logic logic = new Logic();

            // 2. Act:
            logic.matrix[2][0] = "O";
            logic.matrix[2][1] = "O";
            logic.matrix[2][2] = "O";

            //3. Assert:
            Assert.IsTrue(logic.IsWon());
        }
Beispiel #11
0
        public void TestIsWonInLeftVerticalPositionForX()
        {
            // 1. Arrange:
            Logic logic = new Logic();

            // 2. Act:
            logic.matrix[0][0] = "X";
            logic.matrix[1][0] = "X";
            logic.matrix[2][0] = "X";

            //3. Assert:
            Assert.IsTrue(logic.IsWon());
        }
Beispiel #12
0
        public void TestIsWonInDiagonalPositionForXTopLeftToBottomRight()
        {
            // 1. Arrange:
            Logic logic = new Logic();

            // 2. Act:
            logic.matrix[0][0] = "X";
            logic.matrix[1][1] = "X";
            logic.matrix[2][2] = "X";

            //3. Assert:
            Assert.IsTrue(logic.IsWon());
        }
Beispiel #13
0
        public void TestIsWonForRandomGameWhereThereIsATie()
        {
            // 1. Arrange:
            Logic logic = new Logic();

            // 2. Act:
            logic.matrix[0][0] = "X";
            logic.matrix[0][1] = "O";
            logic.matrix[0][2] = "X";
            logic.matrix[1][0] = "X";
            logic.matrix[1][1] = "O";
            logic.matrix[1][2] = "X";
            logic.matrix[2][0] = "O";
            logic.matrix[2][1] = "X";
            logic.matrix[2][2] = "O";

            // 3. Assert:
            Assert.IsFalse(logic.IsWon());
        }
Beispiel #14
0
 public void TestIsAvailable()
 {
     // 1. Arrange:
     Logic logic = new Logic();
     // 2. Act:
     logic.matrix[0][0] = Global.PLAYER1;
     logic.matrix[1][1] = Global.PLAYER2;
     // 3. Assert:
     Assert.IsTrue(logic.IsAvailable(2, 2));
     Assert.IsFalse(logic.IsAvailable(1, 1));
     Assert.IsFalse(logic.IsAvailable(0, 0));
 }