Skip to content

Commit

Permalink
Merge branch 'master' of github.com:wakaleo/game-of-life
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Nov 6, 2011
2 parents 678ff2e + a8e328e commit 176308c
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 261 deletions.
17 changes: 0 additions & 17 deletions gameoflife-core/pom.xml
Expand Up @@ -12,23 +12,6 @@
<version>0.7.49-SNAPSHOT</version>
<name>gameoflife-core</name>
<url>${HUDSON_URL}</url>
<build>
<plugins>
<plugin>
<groupId>org.easyb</groupId>
<artifactId>maven-easyb-plugin</artifactId>
<version>${easyb.version}</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.easyb</groupId>
<artifactId>easyb-core</artifactId>
<version>${easyb.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
Expand Down
Expand Up @@ -5,7 +5,9 @@

public class GridReader {

public Cell[][] loadFrom(String gridContents) {
public final String NEW_LINE = System.getProperty("line.separator");

public Cell[][] loadFrom(String gridContents) {
List<Cell[]> rows = new ArrayList<Cell[]>();
String[] rowValues = splitIntoRows(gridContents);
for (String row : rowValues) {
Expand All @@ -30,7 +32,7 @@ private Cell[] splitIntoCells(String row) {
}

private String[] splitIntoRows(String gridContents) {
return gridContents.split("\n");
return gridContents.split(NEW_LINE);
}

}
Expand Up @@ -2,15 +2,17 @@

public class GridWriter {

public String convertToString(Cell[][] gridContents) {
private final String LINE_SEPARATOR = System.getProperty("line.separator");

public String convertToString(Cell[][] gridContents) {
StringBuffer printedGrid = new StringBuffer();
for(Cell[] row : gridContents) {
for( Cell cell : row) {
printedGrid.append(cell.toString());
}
// TODO: This simply masks the problem: why empty rows being passed?
if(row.length > 0) {
printedGrid.append("\n");
printedGrid.append(LINE_SEPARATOR);
}
}
return printedGrid.toString();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Expand Up @@ -10,7 +10,9 @@

public class WhenYouCreateAGrid {

public static final String EMPTY_GRID = "...\n" + "...\n" + "...\n";
private static final String NEW_LINE = System.getProperty("line.separator");

public static final String EMPTY_GRID = "..." + NEW_LINE + "..." + NEW_LINE + "..." + NEW_LINE;

@Test
public void aNewGridShouldBeEmpty() {
Expand All @@ -21,9 +23,9 @@ public void aNewGridShouldBeEmpty() {
@Test
public void shouldBeAbleToSeedAGridWithAString() {

String gridContents = "...\n" + "...\n" + "...";
String gridContents = "..." + NEW_LINE + "..." + NEW_LINE + "...";

String expectedPrintedGrid = "...\n" + "...\n" + "...\n";
String expectedPrintedGrid = "..." + NEW_LINE + "..." + NEW_LINE + "..." + NEW_LINE;

Grid grid = new Grid(gridContents);
assertThat(grid.toString(), is(expectedPrintedGrid));
Expand All @@ -32,9 +34,9 @@ public void shouldBeAbleToSeedAGridWithAString() {
@Test
public void shouldBeAbleToSeedAGridWithANonEmptyString() {

String gridContents = "*..\n" + ".*.\n" + ".*.";
String gridContents = "*.." + NEW_LINE + ".*." + NEW_LINE + ".*.";

String expectedPrintedGrid = "*..\n" + ".*.\n" + ".*.\n";
String expectedPrintedGrid = "*.." + NEW_LINE + ".*." + NEW_LINE + ".*." + NEW_LINE;

Grid grid = new Grid(gridContents);
assertThat(grid.toString(), is(expectedPrintedGrid));
Expand All @@ -43,7 +45,7 @@ public void shouldBeAbleToSeedAGridWithANonEmptyString() {
@Test
public void shouldBeAbleToCountLiveNeighboursOfACell() {

String gridContents = ".*.\n" + "...\n" + "...";
String gridContents = ".*." + NEW_LINE + "..." + NEW_LINE + "...";

Grid grid = new Grid(gridContents);
assertThat(grid.getLiveNeighboursAt(1, 1), is(1));
Expand All @@ -52,7 +54,7 @@ public void shouldBeAbleToCountLiveNeighboursOfACell() {
@Test
public void shouldBeAbleToCountLiveNeighboursOfACellOnBoundaries() {

String gridContents = ".*.\n" + "*..\n" + "...";
String gridContents = ".*." + NEW_LINE + "*.." + NEW_LINE + "...";

Grid grid = new Grid(gridContents);
assertThat(grid.getLiveNeighboursAt(0, 0), is(2));
Expand All @@ -61,7 +63,7 @@ public void shouldBeAbleToCountLiveNeighboursOfACellOnBoundaries() {
@Test
public void shouldBeAbleToCountLiveNeighboursOfACellInTheMiddleOfTheGrid() {

String gridContents = "...\n" + "***\n" + "...";
String gridContents = "..." + NEW_LINE + "***" + NEW_LINE + "...";

Grid grid = new Grid(gridContents);
assertThat(grid.getLiveNeighboursAt(1, 1), is(2));
Expand All @@ -70,7 +72,7 @@ public void shouldBeAbleToCountLiveNeighboursOfACellInTheMiddleOfTheGrid() {
@Test
public void shouldBeAbleToCountLiveNeighboursOfACellOnAnotherLine() {

String gridContents = "...\n" + "***\n" + "...";
String gridContents = "..." + NEW_LINE + "***" + NEW_LINE + "...";

Grid grid = new Grid(gridContents);
assertThat(grid.getLiveNeighboursAt(1, 0), is(3));
Expand All @@ -79,7 +81,7 @@ public void shouldBeAbleToCountLiveNeighboursOfACellOnAnotherLine() {
@Test
public void shouldBeAbleToCountLiveNeighboursOfACellOnDiagonalsAndStraightLines() {

String gridContents = "***\n" + "*.*\n" + "***";
String gridContents = "***" + NEW_LINE + "*.*" + NEW_LINE + "***";

Grid grid = new Grid(gridContents);
assertThat(grid.getLiveNeighboursAt(1, 1), is(8));
Expand All @@ -88,8 +90,8 @@ public void shouldBeAbleToCountLiveNeighboursOfACellOnDiagonalsAndStraightLines(
@Test
public void shouldNotCountTheTargetCellAsANeighbour() {

String gridContents = "***\n" +
"***\n" +
String gridContents = "***" + NEW_LINE +
"***" + NEW_LINE +
"***";

Grid grid = new Grid(gridContents);
Expand All @@ -100,7 +102,7 @@ public void shouldNotCountTheTargetCellAsANeighbour() {
@Test
public void shouldBeAbleToReadTheStateOfALivingCell() {

String currentContents = "...\n" + "***\n" + "...\n";
String currentContents = "..." + NEW_LINE + "***" + NEW_LINE + "...\n";
Grid grid = new Grid(currentContents);
int x = 0;
int y = 1;
Expand All @@ -110,7 +112,7 @@ public void shouldBeAbleToReadTheStateOfALivingCell() {
@Test
public void shouldBeAbleToReadTheStateOfADeadCell() {

String currentContents = "...\n" + "***\n" + "...\n";
String currentContents = "..." + NEW_LINE + "***" + NEW_LINE + "...\n";
Grid grid = new Grid(currentContents);
int x = 1;
int y = 0;
Expand All @@ -119,21 +121,21 @@ public void shouldBeAbleToReadTheStateOfADeadCell() {

@Test
public void shouldBeAbleToReadTheWidthOfTheGrid() {
String currentContents = "...\n" + "***\n";
String currentContents = "..." + NEW_LINE + "***\n";
Grid grid = new Grid(currentContents);
assertThat(grid.getWidth(), is(3));
}

@Test
public void shouldBeAbleToReadTheHeightOfTheGrid() {
String currentContents = "...\n" + "***\n";
String currentContents = "..." + NEW_LINE + "***" + NEW_LINE;
Grid grid = new Grid(currentContents);
assertThat(grid.getHeight(), is(2));
}

@Test
public void shouldBeAbleToObtainTheGridContentsAsAnArray() {
String currentContents = "*..\n*..\n.*.\n";
String currentContents = "*.." + NEW_LINE + "*.." + NEW_LINE + ".*." + NEW_LINE;
Grid grid = new Grid(currentContents);

Cell[][] contents = grid.getContents();
Expand All @@ -144,7 +146,7 @@ public void shouldBeAbleToObtainTheGridContentsAsAnArray() {

@Test
public void theGridContentsAsAnArrayShouldBeTheCorrectSize() {
String currentContents = "*..\n*..\n.*.\n";
String currentContents = "*.." + NEW_LINE + "*.." + NEW_LINE + ".*." + NEW_LINE;
Grid grid = new Grid(currentContents);

Cell[][] contents = grid.getContents();
Expand All @@ -154,7 +156,7 @@ public void theGridContentsAsAnArrayShouldBeTheCorrectSize() {

@Test
public void ModifyingTheGridContentsAsAnArrayShouldNotModifyTheOriginalContents() {
String currentContents = "*..\n.*.\n..*\n";
String currentContents = "*.." + NEW_LINE + ".*." + NEW_LINE + "..*" + NEW_LINE;
Grid grid = new Grid(currentContents);

Cell[][] contents = grid.getContents();
Expand Down

0 comments on commit 176308c

Please sign in to comment.