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); }
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); }
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); }
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 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; } }
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; } }
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; } }
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; } }
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; }
public void TestFactoryInstance() { var factory = new GridCellFactory(4, 4); Assert.IsNotNull(factory); }