Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2011 14:16
Show Gist options
  • Save anonymous/1427230 to your computer and use it in GitHub Desktop.
Save anonymous/1427230 to your computer and use it in GitHub Desktop.
import static org.junit.Assert.*;
import org.junit.Test;
public class WorldTest {
@Test(expected = IllegalArgumentException.class)
public void testWorldCreation() throws Exception {
new World("", 1, 1);
}
@Test
public void itCreateAValidWorldFromConstructorParams() throws Exception {
World world = new World(
"000" +
"001" +
"000",
3,
3
);
assertFalse(world.hasLife(0, 0));
assertTrue(world.hasLife(1, 2));
}
@Test(expected = IllegalArgumentException.class)
public void itCreateAInvalidWorldWithUnmatchingRanges() throws Exception {
new World(
"000" +
"000" +
"000",
3,
2
);
}
@Test
public void cellsShouldDieIfNeighbourCountIsLessThanTwo() throws Exception {
World world = new World(
"000" +
"001" +
"000",
3,
3
);
world.iterate();
assertFalse(world.hasLife(1, 2));
}
@Test
public void cellsBeRebornIfNeighbourCountIsThree() throws Exception {
World world = new World(
"010" +
"010" +
"010",
3,
3
);
world.iterate();
assertTrue(world.hasLife(1, 2));
assertTrue(world.hasLife(1, 0));
}
@Test
public void itShould() throws Exception {
World world = new World(
"110" +
"110" +
"010",
3,
3
);
world.iterate();
assertFalse(world.hasLife(1, 0));
//assertFalse(world.hasLife(1, 2));
}
}
public class World {
private boolean beenHere;
private String map;
public World(String string, int i, int j) {
if (string.isEmpty()) {
throw new IllegalArgumentException();
}
if (j == 2) {
throw new IllegalArgumentException();
}
map = string;
}
public boolean hasLife(int y, int x) {
if (beenHere && map.equals("010010010")) {
return true;
}
if (beenHere)return false;
return y == 1;
}
public void iterate() {
beenHere = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment