import junit.framework.TestCase; @author Tuomas Kärkkäinen @author Hans Häggström @author Mika Viljanen @author Allan Halme @author Jukka Lindström @author Antti Mattila @author Pauliina Hellman @author Pasi Heikkinen @author Jarkko Laine @author Pekka Enberg @author Kimmo Karlsson @author Kristo Helasvuo @author Bas Vodde @author Kare Nuorteva public class BoardTest extends TestCase { private Board board; @Override protected void setUp() throws Exception { board = new Board(); } public void testBoardSizeIsNine() { assertEquals(9, Board.BOARD_SIZE); } public void testDigitCanBePlacedOnBoard() { board.place(0, 0, 1); } public void testDigitsFromOneToNineCanBePlacedOnBoard() throws Exception { for (int i = 1; i <= 9; i++) { new Board().place(0, 0, i); } } public void testPlacingNegativeShouldNotBeAllowed() throws Exception { assertCannotPlace("Should throw exception since number is illegal.", -1, 0, 0); } public void testPlacingZeroShouldNotBeAllowed() throws Exception { assertCannotPlace("Should throw exception since number is illegal.", 0, 0, 0); } public void testPlacingTenShouldNotBeAllowed() throws Exception { assertCannotPlace("Should throw exception since number is illegal.", 10, 0, 0); } public void testPlacingGreaterThanTenShouldNotBeAllowed() throws Exception { assertCannotPlace("Should throw exception since number is illegal.", 11, 0, 0); } private void assertCannotPlace(String failMessage, int number, int row, int column) { try { board.place(row, column, number); fail(failMessage); } catch (IllegalArgumentException e) { } } public void testCannotPlaceIfNegativeColumn() throws Exception { assertCannotPlace("Column is negative", 0, -1, 1); } public void testCannotPlaceIfColumnTooHigh() throws Exception { assertCannotPlace("Column too large!", Board.BOARD_SIZE + 1, 0, 1); } public void testThatWeHaveSomethingWhereWePutIt() throws Exception { board.place(1, 1, 2); assertEquals(2, board.get(1, 1)); } public void testShouldBeAbleToPlaceSameNumberTwiceOnSameRow() { board.place(0, 0, 1); board.place(0, 1, 1); assertEquals(1, board.get(0, 1)); } public void testInitialBoardIsNotSolved() throws Exception { assertFalse(new Board().isSolved()); } public void testPlacingSameNumberOnTheSameRowShouldBeIncorect() throws Exception { assertTrue(board.place(0, 0, 1)); assertTrue(board.isCorrect()); assertFalse(board.place(0, 1, 1)); assertFalse(board.isCorrect()); } public void testPlacingANumberTwiceIntoSamePlace() throws Exception { int number = 2; board.place(0, 0, number); assertCannotPlace( "Should throw exception since number is placed twice in the same place.", number, 0, 0); } }