예제 #1
0
        public void TestCreateCell()
        {
            // in 4x4 cells are fixed
            //00 top left
            //01 top, 02 top , 03 top right
            //10 and 20 left 
            //11 21 normal, 12 22 normal, 13 23 right
            //30 bottom left
            // 31 bottom, 32 bottom, 33 bottom right

            var factory = new GridCellFactory(4, 4);
            Assert.IsTrue(factory.CreateCell(0,0) is TopLeftCell);
            Assert.IsTrue(factory.CreateCell(0, 1) is TopCell);
            Assert.IsTrue(factory.CreateCell(0, 2) is TopCell);
            Assert.IsTrue(factory.CreateCell(0, 3) is TopRightCell);
            Assert.IsTrue(factory.CreateCell(1, 0) is LeftCell);
            Assert.IsTrue(factory.CreateCell(1,1) is CenterCell);
            Assert.IsTrue(factory.CreateCell(1, 2) is CenterCell);
            Assert.IsTrue(factory.CreateCell(1, 3) is RightCell);
            Assert.IsTrue(factory.CreateCell(2, 0) is LeftCell);
            Assert.IsTrue(factory.CreateCell(2, 1) is CenterCell);
            Assert.IsTrue(factory.CreateCell(2, 2) is CenterCell);
            Assert.IsTrue(factory.CreateCell(2, 3) is RightCell);
            Assert.IsTrue(factory.CreateCell(3, 0) is BottomLeftCell);
            Assert.IsTrue(factory.CreateCell(3, 1) is BottomCell);
            Assert.IsTrue(factory.CreateCell(3, 2) is BottomCell);
            Assert.IsTrue(factory.CreateCell(3, 3) is BottomRightCell);
        }
예제 #2
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);
 }
예제 #3
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());
                }
            }
        }
예제 #4
0
 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);
 }
예제 #5
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));
 }
예제 #6
0
        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);
        }
예제 #7
0
 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());
 }
예제 #8
0
 public void TestFactoryLowerLimit()
 {
     try
     {
         var factory = new GridCellFactory(3, 4);
     }
     catch (Exception exception)
     {
         Assert.AreEqual("row and column size should not be less than 4", exception.Message);
         throw;
     }
 }
예제 #9
0
 public void TestMinimumPlayfieldException()
 {
     try
     {
         ICellFactory factory = new GridCellFactory(4, 4);
         new GridPlayField(factory,3, 4);
     }
     catch (Exception exception)
     {
         Assert.AreEqual("rows and columns value can't ne less than 4", exception.Message);
         throw;
     }
 }
예제 #10
0
        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;
            }
        }
예제 #11
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;
     }
 }
예제 #12
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;
        }
예제 #13
0
 public void TestFactoryInstance()
 {
     var factory = new GridCellFactory(4, 4);
     Assert.IsNotNull(factory);
 }