def test_a_dead_cell_with_three_alive_neighbours_resurrects(self): board = Board([ [0, 1], [1, 1] ]) board.evolve() self.assertEqual(board.cell_at(0, 0), CellState.is_alive)
def test_create_board(self): board = Board([ [0, 0, 0], [1, 0, 1], [0, 0, 0] ]) self.assertEqual(board.cell_at(0, 1), CellState.is_alive) self.assertEqual(board.cell_at(1, 1), CellState.is_dead)
def test_number_of_alive_neighbours(self): board = Board([ [1, 0, 0], [1, 1, 1], [0, 0, 0] ]) self.assertEqual(board.num_alive_neighbours(1, 1), 3) self.assertEqual(board.num_alive_neighbours(2, 1), 1)
def test_an_alive_cell_with_more_than_four_neighbours_dies(self): board = Board([ [1, 1, 1, 0], [1, 1, 1, 0], [1, 1, 1, 0] ]) board.evolve() self.assertEqual(board.cell_at(1, 1), CellState.is_dead)
def test_an_alive_cell_without_living_neighbours_dies(self): board = Board([ [0, 0, 0], [0, 1, 0], [0, 0, 0] ]) board.evolve() self.assertEqual(board.cell_at(1, 1), CellState.is_dead)
def testSetCell(self): board = Board(3, 4) self.assertEqual(board.get_cell(1, 1), False) board.set_cell(1, 1, True) self.assertEqual(board.get_cell(1, 1), True) self.assertEqual(board.get_cell(-1, -1), False) self.assertEqual(board.get_cell(3, 4), False)
def testNextStateSquare(self): board = Board(2, 2) board.set_cell(0, 0, True) board.set_cell(1, 0, True) board.set_cell(0, 1, True) board.set_cell(1, 1, True) self.assertEqual(board.get_next_board().board, [[True, True], [True, True]])
def testLine(self): board = Board(3, 3) board.set_cell(1, 0, True) board.set_cell(1, 1, True) board.set_cell(1, 2, True) self.assertEqual( board.get_next_board().board, [[False, True, False], [False, True, False], [False, True, False]])
def testNeighbourVals(self): board = Board(4, 5) self.assertEqual(board.get_neighbour_vals( 3, 4), [False, False, False, False, False, False, False, False]) board.set_cell(2, 3, True) self.assertEqual(board.get_neighbour_vals( 3, 4), [True, False, False, False, False, False, False, False])
def testFillNum(self): board = Board(50, 50) board.set_cell(4, 5, True) self.assertEquals(board.get_number_filled(), 1)
def testNeighbours(self): board = Board(3, 4) self.assertEqual(board.get_neighbours(3, 4), [(2, 3), (2, 4), (2, 5), (3, 3), (3, 5), (4, 3), (4, 4), (4, 5)])
import time from game_of_life import Board import os board = Board([ [0, 1, 0], [0, 1, 0], [0, 1, 0], ]) for i in range(100): print(board) board.evolve() time.sleep(1) os.system('clear')
def testNextState(self): board = Board(2, 2) self.assertEqual(board.get_next_board().board, [[False, False], [False, False]])
def testRows(self): board = Board(3, 4) self.assertEqual(board.get_rows(), 3) self.assertEqual(board.get_cols(), 4)
def testAllBoardCoords(self): board = Board(2, 2) self.assertEqual(board.get_board_coords(), [(0, 0), (0, 1), (1, 0), (1, 1)])
def testNextState(self): board = Board(4, 5) self.assertEqual(board.get_next_state(3, 4), False)
def testRandom(self): board = Board(50, 50) board.fill() assert board.get_number_filled() > 0
def get_next_state(init_state): board = Board(3, 3, init_state) board.next_state() return board.board
def testNumNeigh(self): board = Board(4, 5) self.assertEqual(board.get_num_neigh(3, 4), 0) board.set_cell(2, 3, True) self.assertEqual(board.get_num_neigh(3, 4), 1)