// setup fixture @Before public void setUp() { log = new Log(); status = new Success(); mock_simulator = new Mocks.MockSimulation(); Simulation.setInstance(mock_simulator); }
private void runTest(int width, int height, int[] startingCells, int[] expectedCells, int steps) { // Create the game board and simulation Board board = new Board(width, height, startingCells); Simulation sim = new Simulation(board, ConwaysOriginalRules); // Run the simulation for the given number of steps sim.step(steps); // Check the final board state is as expected for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { int actual = board.getCellState(x, y); int expected = expectedCells[(y * width) + x]; if (actual != expected) { System.err.println("ACTUAL BOARD:"); System.err.println(board); System.err.println("EXPECTED BOARD:"); System.err.println(new Board(width, height, expectedCells)); fail("Cell (" + x + "," + y + ") has state " + actual + ", expected " + expected); } assertTrue(board.getCellState(x, y) == expected); } } }