Package org.drools.examples.conway

Examples of org.drools.examples.conway.Cell


        grid = null;
    }

    public void testGetCellAt() {

        Cell cell = grid.getCellAt(ROWS - 1, COLUMNS - 1);

        assertNotNull("getCellAt returned null", cell);

        assertEquals("cell had wrong initial state", CellState.DEAD, cell.getCellState());
    }
View Full Code Here


        assertEquals("cell had wrong initial state", CellState.DEAD, cell.getCellState());
    }

    public void testInitialStateOfCell() {
        Cell cell = grid.getCellAt(ROWS - 1, COLUMNS - 1);

        assertNotNull("getCellAt returned null", cell);

        assertEquals("cell had wrong initial state", CellState.DEAD, cell.getCellState());
    }
View Full Code Here

        assertEquals("cell had wrong initial state", CellState.DEAD, cell.getCellState());
    }

    public void testNumberOfNeighbors() {
        Cell cell = grid.getCellAt(0, 0);

        // corner cells should all have 3 neighbors
        assertEquals("cell(0,0) had wrong number of neighbors", 3, cell.getNumberOfNeighboringCells());
        cell = grid.getCellAt(0, COLUMNS - 1);
        assertEquals("cell(0, COLUMNS-1) had wrong number of neighbors", 3, cell.getNumberOfNeighboringCells());
        cell = grid.getCellAt(ROWS - 1, COLUMNS - 1);
        assertEquals("cell(ROWS-1, COLUMNS-1) had wrong number of neighbors", 3, cell.getNumberOfNeighboringCells());
        cell = grid.getCellAt(ROWS - 1, 0);
        assertEquals("cell(ROWS - 1, 0) had wrong number of neighbors", 3, cell.getNumberOfNeighboringCells());

        // cells in the first and last row (except corners) should all have 5 neighbors
        for(int column = 1; column < COLUMNS -1; column++) {
            cell = grid.getCellAt(0, column);
            assertEquals("cell had wrong number of neighbors", 5, cell.getNumberOfNeighboringCells());
            cell = grid.getCellAt(ROWS-1, column);
            assertEquals("cell had wrong number of neighbors", 5, cell.getNumberOfNeighboringCells());
        }

        // cells in the first and last column (except corners) should all ahve 5 neighbors
        for(int row = 1; row < ROWS -1; row++) {
            cell = grid.getCellAt(row, 0);
            assertEquals("cell had wrong number of neighbors", 5, cell.getNumberOfNeighboringCells());
            cell = grid.getCellAt(row, COLUMNS-1);
            assertEquals("cell had wrong number of neighbors", 5, cell.getNumberOfNeighboringCells());
        }

        // cells not in the first row and first column should all have 8 neighbors
        for(int row= 1; row < ROWS-1; row++) {
            for(int column= 1; column < COLUMNS-1; column++) {
                cell = grid.getCellAt(row, column);
                assertEquals("cell had wrong number of neighbors", 8, cell.getNumberOfNeighboringCells());
            }
        }

    }
View Full Code Here

    public void testGettingAllCells() {
        int numberOfRows = grid.getNumberOfRows();
        int numberOfColumns = grid.getNumberOfColumns();
        for (int row = 0; row < numberOfRows; row++) {
            for (int column = 0; column < numberOfColumns; column++) {
                Cell cell = grid.getCellAt(row, column);
                assertNotNull("getCellAt returned null", cell);

                assertEquals("cell had wrong initial state", CellState.DEAD, cell.getCellState());
            }
        }
    }
View Full Code Here

*
*/
public class CellTest extends TestCase {

    public void testDefaultStateIsDead() {
        Cell c1 = new Cell();

        assertEquals("c1 had wrong inital state", CellState.DEAD, c1.getCellState());
    }
View Full Code Here

        assertEquals("c1 had wrong inital state", CellState.DEAD, c1.getCellState());
    }

    public void testAddNeighbor() {
        Cell c1 = new Cell();
        Cell c2 = new Cell();
        assertEquals("c1 had wrong number of neighbors before adding neighbor", 0, c1.getNumberOfNeighboringCells());
        assertEquals("c2 had wrong number of neighbors before adding neighbor", 0, c2.getNumberOfNeighboringCells());


        c1.addNeighbor(c2);

        assertEquals("c1 had wrong number of neighbors after adding neighbor", 1, c1.getNumberOfNeighboringCells());
        assertEquals("c2 had wrong number of neighbors after adding neighbor", 1, c2.getNumberOfNeighboringCells());
    }
View Full Code Here

        assertEquals("c1 had wrong number of neighbors after adding neighbor", 1, c1.getNumberOfNeighboringCells());
        assertEquals("c2 had wrong number of neighbors after adding neighbor", 1, c2.getNumberOfNeighboringCells());
    }

    public void testAddingNeighborMultipleTimes() {
        Cell c1 = new Cell();
        Cell c2 = new Cell();
        assertEquals("c1 had wrong number of neighbors before adding neighbor", 0, c1.getNumberOfNeighboringCells());
        assertEquals("c2 had wrong number of neighbors before adding neighbor", 0, c2.getNumberOfNeighboringCells());


        c1.addNeighbor(c2);

        assertEquals("c1 had wrong number of neighbors after adding neighbor", 1, c1.getNumberOfNeighboringCells());
        assertEquals("c2 had wrong number of neighbors after adding neighbor", 1, c2.getNumberOfNeighboringCells());

        c1.addNeighbor(c2);
        c1.addNeighbor(c2);
        c2.addNeighbor(c1);

        assertEquals("c1 had wrong number of neighbors after adding neighbor again", 1, c1.getNumberOfNeighboringCells());
        assertEquals("c2 had wrong number of neighbors after adding neighbor again", 1, c2.getNumberOfNeighboringCells());
    }
View Full Code Here

        assertEquals("c1 had wrong number of neighbors after adding neighbor again", 1, c1.getNumberOfNeighboringCells());
        assertEquals("c2 had wrong number of neighbors after adding neighbor again", 1, c2.getNumberOfNeighboringCells());
    }

    public void testNumberOfLiveNeighbors() {
        Cell c1 = new Cell();
        Cell c2 = new Cell();
        Cell c3 = new Cell();

        c1.addNeighbor(c2);

        assertEquals("c1 had wrong number of live neighbors initally", 0, c1.getNumberOfLiveNeighbors());

        c2.setCellState(CellState.LIVE);

        assertEquals("c1 had wrong number of live neighbors", 1, c1.getNumberOfLiveNeighbors());
        c3.setCellState(CellState.LIVE);
        c1.addNeighbor(c3);
        assertEquals("c1 had wrong number of live neighbors", 2, c1.getNumberOfLiveNeighbors());

    }
View Full Code Here

        assertEquals("c1 had wrong number of live neighbors", 2, c1.getNumberOfLiveNeighbors());

    }

    public void testStateQueuing() {
        Cell c1 = new Cell();
        assertEquals("c1 had wrong inital state", CellState.DEAD, c1.getCellState());

        c1.setCellState(CellState.LIVE);
        assertEquals("c1 had wrong state", CellState.LIVE, c1.getCellState());

        c1.queueNextCellState(CellState.DEAD);
        assertEquals("c1 had wrong state", CellState.LIVE, c1.getCellState());

        c1.transitionState();
        assertEquals("c1 had wrong state", CellState.DEAD, c1.getCellState());

        c1.queueNextCellState(CellState.LIVE);
        assertEquals("c1 had wrong state", CellState.DEAD, c1.getCellState());

        c1.transitionState();
        assertEquals("c1 had wrong state", CellState.LIVE, c1.getCellState());

    }
View Full Code Here

        addMouseMotionListener( new MouseMotionAdapter( ) {

            public void mouseDragged(MouseEvent e)
            {
                Cell cell = getCellAtPoint( e.getX( ),
                                            e.getY( ) );
                if ( cell != null )
                {
                    cell.setCellState( CellState.LIVE );
                    repaint( );
                }
            }
        } );
    }
View Full Code Here

TOP

Related Classes of org.drools.examples.conway.Cell

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.