[Picross-commit] SF.net SVN: picross:[95] trunk
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2011-06-29 13:07:52
|
Revision: 95 http://picross.svn.sourceforge.net/picross/?rev=95&view=rev Author: yvan_norsa Date: 2011-06-29 13:07:46 +0000 (Wed, 29 Jun 2011) Log Message: ----------- big reorganisation Added Paths: ----------- trunk/src/picross/grid/Box.java trunk/test/picross/grid/AbstractPicrossGridTest.java Removed Paths: ------------- trunk/test/picross/AbstractPicrossGridTest.java Added: trunk/src/picross/grid/Box.java =================================================================== --- trunk/src/picross/grid/Box.java (rev 0) +++ trunk/src/picross/grid/Box.java 2011-06-29 13:07:46 UTC (rev 95) @@ -0,0 +1,161 @@ +/* + * $Id$ + * + * Copyright (c) 2007-2011 + * + * 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.HashMap; +import java.util.Map; +import java.util.Random; + +import picross.Picross; + +//import org.apache.log4j.Logger; + +/** + * Representation of a box in the grid. + * + * @author Y. Norsa + */ +public class Box { + /*** Enum ***/ + + /** Possibles states of a box. */ + public enum BoxState { + /** An empty box. */ + EMPTY, + + /** A checked box. */ + CHECKED, + + /** A crossed box. */ + CROSSED + } + + /*** Constants ***/ + + /** The class's logger. */ + //private static Logger log = Logger.getLogger(Box.class); + + /** Random number generator. */ + private static Random rand; + + /*** Fields ***/ + + /** State of the box. */ + protected Box.BoxState state; + + /** Pseudo random hash-code. */ + protected int hash; + + /*** Static block ***/ + static { + Box.rand = new Random(); + } + + /*** Constructor ***/ + + /** Constructor. */ + public Box() { + this.empty(); + this.hash = Box.rand.nextInt(); + } + + /*** Methods overloaded from the class Object ***/ + + /** {@inheritDoc} */ + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + + if (obj == this) { + return true; + } + + if (!(obj instanceof Box)) { + return false; + } + + return (this.state == ((Box) obj).state); + } + + /** {@inheritDoc} */ + public int hashCode() { + return this.hash; + } + + /*** Methods ***/ + + /** + * Permits to know if the box is checked. + * + * @return boolean telling if the box is checked + */ + public boolean isChecked() { + return this.state == Box.BoxState.CHECKED; + } + + /** + * Permits to know if the box is crossed. + * + * @return boolean telling if the box is crossed + */ + public boolean isCrossed() { + return this.state == Box.BoxState.CROSSED; + } + + /** + * Permits to know if the box is empty. + * + * @return boolean telling if the box is empty + */ + public boolean isEmpty() { + return this.state == Box.BoxState.EMPTY; + } + + /** Empties the box. */ + public void empty() { + this.state = Box.BoxState.EMPTY; + } + + /** Checks the box. */ + public void check() { + this.state = Box.BoxState.CHECKED; + } + + /** Crosses the box. */ + public void cross() { + this.state = Box.BoxState.CROSSED; + } +} + Property changes on: trunk/src/picross/grid/Box.java ___________________________________________________________________ Added: svn:keywords + Id Deleted: trunk/test/picross/AbstractPicrossGridTest.java =================================================================== --- trunk/test/picross/AbstractPicrossGridTest.java 2011-06-29 13:02:58 UTC (rev 94) +++ trunk/test/picross/AbstractPicrossGridTest.java 2011-06-29 13:07:46 UTC (rev 95) @@ -1,112 +0,0 @@ -/* - * $Id$ - * - * Copyright (c) 2007-2008 - * - * 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; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - * Abstract test class for the PicrossGrid interface. - * - * @author Y. Norsa - */ -public abstract class AbstractPicrossGridTest { - /*** Field ***/ - - /** The instance to test. */ - private PicrossGrid picrossGrid = null; - - /*** Abstract method ***/ - - /** - * Returns an instance. - * - * @return instance to test - */ - protected abstract PicrossGrid getPicrossGrid(); - - /*** Methods ***/ - - /** Performs the instance initialisation. */ - @Before - public void setUp() { - this.picrossGrid = this.getPicrossGrid(); - } - - /** Tests the method getWidth(). */ - @Test - public void testGetWidth() { - int width = this.picrossGrid.getWidth(); - Assert.assertTrue("width = " + width, (width > 0)); - } - - /** Tests the method getHeight(). */ - @Test - public void testGetHeight() { - int height = this.picrossGrid.getHeight(); - Assert.assertTrue("height = " + height, (height > 0)); - } - - /** Tests the method getData(). */ - @Test - public void testGetData() { - boolean[][] data = this.picrossGrid.getData(); - Assert.assertNotNull("data = null", data); - - int width = this.picrossGrid.getWidth(); - int height = this.picrossGrid.getHeight(); - - Assert.assertEquals("data.length = " + data.length, - width, data.length); - - for (int i = 0; i < width; i++) { - Assert.assertEquals("data[" + i + "].length = " + data[i].length, - height, data[i].length); - } - - boolean atLeastOneCheckedBox = false; - - for (int i = 0; i < width; i++) { - for (int j = 0; j < height; j++) { - if (data[i][j]) { - atLeastOneCheckedBox = true; - break; - } - } - } - - Assert.assertTrue("Empty grid", atLeastOneCheckedBox); - } -} Added: trunk/test/picross/grid/AbstractPicrossGridTest.java =================================================================== --- trunk/test/picross/grid/AbstractPicrossGridTest.java (rev 0) +++ trunk/test/picross/grid/AbstractPicrossGridTest.java 2011-06-29 13:07:46 UTC (rev 95) @@ -0,0 +1,112 @@ +/* + * $Id$ + * + * Copyright (c) 2007-2008 + * + * 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; + +/** + * Abstract test class for the PicrossGrid interface. + * + * @author Y. Norsa + */ +public abstract class AbstractPicrossGridTest { + /*** Field ***/ + + /** The instance to test. */ + private PicrossGrid picrossGrid = null; + + /*** Abstract method ***/ + + /** + * Returns an instance. + * + * @return instance to test + */ + protected abstract PicrossGrid getPicrossGrid(); + + /*** Methods ***/ + + /** Performs the instance initialisation. */ + @Before + public void setUp() { + this.picrossGrid = this.getPicrossGrid(); + } + + /** Tests the method getWidth(). */ + @Test + public void testGetWidth() { + int width = this.picrossGrid.getWidth(); + Assert.assertTrue("width = " + width, (width > 0)); + } + + /** Tests the method getHeight(). */ + @Test + public void testGetHeight() { + int height = this.picrossGrid.getHeight(); + Assert.assertTrue("height = " + height, (height > 0)); + } + + /** Tests the method getData(). */ + @Test + public void testGetData() { + boolean[][] data = this.picrossGrid.getData(); + Assert.assertNotNull("data = null", data); + + int width = this.picrossGrid.getWidth(); + int height = this.picrossGrid.getHeight(); + + Assert.assertEquals("data.length = " + data.length, + width, data.length); + + for (int i = 0; i < width; i++) { + Assert.assertEquals("data[" + i + "].length = " + data[i].length, + height, data[i].length); + } + + boolean atLeastOneCheckedBox = false; + + for (int i = 0; i < width; i++) { + for (int j = 0; j < height; j++) { + if (data[i][j]) { + atLeastOneCheckedBox = true; + break; + } + } + } + + Assert.assertTrue("Empty grid", atLeastOneCheckedBox); + } +} Property changes on: trunk/test/picross/grid/AbstractPicrossGridTest.java ___________________________________________________________________ Added: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |