Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions minesweeper/src/main/java/edu/pdx/cs410J/katas/Minesweeper.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
package edu.pdx.cs410J.katas;

public class Minesweeper {
import java.util.ArrayList;
import java.util.List;

public Minesweeper(int row, int column) {
public class Minesweeper {
private int row, column;
private List<Character> board = new ArrayList<>();

public Minesweeper(int row, int column) throws ZeroSizedBoardException{
if(row == 0 || column == 0){
throw new ZeroSizedBoardException();
}
this.row = row;
this.column = column;
}

public void addRow(String row) {
public void addRow(String row) throws RaggedBoardException{

if(row.length() != this.column){
throw new RaggedBoardException();
}
for(int i = 0; i<row.length(); i++){
this.board.add(row.charAt(i));
}

}

public String solve() {
return null;
String solved = "";
for(char c: this.board){
if(c == '*'){
solved += "*";
}
else if(c == '.'){
solved += "0";
}
}
return solved;
}
}
28 changes: 13 additions & 15 deletions minesweeper/src/test/java/edu/pdx/cs410J/katas/MinesweeperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,50 @@
*/
public class MinesweeperTest {

@Ignore

@Test(expected = ZeroSizedBoardException.class)
public void zeroSizedBoardThrowException() {
public void zeroSizedBoardThrowException() throws ZeroSizedBoardException{
new Minesweeper(0, 0);
}

@Ignore

@Test(expected = ZeroSizedBoardException.class)
public void boardWithZeroRowsThrowsException() {
public void boardWithZeroRowsThrowsException() throws ZeroSizedBoardException{
new Minesweeper(0, 5);
}

@Ignore

@Test(expected = ZeroSizedBoardException.class)
public void boardWithZeroColumnsThrowsException() {
public void boardWithZeroColumnsThrowsException() throws ZeroSizedBoardException {
new Minesweeper(5, 0);
}

@Ignore

@Test(expected = RaggedBoardException.class)
public void raggedInputRowThrowsException() {
public void raggedInputRowThrowsException() throws ZeroSizedBoardException,RaggedBoardException {
Minesweeper board = new Minesweeper(1, 2);
board.addRow(".");
}

@Ignore
@Test(expected = RaggedBoardException.class)
public void raggedInputColumnThrowsException() {
public void raggedInputColumnThrowsException() throws ZeroSizedBoardException, RaggedBoardException{
Minesweeper board = new Minesweeper(2, 1);
board.addRow(".");
board.addRow("..");
}

@Ignore
@Test
public void oneSquareWithMine() {
public void oneSquareWithMine() throws ZeroSizedBoardException, RaggedBoardException{
Minesweeper board = new Minesweeper(1, 1);
board.addRow("*");

String solved = board.solve();
assertThat(solved, equalTo("*"));
}

@Ignore

@Test
public void oneSquareWithNoMine() {
public void oneSquareWithNoMine() throws ZeroSizedBoardException, RaggedBoardException{
Minesweeper board = new Minesweeper(1, 1);
board.addRow(".");

Expand All @@ -66,7 +64,7 @@ public void oneSquareWithNoMine() {

@Ignore
@Test
public void twoByTwoBoardWithMineAtZeroZero() {
public void twoByTwoBoardWithMineAtZeroZero() throws ZeroSizedBoardException,RaggedBoardException {
Minesweeper board = new Minesweeper(2, 2);
board.addRow("*.");
board.addRow("..");
Expand Down