import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.junit.Assert.assertEquals; public final class MinesweeperBoardTest { /* * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and * ExpectedExceptions in particular. */ @Rule public ExpectedException expectedException = ExpectedException.none(); @Test public void testInputBoardWithNoRowsAndNoColumns() { final List inputBoard = Collections.emptyList(); final List expectedAnnotatedRepresentation = Collections.emptyList(); final List actualAnnotatedRepresentation = new MinesweeperBoard(inputBoard).getAnnotatedRepresentation(); assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation); } @Ignore @Test public void testInputBoardWithOneRowAndNoColumns() { final List inputBoard = Collections.singletonList(""); final List expectedAnnotatedRepresentation = Collections.singletonList(""); final List actualAnnotatedRepresentation = new MinesweeperBoard(inputBoard).getAnnotatedRepresentation(); assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation); } @Ignore @Test public void testInputBoardWithNoMines() { final List inputBoard = Arrays.asList( " ", " ", " " ); final List expectedAnnotatedRepresentation = Arrays.asList( " ", " ", " " ); final List actualAnnotatedRepresentation = new MinesweeperBoard(inputBoard).getAnnotatedRepresentation(); assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation); } @Ignore @Test public void testInputBoardWithOnlyMines() { final List inputBoard = Arrays.asList( "***", "***", "***" ); final List expectedAnnotatedRepresentation = Arrays.asList( "***", "***", "***" ); final List actualAnnotatedRepresentation = new MinesweeperBoard(inputBoard).getAnnotatedRepresentation(); assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation); } @Ignore @Test public void testInputBoardWithSingleMineAtCenter() { final List inputBoard = Arrays.asList( " ", " * ", " " ); final List expectedAnnotatedRepresentation = Arrays.asList( "111", "1*1", "111" ); final List actualAnnotatedRepresentation = new MinesweeperBoard(inputBoard).getAnnotatedRepresentation(); assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation); } @Ignore @Test public void testInputBoardWithMinesAroundPerimeter() { final List inputBoard = Arrays.asList( "***", "* *", "***" ); final List expectedAnnotatedRepresentation = Arrays.asList( "***", "*8*", "***" ); final List actualAnnotatedRepresentation = new MinesweeperBoard(inputBoard).getAnnotatedRepresentation(); assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation); } @Ignore @Test public void testInputBoardWithSingleRowAndTwoMines() { final List inputBoard = Collections.singletonList( " * * " ); final List expectedAnnotatedRepresentation = Collections.singletonList( "1*2*1" ); final List actualAnnotatedRepresentation = new MinesweeperBoard(inputBoard).getAnnotatedRepresentation(); assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation); } @Ignore @Test public void testInputBoardWithSingleRowAndTwoMinesAtEdges() { final List inputBoard = Collections.singletonList( "* *" ); final List expectedAnnotatedRepresentation = Collections.singletonList( "*1 1*" ); final List actualAnnotatedRepresentation = new MinesweeperBoard(inputBoard).getAnnotatedRepresentation(); assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation); } @Ignore @Test public void testInputBoardWithSingleColumnAndTwoMines() { final List inputBoard = Arrays.asList( " ", "*", " ", "*", " " ); final List expectedAnnotatedRepresentation = Arrays.asList( "1", "*", "2", "*", "1" ); final List actualAnnotatedRepresentation = new MinesweeperBoard(inputBoard).getAnnotatedRepresentation(); assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation); } @Ignore @Test public void testInputBoardWithSingleColumnAndTwoMinesAtEdges() { final List inputBoard = Arrays.asList( "*", " ", " ", " ", "*" ); final List expectedAnnotatedRepresentation = Arrays.asList( "*", "1", " ", "1", "*" ); final List actualAnnotatedRepresentation = new MinesweeperBoard(inputBoard).getAnnotatedRepresentation(); assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation); } @Ignore @Test public void testInputBoardWithMinesInCross() { final List inputBoard = Arrays.asList( " * ", " * ", "*****", " * ", " * " ); final List expectedAnnotatedRepresentation = Arrays.asList( " 2*2 ", "25*52", "*****", "25*52", " 2*2 " ); final List actualAnnotatedRepresentation = new MinesweeperBoard(inputBoard).getAnnotatedRepresentation(); assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation); } @Ignore @Test public void testLargeInputBoard() { final List inputBoard = Arrays.asList( " * * ", " * ", " * ", " * *", " * * ", " " ); final List expectedAnnotatedRepresentation = Arrays.asList( "1*22*1", "12*322", " 123*2", "112*4*", "1*22*2", "111111" ); final List actualAnnotatedRepresentation = new MinesweeperBoard(inputBoard).getAnnotatedRepresentation(); assertEquals(expectedAnnotatedRepresentation, actualAnnotatedRepresentation); } @Ignore @Test public void testNullInputBoardIsRejected() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Input board may not be null."); new MinesweeperBoard(null); } @Ignore @Test public void testInputBoardWithInvalidSymbolsIsRejected() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Input board can only contain the characters ' ' and '*'."); new MinesweeperBoard(Collections.singletonList(" * & ")); } @Ignore @Test public void testInputBoardWithInconsistentRowLengthsIsRejected() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Input board rows must all have the same number of columns."); new MinesweeperBoard(Arrays.asList( "*", "**", "* *", "* *", "* *" )); } }