From a00e643d061f58f36cc500498452d030731efe00 Mon Sep 17 00:00:00 2001 From: Joseph Venetucci Date: Wed, 26 Jul 2017 20:25:50 -0700 Subject: [PATCH] Finished 6/8 Test cases --- .../edu/pdx/cs410J/katas/Minesweeper.java | 68 ++++++++++++++++--- .../edu/pdx/cs410J/katas/MinesweeperTest.java | 26 ++++--- 2 files changed, 72 insertions(+), 22 deletions(-) diff --git a/minesweeper/src/main/java/edu/pdx/cs410J/katas/Minesweeper.java b/minesweeper/src/main/java/edu/pdx/cs410J/katas/Minesweeper.java index 3fe6bf0..d97ac70 100644 --- a/minesweeper/src/main/java/edu/pdx/cs410J/katas/Minesweeper.java +++ b/minesweeper/src/main/java/edu/pdx/cs410J/katas/Minesweeper.java @@ -1,16 +1,68 @@ package edu.pdx.cs410J.katas; -public class Minesweeper { +public class Minesweeper { + int row; + int column; - public Minesweeper(int row, int column) { + char[][] board; - } + int indexRow = 0; - public void addRow(String row) { + public Minesweeper(int row, int column) throws ZeroSizedBoardException { + if (row == 0 || column == 0) + throw new ZeroSizedBoardException(); + this.row = row; + this.column = column; - } + board = new char[row][column]; + } - public String solve() { - return null; - } + public void addRow(String row) throws RaggedBoardException { + if (row.length() != this.column) { + throw new RaggedBoardException(); + } + for (int z = 0; z < this.column; ++z) { + board[indexRow][z] = row.charAt(z); + } + ++indexRow; + + } + + public String solve() { + StringBuilder sb = new StringBuilder(); + for (int rowCount = 0; rowCount < this.row; rowCount++) { + for (int columnCount = 0; columnCount < this.column; columnCount++) { + //if (board[rowCount][columnCount] == '.') { + // sb.append(checkMines(rowCount, columnCount)); + //} else { + sb.append(board[rowCount][columnCount]); + //} + } + if (rowCount > 1) { + sb.append("\n"); + } + } + return sb.toString(); + } + + /* + private int checkMines(int rowCount, int columnCount) { + int numberOfSurroundingMines = 0; + + for (int rowCheckPos = rowCount - 1; rowCheckPos <= rowCount + 1; rowCheckPos++) { + if (rowCheckPos < 0 || rowCheckPos > this.row) { + continue; + } else { + for (int colCheckPos = columnCount - 1; colCheckPos <= columnCount + 1; colCheckPos++) { + if (colCheckPos < 0 || colCheckPos > this.column) { + continue; + } else if (board[rowCheckPos][colCheckPos] == '*') { + numberOfSurroundingMines++; + } + } + } + } + return numberOfSurroundingMines; + } + */ } diff --git a/minesweeper/src/test/java/edu/pdx/cs410J/katas/MinesweeperTest.java b/minesweeper/src/test/java/edu/pdx/cs410J/katas/MinesweeperTest.java index c209511..e68bb3b 100644 --- a/minesweeper/src/test/java/edu/pdx/cs410J/katas/MinesweeperTest.java +++ b/minesweeper/src/test/java/edu/pdx/cs410J/katas/MinesweeperTest.java @@ -11,42 +11,40 @@ */ 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("*"); @@ -56,7 +54,7 @@ public void oneSquareWithMine() { @Ignore @Test - public void oneSquareWithNoMine() { + public void oneSquareWithNoMine() throws ZeroSizedBoardException, RaggedBoardException { Minesweeper board = new Minesweeper(1, 1); board.addRow("."); @@ -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("..");