public void CellConstructorTest() { string value = "-"; // TODO: Initialize to an appropriate value Cell target = new Cell(value); string actual = target.ToString(); Assert.AreEqual(actual, value); }
public void GetNeighbors() { var dic=new Dictionary<string,Cell>(); var cell0=new Cell(-1,-1); var cell1=new Cell(-1,0); var cell2=new Cell(-1,1); var cell3=new Cell(0,-1); var cell4=new Cell(0,1); var cell5=new Cell(1,-1); var cell6=new Cell(1,0); var cell7=new Cell(1,1); dic.Add(cell0.ToString(),cell0); dic.Add(cell1.ToString(),cell1); dic.Add(cell2.ToString(),cell2); dic.Add(cell3.ToString(),cell3); dic.Add(cell4.ToString(),cell4); dic.Add(cell5.ToString(),cell5); dic.Add(cell6.ToString(),cell6); dic.Add(cell7.ToString(),cell7); Assert.IsTrue(new Cell(0, 0).GetCountOfNeighbors(dic)==8); dic.Remove(cell0.ToString()); Assert.IsTrue(new Cell(0, 0).GetCountOfNeighbors(dic)==7); dic.Remove(cell1.ToString()); Assert.IsTrue(new Cell(0, 0).GetCountOfNeighbors(dic)==6); dic.Remove(cell2.ToString()); Assert.IsTrue(new Cell(0, 0).GetCountOfNeighbors(dic)==5); dic.Remove(cell3.ToString()); Assert.IsTrue(new Cell(0, 0).GetCountOfNeighbors(dic)==4); dic.Remove(cell4.ToString()); Assert.IsTrue(new Cell(0, 0).GetCountOfNeighbors(dic)==3); dic.Remove(cell5.ToString()); Assert.IsTrue(new Cell(0, 0).GetCountOfNeighbors(dic)==2); dic.Remove(cell6.ToString()); Assert.IsTrue(new Cell(0, 0).GetCountOfNeighbors(dic)==1); dic.Remove(cell7.ToString()); Assert.IsTrue(new Cell(0, 0).GetCountOfNeighbors(dic)==0); }
/// <summary> /// Adds all cells that will be born in next move to the dictionary. /// </summary> /// <param name="dictionary">current living cells</param> private void AddNewbornsToDictionary(IDictionary<string, Cell> dictionary) { var allreadyTested=new Dictionary<string, Cell>(); foreach (KeyValuePair<string, Cell> cell in _cells) { for (int x = -1; x < 2; x++) { for (int y = -1; y < 2; y++) { string nameFormat = $"{cell.Value.X + x}|{cell.Value.Y + y}"; if (_cells.ContainsKey(nameFormat)) continue; if (allreadyTested.ContainsKey(nameFormat)) continue; var unbornCell =new Cell(cell.Value.X + x , cell.Value.Y + y); if (WillBeCellAliveInNextTurn(unbornCell,false)) dictionary.Add(unbornCell.ToString(),unbornCell); allreadyTested.Add(unbornCell.ToString(),unbornCell); } } } }
public void ToStringTest() { string expected = "X"; Cell target = new Cell(expected); // TODO: Initialize to an appropriate value // TODO: Initialize to an appropriate value string actual; actual = target.ToString(); Assert.AreEqual(expected, actual); //Assert.Inconclusive("Verify the correctness of this test method."); }