Example #1
0
 public void TestCreatePlayfieldInstance()
 {
     ICellFactory factory = new GridCellFactory(4, 4);
     IPlayField playField = new GridPlayField(factory,4, 4);
     Assert.AreEqual(4, playField.Columns);
     Assert.AreEqual(4, playField.Rows);
 }
Example #2
0
        public void TestRender()
        {
            IRenderer render = new ConsoleRenderer();
            ICellFactory factory = new GridCellFactory(4, 4);
            IPlayField playField = new GridPlayField(factory,4, 4);
            playField.InitializePlayField("0010001000100010");
            using (var sw = new StringWriter())
            {
                Console.SetOut(sw);

                using (var sr = new StringReader(""))
                {
                    Console.SetIn(sr);

                    render.Render(playField);

                    string expected = string.Format("  # {0}  # {1}  # {2}  # {3}", Environment.NewLine,
                                                    Environment.NewLine, Environment.NewLine, Environment.NewLine);
                    /*  
                    * | | |#| |
                    * | | |#| |
                    * | | |#| |
                    * | | |#| |
                    */
                    Assert.AreEqual(expected, sw.ToString());
                }
            }
        }
 public void TestGameControllerInstance()
 {
     ICellFactory factory = new GridCellFactory(4,4);
     IPlayField playField = new GridPlayField(factory, 4, 4);
     IGameRule rule = new ClassicRule();
     var controller = new GameController(playField, rule);
     Assert.IsNotNull(controller);
 }
Example #4
0
 public void TestGetCells()
 {
     ICellFactory factory = new GridCellFactory(4, 4);
     IPlayField playField = new GridPlayField(factory,4, 4);
     playField.InitializePlayField("01001101001");
     AbstractCell[,] cells = playField.GetCells();
     for (int i = 0; i < 4; i++)
         for (int j = 0; j < 4; j++)
             Assert.AreEqual(cells[i, j], playField.GetCell(i, j));
 }
        public void TestGameFieldInitialization()
        {
            ICellFactory factory = new GridCellFactory(4, 4);
            IPlayField playField = new GridPlayField(factory, 4, 4);
            IGameRule rule = new ClassicRule();
            var controller = new GameController(playField, rule);
            string state = "0100111011001010";
            controller.SetState(state);

            Assert.AreEqual(controller.GetState(), state);
        }
 public void TestNextGeneration()
 {
     ICellFactory factory = new GridCellFactory(4, 4);
     IPlayField playField = new GridPlayField(factory, 4, 4);
     IGameRule rule = new ClassicRule();
     var controller = new GameController(playField, rule);
     const string state = "0100010001000000"; // blinker 
     const string nextState = "0000111000000000";
     controller.SetState(state);
     controller.MoveToNextGeneration();
     Assert.AreEqual(nextState, controller.GetState());
 }
        public void TestGameControllerInstanceNullGameRule()
        {
            try
            {
                ICellFactory factory = new GridCellFactory(4, 4);
                IPlayField playField = new GridPlayField(factory,4, 4);

                var controller = new GameController(playField, null);
            }
            catch (Exception exception)
            {
                Assert.AreEqual("Value cannot be null.\r\nParameter name: gameRule", exception.Message);
                throw;
            }
        }
Example #8
0
 public void TestInvalidGetCell()
 {
     try
     {
         ICellFactory factory = new GridCellFactory(4, 4);
         IPlayField playField = new GridPlayField(factory,4, 4);
         playField.InitializePlayField("01001101001");
         playField.GetCell(-1, -2);
     }
     catch (Exception exception)
     {
         Assert.AreEqual("row should be between 0 to 3 and column should be between 0 to 3", exception.Message);
         throw;
     }
 }
Example #9
0
        public IPlayField Clone()
        {
            ICellFactory cellFactory = new GridCellFactory(_rows,_columns);
            IPlayField playFieldGrid = new GridPlayField(cellFactory,_rows, _columns);
            AbstractCell[,] gridCopy = playFieldGrid.GetCells(); // get reference to this class's grid
            for (int row = 0; row < _rows; row++)
                for (int column = 0; column < _columns; column++)
                    gridCopy[row, column] = GetCell(row, column).Clone();

            playFieldGrid.IncreaseGeneration(CurrentGeneration);

            return playFieldGrid;
        }