public void Should_reborn_with_three_neighbours_on_GenerateNextState() { var cellFieldInitial = new CellField(3, 3); cellFieldInitial.SeedLife(0, 0); cellFieldInitial.SeedLife(1, 0); cellFieldInitial.SeedLife(0, 1); _sut.GenerateNextState(cellFieldInitial); Assert.That(cellFieldInitial[1, 1].IsAlive); }
public void Should_kill_two_neighbour_cells_on_GenerateNextState() { var cellFieldInitial = new CellField(3, 3); cellFieldInitial.SeedLife(0, 0); cellFieldInitial.SeedLife(0, 1); _sut.GenerateNextState(cellFieldInitial); Assert.That(!cellFieldInitial[0, 0].IsAlive); Assert.That(!cellFieldInitial[0, 1].IsAlive); }
public void Should_kill_lone_cell_on_GenerateNextState() { var cellFieldInitial = new CellField(3, 3); cellFieldInitial.SeedLife(1, 1); _sut.GenerateNextState(cellFieldInitial); Assert.That(!cellFieldInitial[1, 1].IsAlive); }
public void Should_CellField_Equals() { var cellField1 = new CellField(2, 2); cellField1.SeedLife(0, 0); var cellField2 = new CellField(2, 2); cellField2.SeedLife(0, 0); Assert.IsTrue(cellField1.Equals(cellField2)); Assert.IsFalse(cellField1 == cellField2); }
public void Should_state_not_changed_on_GenerateNextState() { var cellFieldInitial = new CellField(3, 3); var cellFieldWithNextState = new CellField(3, 3); for (int j = 0; j < 2; j++) { for (int i = 0; i < 2; i++) { cellFieldInitial.SeedLife(i, j); cellFieldWithNextState.SeedLife(i, j); } } _sut.GenerateNextState(cellFieldWithNextState); Assert.That(cellFieldInitial.Equals(cellFieldWithNextState)); }
/// <summary> /// Seeds instance of CeedField with alive cells randomly /// </summary> /// <param name="field"></param> /// <param name="density">Value from 0 to 1. Defines the chance of seeding alive cell.</param> public static void SeedFieldRandomly(this CellField field, double density) { if (density < 0 || 1 < density) { throw new ArgumentOutOfRangeException(nameof(density), density, "Value of the \"{0}\" should be in range of 0 and 1."); } var random = new Random(); for (int j = 0; j < field.Height; j++) { for (int i = 0; i < field.Width; i++) { if (random.NextDouble() < density) { field.SeedLife(i, j); } } } }