private static bool SomeLiveCellsAreWithinBounds(Universe universe) { var result = false; universe.IterateLiveCells((coords, cellState) => { if (GridCoordsAreWithinBounds(coords)) { result = true; } }); return result; }
private void AssertThatGridContainsExpectedLiveCellsAfterTick(Universe universe, Coords[] setOfExpectedCoords) { universe.Tick(); var coordsOfLiveCells = new List<Coords>(); universe.IterateLiveCells((coords, cellState) => coordsOfLiveCells.Add(coords)); Assert.That(setOfExpectedCoords, Is.Unique); Assert.That(coordsOfLiveCells, Is.Unique); Assert.That(coordsOfLiveCells.Count(), Is.EqualTo(setOfExpectedCoords.Count()), "Found the wrong number of live cells"); foreach (var expectedCoords in setOfExpectedCoords) { var match = coordsOfLiveCells.FirstOrDefault(coords => coords.Equals(expectedCoords)); var message = string.Format("Expected to find a live cell at ({0}, {1})", expectedCoords.X, expectedCoords.Y); Assert.That(match, Is.Not.Null, message); } }