[Picross-commit] SF.net SVN: picross: [42] trunk
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2007-06-29 07:02:43
|
Revision: 42 http://picross.svn.sourceforge.net/picross/?rev=42&view=rev Author: yvan_norsa Date: 2007-06-29 00:02:39 -0700 (Fri, 29 Jun 2007) Log Message: ----------- unit tests Modified Paths: -------------- trunk/build.xml trunk/src/picross/game/random/RandomPicrossModel.java trunk/src/picross/grid/Box.java trunk/src/picross/grid/CompletedHints.java trunk/src/picross/grid/FillCommand.java trunk/src/picross/grid/GridController.java trunk/src/picross/grid/GridMediator.java trunk/src/picross/grid/GridModel.java trunk/src/picross/grid/PaintCommand.java Added Paths: ----------- trunk/src/picross/grid/BoxTest.java trunk/src/picross/grid/CompletedHintsTest.java trunk/src/picross/grid/FillCommandTest.java trunk/src/picross/grid/GridAction.java trunk/src/picross/grid/GridModelTest.java trunk/src/picross/grid/IGridMediator.java trunk/src/picross/grid/PaintCommandTest.java trunk/src/picross/grid/tests/ trunk/src/picross/grid/tests/IGridMediatorStub.java Removed Paths: ------------- trunk/src/picross/grid/CompletedCommand.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2007-06-17 18:55:46 UTC (rev 41) +++ trunk/build.xml 2007-06-29 07:02:39 UTC (rev 42) @@ -149,10 +149,10 @@ <target name="doc" depends="compile"> <!-- FIXME test classes which are not in a "tests" subpackage - shouldn't be included in the generated Javadoc --> - <javadoc destdir="${doc.dir}" - link="http://java.sun.com/j2se/1.5.0/docs/api"> - <packageset dir="${src.dir}" + shouldn't be included in the generated Javadoc --> + <javadoc destdir="${doc.dir}" access="private" + link="http://java.sun.com/j2se/1.5.0/docs/api"> + <packageset dir="${src.dir}" defaultexcludes="yes"> <exclude name="**/tests/**" /> </packageset> Modified: trunk/src/picross/game/random/RandomPicrossModel.java =================================================================== --- trunk/src/picross/game/random/RandomPicrossModel.java 2007-06-17 18:55:46 UTC (rev 41) +++ trunk/src/picross/game/random/RandomPicrossModel.java 2007-06-29 07:02:39 UTC (rev 42) @@ -69,9 +69,17 @@ this.data = new boolean[this.width][this.height]; - for (int i = 0; i < this.width; i++) { - for (int j = 0; j < this.height; j++) { - this.data[i][j] = rand.nextBoolean(); + boolean gridOK = false; + + while (!gridOK) { + for (int i = 0; i < this.width; i++) { + for (int j = 0; j < this.height; j++) { + this.data[i][j] = rand.nextBoolean(); + + if (this.data[i][j]) { + gridOK = true; + } + } } } } Modified: trunk/src/picross/grid/Box.java =================================================================== --- trunk/src/picross/grid/Box.java 2007-06-17 18:55:46 UTC (rev 41) +++ trunk/src/picross/grid/Box.java 2007-06-29 07:02:39 UTC (rev 42) @@ -233,8 +233,14 @@ * Permits to define the rectangle occupied by the box. * * @param rect rectangle of the box + * @throws IllegalArgumentException if <code>rect</code> + * is <code>null</code> */ - void setRect(Rectangle rect) { + void setRect(Rectangle rect) throws IllegalArgumentException { + if (rect == null) { + throw new IllegalArgumentException("rect cannot be null"); + } + this.rect = rect; } Added: trunk/src/picross/grid/BoxTest.java =================================================================== --- trunk/src/picross/grid/BoxTest.java (rev 0) +++ trunk/src/picross/grid/BoxTest.java 2007-06-29 07:02:39 UTC (rev 42) @@ -0,0 +1,156 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author Y. Norsa + */ +public class BoxTest { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + private Box box = null; + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + BoxTest() { + } + */ + /*** M\xE9thode ***/ + + @Before + public void setUp() { + this.box = new Box(); + } + + @Test + public void testCheck() { + this.box.check(); + Assert.assertTrue("box unchecked", this.box.isChecked()); + } + + @Test + public void testCross() { + this.box.cross(); + Assert.assertTrue("box not crossed", this.box.isCrossed()); + } + + @Test + public void testEmpty() { + this.box.empty(); + Assert.assertTrue("box not empty", this.box.isEmpty()); + } + + @Test + public void testEquals() { + Assert.assertFalse("this.box = null", this.box.equals(null)); + Assert.assertTrue("box != box", this.box.equals(this.box)); + + this.box.check(); + + Box box2 = new Box(); + Assert.assertFalse("box = box2", this.box.equals(box2)); + + box2.check(); + + Assert.assertTrue("box != box2", this.box.equals(box2)); + } + + @Test + public void testgetIcon() { + Assert.assertNotNull("empty icon = null", this.box.getIcon()); + + this.box.check(); + Assert.assertNotNull("checked icon = null", this.box.getIcon()); + + this.box.cross(); + Assert.assertNotNull("crossed icon = null", this.box.getIcon()); + } + + @Test + public void testGetRolloverIcon() { + Assert.assertNotNull("rollover empty icon = null", + this.box.getRolloverIcon()); + + this.box.check(); + Assert.assertNotNull("rollover checked icon = null", + this.box.getRolloverIcon()); + + this.box.cross(); + Assert.assertNotNull("rollover crossed icon = null", + this.box.getRolloverIcon()); + } + + @Test + public void testIsChecked() { + this.box.check(); + + Assert.assertFalse("box crossed AND checked", this.box.isCrossed()); + Assert.assertFalse("box empty AND checked", this.box.isEmpty()); + } + + @Test + public void testIsCrossed() { + this.box.cross(); + + Assert.assertFalse("box checked AND crossed", this.box.isChecked()); + Assert.assertFalse("box empty AND crossed", this.box.isEmpty()); + } + + @Test + public void testIsEmpty() { + Assert.assertFalse("box checked AND empty", this.box.isChecked()); + Assert.assertFalse("box crossed AND empty", this.box.isCrossed()); + } + + @Test + public void testSetRect() { + try { + this.box.setRect(null); + Assert.fail("box.setRect(null)"); + } catch (IllegalArgumentException argEx) { } + } +} + Property changes on: trunk/src/picross/grid/BoxTest.java ___________________________________________________________________ Name: svn:keywords + Id Deleted: trunk/src/picross/grid/CompletedCommand.java =================================================================== --- trunk/src/picross/grid/CompletedCommand.java 2007-06-17 18:55:46 UTC (rev 41) +++ trunk/src/picross/grid/CompletedCommand.java 2007-06-29 07:02:39 UTC (rev 42) @@ -1,107 +0,0 @@ -/* - * $Id$ - * - * Copyright (c) 2007 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - */ - - -package picross.grid; - -import fr.cle.mmvcs.Command; - -/** - * Command indicating that a hint has been completed. - * - * @author Y. Norsa - */ -final class CompletedCommand extends Command { - /*** Constants ***/ - - /** A column hint has been completed. */ - static final int COLUMN = 0; - - /** A row hint has been completed. */ - static final int ROW = 1; - - /*** Fields ***/ - - /** Type of hint that has been completed. */ - private int type; - - /** Number of the column or row. */ - private int position; - - /** Position of the hint in the column or row. */ - private int hintPos; - - /*** Constructor ***/ - - /** - * Constructor. - * - * @param type type of hint that has been completed - * @param position number of the column or row - * @param hintPos position of the hint in the column or row - */ - CompletedCommand(int type, int position, int hintPos) { - this.type = type; - this.position = position; - this.hintPos = hintPos; - } - - /*** Accessors ***/ - - /** - * Returns the type of hint that has been completed. - * - * @return type of hint that has been completed - */ - int getType() { - return this.type; - } - - /** - * Returns the number of the column or row. - * - * @return number of the column or row - */ - int getPosition() { - return this.position; - } - - /** - * Returns the position of the hint in the column or row. - * - * @return position of the hint in the column or row - */ - int getHintPos() { - return this.hintPos; - } -} - Modified: trunk/src/picross/grid/CompletedHints.java =================================================================== --- trunk/src/picross/grid/CompletedHints.java 2007-06-17 18:55:46 UTC (rev 41) +++ trunk/src/picross/grid/CompletedHints.java 2007-06-29 07:02:39 UTC (rev 42) @@ -59,9 +59,32 @@ * @param colsHintsHeight height of the column hints list * @param rowsHintsWidth width of the row hints list * @param rowsHintsHeight height of the row hints list + * @throws IllegalArgumentException if one of the parameters is <= 0 */ CompletedHints(int colsHintsWidth, int colsHintsHeight, - int rowsHintsWidth, int rowsHintsHeight) { + int rowsHintsWidth, int rowsHintsHeight) + throws IllegalArgumentException { + + if (colsHintsWidth <= 0) { + throw new IllegalArgumentException("colsHintsWidth must be " + + "greater than 0"); + } + + if (colsHintsHeight <= 0) { + throw new IllegalArgumentException("colsHintsHeight must be " + + "greater than 0"); + } + + if (rowsHintsWidth <= 0) { + throw new IllegalArgumentException("rowsHintsWidth must be " + + "greater than 0"); + } + + if (rowsHintsHeight <= 0) { + throw new IllegalArgumentException("rowsHintsHeight must be " + + "greater than 0"); + } + this.completedCols = new boolean[colsHintsWidth][colsHintsHeight]; this.completedRows = new boolean[rowsHintsWidth][rowsHintsHeight]; } @@ -84,8 +107,19 @@ * * @param column column number * @return list of completed hints in the column + * @throws IllegalArgumentException if <code>column</code> is lesser + * than 0 or greater than the number of hints columns */ - List<Integer> getCompleteColHints(int column) { + List<Integer> getCompleteColHints(int column) + throws IllegalArgumentException { + + if (column < 0 || column >= this.completedCols.length) { + throw new IllegalArgumentException("column must be between 0 " + + "and " + + (this.completedCols.length + - 1)); + } + List<Integer> res = new ArrayList<Integer>(); for (int i = 0; i < this.completedCols[column].length; i++) { @@ -133,8 +167,18 @@ * * @param row row number * @return list of completed hints in the row + * @throws IllegalArgumentException if <code>row</code> is lesser + * than 0 or greater than the number of hints row */ - List<Integer> getCompleteRowHints(int row) { + List<Integer> getCompleteRowHints(int row) + throws IllegalArgumentException { + + if (row < 0 || row >= this.completedRows.length) { + throw new IllegalArgumentException("row must be between 0 and " + + (this.completedRows.length + - 1)); + } + List<Integer> res = new ArrayList<Integer>(); for (int i = 0; i < this.completedRows[row].length; i++) { Added: trunk/src/picross/grid/CompletedHintsTest.java =================================================================== --- trunk/src/picross/grid/CompletedHintsTest.java (rev 0) +++ trunk/src/picross/grid/CompletedHintsTest.java 2007-06-29 07:02:39 UTC (rev 42) @@ -0,0 +1,205 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author Y. Norsa + */ +public class CompletedHintsTest { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + CompletedHints hints = null; + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + CompletedHintsTest() { + } + */ + /*** M\xE9thode ***/ + + @Before + public void setUp() { + this.hints = new CompletedHints(10, 10, 10, 10); + } + + @Test + public void testCompletedHints() { + try { + new CompletedHints(-1, -1, -1, -1); + Assert.fail("colsHintsWidth = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + new CompletedHints(0, -1, -1, -1); + Assert.fail("colsHintsWidth = 0"); + } catch (IllegalArgumentException argEx) { } + + try { + new CompletedHints(1, -1, -1, -1); + Assert.fail("colsHintsHeight = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + new CompletedHints(1, 0, -1, -1); + Assert.fail("colsHintsHeight = 0"); + } catch (IllegalArgumentException argEx) { } + + try { + new CompletedHints(1, 1, -1, -1); + Assert.fail("rowsHintsWidth = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + new CompletedHints(1, 1, 0, -1); + Assert.fail("rowsHintsWidth = 0"); + } catch (IllegalArgumentException argEx) { } + + try { + new CompletedHints(1, 1, 1, -1); + Assert.fail("rowsHintsHeight = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + new CompletedHints(1, 1, 1, 0); + Assert.fail("rowsHintsHeight = 0"); + } catch (IllegalArgumentException argEx) { } + } + + @Test + public void testClearColHint() { + this.hints.setCompleteColHint(3, 4); + this.hints.clearColHint(3, 4); + Assert.assertFalse(this.hints.isColHintComplete(3, 4)); + } + + @Test + public void testClearRowHint() { + this.hints.setCompleteRowHint(8, 2); + this.hints.clearRowHint(8, 2); + Assert.assertFalse(this.hints.isRowHintComplete(8, 2)); + } + + @Test + public void testGetCompleteColHints() { + try { + this.hints.getCompleteColHints(-1); + Assert.fail("column = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + this.hints.getCompleteColHints(42); + Assert.fail("column = 42"); + } catch (IllegalArgumentException argEx) { } + + List<Integer> complete = this.hints.getCompleteColHints(4); + Assert.assertNotNull("complete = null", complete); + int size = complete.size(); + Assert.assertTrue("size = " + size, (size == 0)); + + this.hints.setCompleteColHint(4, 0); + this.hints.setCompleteColHint(4, 9); + + complete = this.hints.getCompleteColHints(4); + Assert.assertNotNull("complete = null", complete); + size = complete.size(); + Assert.assertTrue("size = " + size, (size == 2)); + + int nb1 = complete.get(0); + Assert.assertTrue("nb1 = " + nb1, (nb1 == 0)); + + int nb2 = complete.get(1); + Assert.assertTrue("nb2 = " + nb2, (nb2 == 9)); + } + + @Test + public void testGetCompleteRowHints() { + try { + this.hints.getCompleteRowHints(-1); + Assert.fail("row = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + this.hints.getCompleteRowHints(42); + Assert.fail("row = 42"); + } catch (IllegalArgumentException argEx) { } + + List<Integer> complete = this.hints.getCompleteRowHints(9); + Assert.assertNotNull("complete = null", complete); + int size = complete.size(); + Assert.assertTrue("size = " + size, (size == 0)); + + this.hints.setCompleteRowHint(9, 3); + this.hints.setCompleteRowHint(9, 6); + + complete = this.hints.getCompleteRowHints(9); + Assert.assertNotNull("complete = null", complete); + size = complete.size(); + Assert.assertTrue("size = " + size, (size == 2)); + + int nb1 = complete.get(0); + Assert.assertTrue("nb1 = " + nb1, (nb1 == 3)); + + int nb2 = complete.get(1); + Assert.assertTrue("nb2 = " + nb2, (nb2 == 6)); + } + + @Test + public void testIsColHintCompleteAndSetCompleteColHint() { + Assert.assertFalse(this.hints.isColHintComplete(0, 0)); + this.hints.setCompleteColHint(0, 0); + Assert.assertTrue(this.hints.isColHintComplete(0, 0)); + } + + @Test + public void testIsRowHintCompleteAndSetCompleteRowHint() { + Assert.assertFalse(this.hints.isRowHintComplete(5, 5)); + this.hints.setCompleteRowHint(5, 5); + Assert.assertTrue(this.hints.isRowHintComplete(5, 5)); + } +} + Property changes on: trunk/src/picross/grid/CompletedHintsTest.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/grid/FillCommand.java =================================================================== --- trunk/src/picross/grid/FillCommand.java 2007-06-17 18:55:46 UTC (rev 41) +++ trunk/src/picross/grid/FillCommand.java 2007-06-29 07:02:39 UTC (rev 42) @@ -50,7 +50,8 @@ private int column; /** Type of the action. */ - private int type; + //private int type; + private GridAction type; /*** Constructor ***/ @@ -60,8 +61,26 @@ * @param row row of the box to fill * @param column column of the box to fill * @param type type of the action + * @throws IllegalArgumentException if <code>row</code> + * or <code>column</code> is less than 0, or <code>type</code> + * is <code>GridAction.UNKNOWN</code> */ - FillCommand(int row, int column, int type) { + //FillCommand(int row, int column, int type) { + FillCommand(int row, int column, GridAction type) + throws IllegalArgumentException { + + if (row < 0) { + throw new IllegalArgumentException("row can't be less than 0"); + } + + if (column < 0) { + throw new IllegalArgumentException("column can't be less than 0"); + } + + if (type == GridAction.UNKNOWN) { + throw new IllegalArgumentException("type can't be UNKNOWN"); + } + this.row = row; this.column = column; this.type = type; @@ -99,7 +118,8 @@ * * @return type of the action */ - int getType() { + //int getType() { + GridAction getType() { return this.type; } } Added: trunk/src/picross/grid/FillCommandTest.java =================================================================== --- trunk/src/picross/grid/FillCommandTest.java (rev 0) +++ trunk/src/picross/grid/FillCommandTest.java 2007-06-29 07:02:39 UTC (rev 42) @@ -0,0 +1,80 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Y. Norsa + */ +public class FillCommandTest { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + FillCommandTest() { + } + */ + /*** M\xE9thode ***/ + + @Test + public void testFillCommand() { + try { + new FillCommand(-1, -1, GridAction.UNKNOWN); + Assert.fail("row = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + new FillCommand(0, -1, GridAction.UNKNOWN); + Assert.fail("column = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + new FillCommand(0, 0, GridAction.UNKNOWN); + Assert.fail("UNKNOWN type"); + } catch (IllegalArgumentException argEx) { } + + new FillCommand(0, 0, GridAction.CHECK); + } +} + Property changes on: trunk/src/picross/grid/FillCommandTest.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/grid/GridAction.java =================================================================== --- trunk/src/picross/grid/GridAction.java (rev 0) +++ trunk/src/picross/grid/GridAction.java 2007-06-29 07:02:39 UTC (rev 42) @@ -0,0 +1,59 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +/** + * @author Y. Norsa + */ +enum GridAction { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + */ + + /*** M\xE9thode ***/ + UNKNOWN, + CHECK, + CROSS +} + Property changes on: trunk/src/picross/grid/GridAction.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/grid/GridController.java =================================================================== --- trunk/src/picross/grid/GridController.java 2007-06-17 18:55:46 UTC (rev 41) +++ trunk/src/picross/grid/GridController.java 2007-06-29 07:02:39 UTC (rev 42) @@ -76,10 +76,10 @@ static final String REPAINT_LEFT_HINTS_CMD = "REPAINT_LEFT_HINTS_CMD"; /** Checking a box. */ - static final int CHECK_ACTION = 0; + //static final int CHECK_ACTION = 0; /** Crossing a box. */ - static final int CROSS_ACTION = 1; + //static final int CROSS_ACTION = 1; /*** Static field ***/ @@ -193,7 +193,8 @@ if (this.view.isInGrid(point)) { int row = this.view.getRow(point); int column = this.view.getColumn(point); - int type = GridController.modifiersToType(modifiers); + //int type = GridController.modifiersToType(modifiers); + GridAction type = GridController.modifiersToType(modifiers); //GridController.log.debug("type : " + type); @@ -209,16 +210,20 @@ * @param modifiers mouse event modifiers * @return corresponding action, or -1 */ - private static int modifiersToType(int modifiers) { + //private static int modifiersToType(int modifiers) { + private static GridAction modifiersToType(int modifiers) { switch (modifiers) { case MouseEvent.BUTTON1_MASK: - return GridController.CHECK_ACTION; + //return GridController.CHECK_ACTION; + return GridAction.CHECK; case MouseEvent.BUTTON3_MASK: - return GridController.CROSS_ACTION; + //return GridController.CROSS_ACTION; + return GridAction.CROSS; default: - return -1; + //return -1; + return GridAction.UNKNOWN; } } Modified: trunk/src/picross/grid/GridMediator.java =================================================================== --- trunk/src/picross/grid/GridMediator.java 2007-06-17 18:55:46 UTC (rev 41) +++ trunk/src/picross/grid/GridMediator.java 2007-06-29 07:02:39 UTC (rev 42) @@ -49,7 +49,7 @@ * * @author Y. Norsa */ -public final class GridMediator extends Mediateur { +public final class GridMediator extends Mediateur implements IGridMediator { /*** Static field ***/ /** Class' logger. */ @@ -106,7 +106,7 @@ if (cmd.equals(GridController.FILL_CMD)) { FillCommand command = (FillCommand) e.getCommand(); - this.model.checkBox(command.getRow(), command.getColumn(), + this.model.actOnBox(command.getRow(), command.getColumn(), command.getType()); return; @@ -118,10 +118,10 @@ } } - /*** Methods ***/ + /*** Methods implanted from the interface IGridMediator ***/ /** Tells the application mediator the grid has been filled. */ - void congratulations() { + public void congratulations() { this.fireEventPerformed(GridController.GRID_FILLED_CMD); } @@ -131,18 +131,18 @@ * @param row row number of the box * @param column column number of the box */ - void repaint(int row, int column) { + public void repaint(int row, int column) { this.fireEventPerformed(GridController.PAINT_CMD, new PaintCommand(row, column)); } /** Asks to repaint the column hints. */ - void repaintColHints() { + public void repaintColHints() { this.fireEventPerformed(GridController.REPAINT_TOP_HINTS_CMD); } /** Asks to repaint the row hints. */ - void repaintRowHints() { + public void repaintRowHints() { this.fireEventPerformed(GridController.REPAINT_LEFT_HINTS_CMD); } Modified: trunk/src/picross/grid/GridModel.java =================================================================== --- trunk/src/picross/grid/GridModel.java 2007-06-17 18:55:46 UTC (rev 41) +++ trunk/src/picross/grid/GridModel.java 2007-06-29 07:02:39 UTC (rev 42) @@ -57,7 +57,7 @@ /*** Fields ***/ /** This model's mediator. */ - private GridMediator mediator; + private IGridMediator mediator; /** The original grid. */ private boolean[][] data; @@ -87,8 +87,38 @@ * * @param mediator this model's mediator * @param data grid content + * @throws IllegalArgumentException if <code>mediator</code> + * or <code>data</code> is <code>null</code> */ - GridModel(GridMediator mediator, boolean[][] data) { + GridModel(IGridMediator mediator, boolean[][] data) + throws IllegalArgumentException { + + if (mediator == null) { + throw new IllegalArgumentException("mediator cannot be null"); + } + + if (data == null) { + throw new IllegalArgumentException("data cannot be null"); + } + + if (data.length == 0) { + throw new IllegalArgumentException("data cannot be empty"); + } + + int expectedSize = data[0].length; + + if (expectedSize == 0) { + throw new IllegalArgumentException("data cannot be empty"); + } + + for (int i = 0; i < data.length; i++) { + if (data[i].length == 0 || data[i].length != expectedSize) { + throw new IllegalArgumentException("data[i].length " + + "is supposed to be " + + expectedSize); + } + } + this.mediator = mediator; this.data = data; @@ -291,13 +321,30 @@ /*** Methods ***/ /** - * Method called during an action. - * TODO rename this method + * Method called during an action. Does the action on the specified box, + * then checks for completed hints. * * @param row row of the box * @param column column of the box + * @throws IllegalArgumentException if <code>row</code> or + * <code>column</code> is less than 0 */ - void checkBox(int row, int column, int type) { + //void checkBox(int row, int column, int type) { + void actOnBox(int row, int column, GridAction type) + throws IllegalArgumentException { + + if (row < 0) { + throw new IllegalArgumentException("row cannot be less than 0"); + } + + if (column < 0) { + throw new IllegalArgumentException("column cannot be less than 0"); + } + + if (type == GridAction.UNKNOWN) { + return; + } + //GridModel.log.debug("checkBox(" + row + ", " + column + ")"); //GridModel.log.debug("lastModified == null : " // + (lastModified == null)); @@ -326,9 +373,9 @@ if (this.boxes[column][row].isEmpty() && (this.lastModified == null || !this.lastModified.isEmpty())) { - if (type == GridController.CHECK_ACTION) { + if (type == GridAction.CHECK) { this.boxes[column][row].check(); - } else { //if (type == GridController.CROSS_ACTION) { + } else { //if (type == GridAction.CROSS) { this.boxes[column][row].cross(); } @@ -340,17 +387,17 @@ if (this.boxes[column][row].isChecked()) { //GridModel.log.debug("checked"); - if (type == GridController.CHECK_ACTION) { + if (type == GridAction.CHECK) { this.boxes[column][row].empty(); - } else { //if (type == GridController.CROSS_ACTION) { + } else { //if (type == GridAction.CROSS) { this.boxes[column][row].cross(); } } else { //if (this.boxes[column][row].isCrossed()) { //GridModel.log.debug("crossed"); - if (type == GridController.CROSS_ACTION) { + if (type == GridAction.CROSS) { this.boxes[column][row].empty(); - } else { + } else { //if (type == GridAction.CHECK) { //GridModel.log.debug("check()"); this.boxes[column][row].check(); Added: trunk/src/picross/grid/GridModelTest.java =================================================================== --- trunk/src/picross/grid/GridModelTest.java (rev 0) +++ trunk/src/picross/grid/GridModelTest.java 2007-06-29 07:02:39 UTC (rev 42) @@ -0,0 +1,110 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import picross.grid.tests.IGridMediatorStub; + +/** + * @author Y. Norsa + */ +public class GridModelTest { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + private GridModel model = null; + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + GridModelTest() { + }*/ + + /*** M\xE9thode ***/ + + @Before + public void setUp() { + this.model = new GridModel(new IGridMediatorStub(), new boolean[3][5]); + } + + @Test + public void testGridModel() { + try { + new GridModel(null, null); + Assert.fail("mediator = null"); + } catch (IllegalArgumentException argEx) { } + + IGridMediator stub = new IGridMediatorStub(); + + try { + new GridModel(stub, null); + Assert.fail("data = null"); + } catch (IllegalArgumentException argEx) { } + + try { + new GridModel(stub, new boolean[0][0]); + Assert.fail("empty data"); + } catch (IllegalArgumentException argEx) { } + + try { + new GridModel(stub, new boolean[1][0]); + Assert.fail("empty data"); + } catch (IllegalArgumentException argEx) { } + } + + @Test + public void testActOnBox() { + try { + this.model.actOnBox(-1, -1, GridAction.CHECK); + Assert.fail("row = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + this.model.actOnBox(0, -1, GridAction.CHECK); + Assert.fail("column = -1"); + } catch (IllegalArgumentException argEx) { } + + this.model.actOnBox(0, 0, GridAction.CHECK); + } +} + Property changes on: trunk/src/picross/grid/GridModelTest.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/grid/IGridMediator.java =================================================================== --- trunk/src/picross/grid/IGridMediator.java (rev 0) +++ trunk/src/picross/grid/IGridMediator.java 2007-06-29 07:02:39 UTC (rev 42) @@ -0,0 +1,57 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +/** + * @author Y. Norsa + */ +public interface IGridMediator { + /** + * Asks to repaint a box. + * + * @param row row number of the box + * @param column column number of the box + */ + void repaint(int row, int column); + + /** Asks to repaint the column hints. */ + void repaintColHints(); + + /** Asks to repaint the row hints. */ + void repaintRowHints(); + + /** Tells the application mediator the grid has been filled. */ + void congratulations(); +} + Property changes on: trunk/src/picross/grid/IGridMediator.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/grid/PaintCommand.java =================================================================== --- trunk/src/picross/grid/PaintCommand.java 2007-06-17 18:55:46 UTC (rev 41) +++ trunk/src/picross/grid/PaintCommand.java 2007-06-29 07:02:39 UTC (rev 42) @@ -56,8 +56,18 @@ * * @param row row number of the box * @param column column number of the box + * @throws IllegalArgumentException if <code>row</code> + * or <code>column</code> is less than 0 */ - PaintCommand(int row, int column) { + PaintCommand(int row, int column) throws IllegalArgumentException { + if (row < 0) { + throw new IllegalArgumentException("row can't be less than 0"); + } + + if (column < 0) { + throw new IllegalArgumentException("column can't be less than 0"); + } + this.row = row; this.column = column; } Added: trunk/src/picross/grid/PaintCommandTest.java =================================================================== --- trunk/src/picross/grid/PaintCommandTest.java (rev 0) +++ trunk/src/picross/grid/PaintCommandTest.java 2007-06-29 07:02:39 UTC (rev 42) @@ -0,0 +1,58 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Y. Norsa + */ +public class PaintCommandTest { + @Test + public void testPaintCommand() { + try { + new PaintCommand(-1, -1); + Assert.fail("row = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + new PaintCommand(0, -1); + Assert.fail("column = -1"); + } catch (IllegalArgumentException argEx) { } + + new PaintCommand(0, 0); + } +} + Property changes on: trunk/src/picross/grid/PaintCommandTest.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/grid/tests/IGridMediatorStub.java =================================================================== --- trunk/src/picross/grid/tests/IGridMediatorStub.java (rev 0) +++ trunk/src/picross/grid/tests/IGridMediatorStub.java 2007-06-29 07:02:39 UTC (rev 42) @@ -0,0 +1,68 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid.tests; + +import picross.grid.IGridMediator; + +/** + * @author Y. Norsa + */ +public class IGridMediatorStub implements IGridMediator { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + IGridMediatorStub() { + } + */ + + /*** M\xE9thode ***/ + + public void repaint(int row, int column) { } + + public void repaintColHints() { } + + public void repaintRowHints() { } + + public void congratulations() { } +} + Property changes on: trunk/src/picross/grid/tests/IGridMediatorStub.java ___________________________________________________________________ Name: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |