public void TestBoardToString3()
        {
            int rows = 1;
            int columns = 1;

            Field[,] fixedFields = new Field[rows, columns];
            fixedFields[0, 0] = new Field();
            fixedFields[0, 0].Status = FieldStatus.Opened;
            fixedFields[0, 0].Value = 5;

            Board board = new Board(rows, columns, 1);

            Type type = typeof(Board);
            var fieldValue = type.GetField("fields", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(board, fixedFields);

            StringBuilder str = new StringBuilder();
            str.Append("    0 \n");
            str.Append("   ___\n");
            str.Append("0 | 5 |\n");
            str.Append("   ___\n");

            string expected = str.ToString();
            string actual = board.ToString();

            Assert.AreEqual(
                expected,
                actual,
                string.Format("The board string is {0}, but must be {1}!", actual, expected));
        }
Ejemplo n.º 2
0
 public void FieldTestInstantiate()
 {
     Field field = new Field();
     field.Status = FieldStatus.Closed;
     field.Value = 8;
     Assert.AreEqual(8, field.Value, "The value has been changed by the field!");
     Assert.AreEqual(FieldStatus.Closed, field.Status, "The FieldStatus enumerations has been changed by the field!");
 }
Ejemplo n.º 3
0
 public void FieldTestInvalidValue()
 {
     Field field = new Field();
     field.Status = FieldStatus.Closed;
     field.Value = 10;
 }
        public void TestToStringAllFieldsRevealed5()
        {
            int rows = 5;
            int columns = 10;

            Field[,] fixedFields = new Field[rows, columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    fixedFields[i, j] = new Field();
                }
            }

            Board board = new Board(rows, columns, 10);

            Type type = typeof(Board);
            var fieldValue = type.GetField("fields", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(board, fixedFields);

            StringBuilder str = new StringBuilder();
            str.Append("    0 1 2 3 4 5 6 7 8 9 \n");
            str.Append("   _____________________\n");
            str.Append("0 | 0 0 0 0 0 0 0 0 0 0 |\n");
            str.Append("1 | 0 0 0 0 0 0 0 0 0 0 |\n");
            str.Append("2 | 0 0 0 0 0 0 0 0 0 0 |\n");
            str.Append("3 | 0 0 0 0 0 0 0 0 0 0 |\n");
            str.Append("4 | 0 0 0 0 0 0 0 0 0 0 |\n");
            str.Append("   _____________________\n");

            string expected = str.ToString();
            string actual = board.ToStringAllFieldsRevealed();

            Assert.AreEqual(
                expected,
                actual,
                string.Format("The board string is {0}, but must be {1}!", actual, expected));
        }
        public void TestOpenFieldWhenOpenLastClosed()
        {
            int rows = 2;
            int columns = 2;

            Field[,] fixedFields = new Field[rows, columns];

            fixedFields[0, 0] = new Field();
            fixedFields[0, 0].Status = FieldStatus.Closed;
            fixedFields[0, 1] = new Field();
            fixedFields[0, 1].Status = FieldStatus.IsAMine;
            fixedFields[1, 0] = new Field();
            fixedFields[1, 0].Status = FieldStatus.Opened;
            fixedFields[1, 1] = new Field();
            fixedFields[1, 1].Status = FieldStatus.Opened;

            Board board = new Board(rows, columns, 1);

            Type type = typeof(Board);
            var fieldValue = type.GetField("fields", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(board, fixedFields);

            BoardStatus expected = BoardStatus.AllFieldsAreOpened;
            BoardStatus actual = board.OpenField(0, 0);

            Assert.AreEqual(
               expected,
               actual,
               string.Format("The BoardStatus is {0}, but must be {1}!", actual, expected));
        }
        public void TestCountOpenedFields2()
        {
            int rows = 5;
            int columns = 10;

            Field[,] fixedFields = new Field[rows, columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    fixedFields[i, j] = new Field();
                }
            }

            fixedFields[0, 0].Status = FieldStatus.Opened;

            Board board = new Board(rows, columns, 10);

            Type type = typeof(Board);
            var fieldValue = type.GetField("fields", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(board, fixedFields);

            int expected = 1;
            int actual = board.CountOpenedFields();

            Assert.AreEqual(
                expected,
                actual,
                string.Format("The board opened fields are {0}, but must be {1}!", actual, expected));
        }
        public void TestBoardToString5()
        {
            int rows = 5;
            int columns = 10;

            Field[,] fixedFields = new Field[rows, columns];
            int counter = 1;
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    fixedFields[i, j] = new Field();
                    fixedFields[i, j].Status = FieldStatus.Opened;
                    fixedFields[i, j].Value = counter;
                    counter++;
                    if (counter == 9)
                    {
                        counter = 1;
                    }
                }
            }

            Board board = new Board(rows, columns, 10);

            Type type = typeof(Board);
            var fieldValue = type.GetField("fields", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(board, fixedFields);

            StringBuilder str = new StringBuilder();
            str.Append("    0 1 2 3 4 5 6 7 8 9 \n");
            str.Append("   _____________________\n");
            str.Append("0 | 1 2 3 4 5 6 7 8 1 2 |\n");
            str.Append("1 | 3 4 5 6 7 8 1 2 3 4 |\n");
            str.Append("2 | 5 6 7 8 1 2 3 4 5 6 |\n");
            str.Append("3 | 7 8 1 2 3 4 5 6 7 8 |\n");
            str.Append("4 | 1 2 3 4 5 6 7 8 1 2 |\n");
            str.Append("   _____________________\n");

            string expected = str.ToString();
            string actual = board.ToString();

            Assert.AreEqual(
                expected,
                actual,
                string.Format("The board string is {0}, but must be {1}!", actual, expected));
        }
        public void TestBoardToString4()
        {
            int rows = 5;
            int columns = 10;

            Field[,] fixedFields = new Field[rows, columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    fixedFields[i, j] = new Field();
                }
            }

            fixedFields[0, 0].Status = FieldStatus.Opened;
            fixedFields[0, 0].Value = 1;
            fixedFields[1, 1].Status = FieldStatus.Opened;
            fixedFields[1, 1].Value = 2;
            fixedFields[2, 2].Status = FieldStatus.Opened;
            fixedFields[2, 2].Value = 3;
            fixedFields[3, 3].Status = FieldStatus.Opened;
            fixedFields[3, 3].Value = 4;
            fixedFields[4, 4].Status = FieldStatus.Opened;
            fixedFields[4, 4].Value = 5;

            Board board = new Board(rows, columns, 10);

            Type type = typeof(Board);
            var fieldValue = type.GetField("fields", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(board, fixedFields);

            StringBuilder str = new StringBuilder();
            str.Append("    0 1 2 3 4 5 6 7 8 9 \n");
            str.Append("   _____________________\n");
            str.Append("0 | 1 ? ? ? ? ? ? ? ? ? |\n");
            str.Append("1 | ? 2 ? ? ? ? ? ? ? ? |\n");
            str.Append("2 | ? ? 3 ? ? ? ? ? ? ? |\n");
            str.Append("3 | ? ? ? 4 ? ? ? ? ? ? |\n");
            str.Append("4 | ? ? ? ? 5 ? ? ? ? ? |\n");
            str.Append("   _____________________\n");

            string expected = str.ToString();
            string actual = board.ToString();

            Assert.AreEqual(
                expected,
                actual,
                string.Format("The board string is {0}, but must be {1}!", actual, expected));
        }