コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
    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)
コード例 #5
0
    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)
コード例 #6
0
 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)
コード例 #7
0
 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]])
コード例 #8
0
 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]])
コード例 #9
0
 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])
コード例 #10
0
 def testFillNum(self):
     board = Board(50, 50)
     board.set_cell(4, 5, True)
     self.assertEquals(board.get_number_filled(), 1)
コード例 #11
0
 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)])
コード例 #12
0
ファイル: main.py プロジェクト: vanessagl2/game_of_life
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')
コード例 #13
0
 def testNextState(self):
     board = Board(2, 2)
     self.assertEqual(board.get_next_board().board,
                      [[False, False], [False, False]])
コード例 #14
0
 def testRows(self):
     board = Board(3, 4)
     self.assertEqual(board.get_rows(), 3)
     self.assertEqual(board.get_cols(), 4)
コード例 #15
0
 def testAllBoardCoords(self):
     board = Board(2, 2)
     self.assertEqual(board.get_board_coords(), [(0, 0), (0, 1), (1, 0),
                                                 (1, 1)])
コード例 #16
0
 def testNextState(self):
     board = Board(4, 5)
     self.assertEqual(board.get_next_state(3, 4), False)
コード例 #17
0
 def testRandom(self):
     board = Board(50, 50)
     board.fill()
     assert board.get_number_filled() > 0
コード例 #18
0
ファイル: tests.py プロジェクト: akashsara/game-of-life
def get_next_state(init_state):
    board = Board(3, 3, init_state)
    board.next_state()
    return board.board
コード例 #19
0
 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)