GameOfLife { protected byte[][] getMatrix() { return matrix; } GameOfLife(int width, byte[] initialStateInBytes, int maxX, int maxY, int maxIterations); static void emptyMatrix(byte[][] matrix, int maxX, int maxY); static void printMatrix(byte[][] matrix, int maxX, int maxY, PrintStream stream); void nextCycle(); static void main(String[] args);  }
@Test public void testSetBigInitialState() throws GameOfLifeException { byte[] bigState = new byte[] { 1, 0, 20, 20 }; GameOfLife gameOfLife = new GameOfLife(5, bigState, 8, 8, 10); assertEquals(0, gameOfLife.getMatrix()[0][0]); assertEquals(0, gameOfLife.getMatrix()[0][1]); assertEquals(1, gameOfLife.getMatrix()[0][2]); assertEquals(0, gameOfLife.getMatrix()[0][3]); assertEquals(1, gameOfLife.getMatrix()[0][4]); assertEquals(0, gameOfLife.getMatrix()[1][0]); assertEquals(0, gameOfLife.getMatrix()[1][1]); assertEquals(0, gameOfLife.getMatrix()[1][2]); assertEquals(0, gameOfLife.getMatrix()[1][3]); assertEquals(0, gameOfLife.getMatrix()[1][4]); assertEquals(1, gameOfLife.getMatrix()[2][0]); assertEquals(0, gameOfLife.getMatrix()[2][1]); assertEquals(1, gameOfLife.getMatrix()[2][2]); assertEquals(0, gameOfLife.getMatrix()[2][3]); assertEquals(0, gameOfLife.getMatrix()[2][4]); assertEquals(0, gameOfLife.getMatrix()[3][0]); assertEquals(0, gameOfLife.getMatrix()[3][1]); assertEquals(0, gameOfLife.getMatrix()[3][2]); assertEquals(0, gameOfLife.getMatrix()[3][3]); assertEquals(0, gameOfLife.getMatrix()[3][4]); assertEquals(0, gameOfLife.getMatrix()[4][0]); assertEquals(0, gameOfLife.getMatrix()[4][1]); assertEquals(0, gameOfLife.getMatrix()[4][2]); assertEquals(0, gameOfLife.getMatrix()[4][3]); assertEquals(1, gameOfLife.getMatrix()[4][4]); }
@Test public void testSetInitialState() throws GameOfLifeException { byte[] smallState = new byte[] { 11 }; GameOfLife gameOfLife = new GameOfLife(2, smallState, 8, 8, 10); assertEquals(1, gameOfLife.getMatrix()[0][0]); assertEquals(1, gameOfLife.getMatrix()[0][1]); assertEquals(0, gameOfLife.getMatrix()[1][0]); assertEquals(1, gameOfLife.getMatrix()[1][1]); smallState = new byte[] { 0, 11 }; gameOfLife = new GameOfLife(4, smallState, 8, 8, 10); assertEquals(1, gameOfLife.getMatrix()[0][0]); assertEquals(1, gameOfLife.getMatrix()[0][1]); assertEquals(0, gameOfLife.getMatrix()[0][2]); assertEquals(1, gameOfLife.getMatrix()[0][3]); for(int i = 1; i < 4; i++) { for(int j = 0; j < 4; j++) { assertEquals(0, gameOfLife.getMatrix()[i][j]); } } }