1415161718192021
public static final String EMPTY_GRID = "..." + NEW_LINE + "..." + NEW_LINE + "..." + NEW_LINE; @Test public void aNewGridShouldBeEmpty() { Grid grid = new Grid(); assertThat(grid.toString(), is(EMPTY_GRID)); }
2526272829303132
String gridContents = "..." + NEW_LINE + "..." + NEW_LINE + "..."; String expectedPrintedGrid = "..." + NEW_LINE + "..." + NEW_LINE + "..." + NEW_LINE; Grid grid = new Grid(gridContents); assertThat(grid.toString(), is(expectedPrintedGrid)); }
3637383940414243
String gridContents = "*.." + NEW_LINE + ".*." + NEW_LINE + ".*."; String expectedPrintedGrid = "*.." + NEW_LINE + ".*." + NEW_LINE + ".*." + NEW_LINE; Grid grid = new Grid(gridContents); assertThat(grid.toString(), is(expectedPrintedGrid)); }
4546474849505152
@Test public void shouldBeAbleToCountLiveNeighboursOfACell() { String gridContents = ".*." + NEW_LINE + "..." + NEW_LINE + "..."; Grid grid = new Grid(gridContents); assertThat(grid.getLiveNeighboursAt(1, 1), is(1)); }
5455565758596061
@Test public void shouldBeAbleToCountLiveNeighboursOfACellOnBoundaries() { String gridContents = ".*." + NEW_LINE + "*.." + NEW_LINE + "..."; Grid grid = new Grid(gridContents); assertThat(grid.getLiveNeighboursAt(0, 0), is(2)); }
6364656667686970
@Test public void shouldBeAbleToCountLiveNeighboursOfACellInTheMiddleOfTheGrid() { String gridContents = "..." + NEW_LINE + "***" + NEW_LINE + "..."; Grid grid = new Grid(gridContents); assertThat(grid.getLiveNeighboursAt(1, 1), is(2)); }
7273747576777879
@Test public void shouldBeAbleToCountLiveNeighboursOfACellOnAnotherLine() { String gridContents = "..." + NEW_LINE + "***" + NEW_LINE + "..."; Grid grid = new Grid(gridContents); assertThat(grid.getLiveNeighboursAt(1, 0), is(3)); }
8182838485868788
@Test public void shouldBeAbleToCountLiveNeighboursOfACellOnDiagonalsAndStraightLines() { String gridContents = "***" + NEW_LINE + "*.*" + NEW_LINE + "***"; Grid grid = new Grid(gridContents); assertThat(grid.getLiveNeighboursAt(1, 1), is(8)); }
9293949596979899100
String gridContents = "***" + NEW_LINE + "***" + NEW_LINE + "***"; Grid grid = new Grid(gridContents); assertThat(grid.getLiveNeighboursAt(1, 1), is(8)); }
101102103104105106107108109110
@Test public void shouldBeAbleToReadTheStateOfALivingCell() { String currentContents = "..." + NEW_LINE + "***" + NEW_LINE + "...\n"; Grid grid = new Grid(currentContents); int x = 0; int y = 1; assertThat(grid.getCellAt(x, y), is(LIVE_CELL)); }