-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db0a69e
commit 4077b27
Showing
4 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,32 @@ | ||
/** | ||
* Created by clay on 4/15/17. | ||
*/ | ||
public class LifeBoard { | ||
public class LifeBoard implements Board { | ||
public static final int X_MAX = 50; | ||
public static final int Y_MAX = 50; | ||
static public boolean[][] value = new boolean[X_MAX][Y_MAX]; | ||
|
||
|
||
public void clear() { | ||
for(int x=0; x < X_MAX; ++x) { | ||
for(int y=0; y < Y_MAX; ++y) { | ||
value[x][y] = false; | ||
} | ||
} | ||
} | ||
|
||
public int at(int x, int y) { | ||
if (value[x][y]) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
public void set(int x, int y, int value) { | ||
if (0 == value) { | ||
this.value[x][y] = false; | ||
} else { | ||
this.value[x][y] = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Created by clay on 4/15/17. | ||
*/ | ||
public class LifeBoardTest { | ||
|
||
private LifeBoard board; | ||
|
||
@Before | ||
public void setUp() { | ||
board = new LifeBoard(); | ||
board.clear(); | ||
} | ||
|
||
@Test | ||
public void clear_byDefault_setsAllValuesToFalse() { | ||
board.value[10][10] = true; | ||
board.clear(); | ||
assertThat(board.value[10][10], is(false)); | ||
} | ||
|
||
@Test | ||
public void at_forATrueCell_returnsOne() { | ||
board.value[10][10] = true; | ||
assertThat(board.at(10, 10), is(1)); | ||
} | ||
|
||
@Test | ||
public void at_forFalseCell_returnsZero() { | ||
board.value[10][10] = false; | ||
assertThat(board.at(10, 10), is(0)); | ||
} | ||
|
||
@Test | ||
public void set_givenZero_willReturnZeroFromAt() { | ||
board.value[10][10] = true; | ||
board.set(10, 10, 0); | ||
assertThat(board.at(10, 10), is(0)); | ||
} | ||
|
||
} |