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 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 TestGameControllerInstanceNullPlayField() { try { IGameRule rule = new ClassicRule(); var controller = new GameController(null, rule); } catch (Exception exception) { Assert.AreEqual("Value cannot be null.\r\nParameter name: playField", exception.Message); throw; } }
public void TestClassicDieUnderPopulationRule() { IGameRule rule = new ClassicRule(); var cell = new CenterCell(); cell.ShouldLive(); Assert.AreEqual(true, cell.IsAlive); Assert.AreEqual(1, cell.CurrentGeneration); var cells = new List<AbstractCell> { new CenterCell(), new CenterCell(), new CenterCell(), new CenterCell() }; cells[0].ShouldLive(); rule.ApplyRule(cell, cells); Assert.AreEqual(false, cell.IsAlive); Assert.AreEqual(0, cell.CurrentGeneration); }
public void TestRuleCellNullException() { try { IGameRule rule = new ClassicRule(); rule.ApplyRule(null, new List<AbstractCell>()); } catch (Exception exception) { Assert.AreEqual("Value cannot be null.\r\nParameter name: cell", exception.Message); throw; } }
public void TestRuleNeighboursNullException() { try { IGameRule rule = new ClassicRule(); rule.ApplyRule(new CenterCell(), null); } catch (Exception exception) { Assert.AreEqual("Value cannot be null.\r\nParameter name: neighbours", exception.Message); throw; } }