コード例 #1
0
class LiveCellBehaviour(CommonCellBehaviour):
    def __init__(self, methodName='runTest'):
        CommonCellBehaviour.__init__(self, methodName=methodName)

    def setUp(self):
        self.cell = Cell("alive")

    def test_LiveCellWithFewerThanTwoLiveNeighbours_DiesOfLoneliness(self):
        '''Dies of Loneliness'''
        for liveNeighbours in (0, 1):
            nextGenCell = self.cell.regenerate(liveNeighbours)
            self.assertDead(nextGenCell)

    def test_LiveCellWithMoreThanThreeLiveNeighboursDiesOfOvercrowding(self):
        '''Dies of Overcrowding'''
        for liveNeighbours in (4, 5, 6, 7, 8):
            nextGenCell = self.cell.regenerate(liveNeighbours)
            self.assertDead(nextGenCell)

    def test_LiveCellWithTwoLiveNeighbours_LivesOn(self):
        '''Survival'''
        nextGenCell = self.cell.regenerate(liveNeighbours=2)
        self.assertAlive(nextGenCell)

    def test_LiveCellWithThreeLiveNeighbours_LivesOn(self):
        '''Survival'''
        nextGenCell = self.cell.regenerate(liveNeighbours=3)
        self.assertAlive(nextGenCell)
コード例 #2
0
ファイル: test_gol.py プロジェクト: doughgle/game_of_life
class LiveCellBehaviour(CommonCellBehaviour):

    def __init__(self, methodName='runTest'):
        CommonCellBehaviour.__init__(self, methodName=methodName)
        
    def setUp(self):
        self.cell = Cell("alive")
     
    def test_LiveCellWithFewerThanTwoLiveNeighbours_DiesOfLoneliness(self):
        '''Dies of Loneliness'''
        for liveNeighbours in (0, 1):
            nextGenCell = self.cell.regenerate(liveNeighbours)
            self.assertDead(nextGenCell)
        
    def test_LiveCellWithMoreThanThreeLiveNeighboursDiesOfOvercrowding(self):
        '''Dies of Overcrowding'''
        for liveNeighbours in (4, 5, 6, 7, 8):
            nextGenCell = self.cell.regenerate(liveNeighbours)
            self.assertDead(nextGenCell)
        
    def test_LiveCellWithTwoLiveNeighbours_LivesOn(self):
        '''Survival'''
        nextGenCell = self.cell.regenerate(liveNeighbours=2)
        self.assertAlive(nextGenCell)
        
    def test_LiveCellWithThreeLiveNeighbours_LivesOn(self):
        '''Survival'''
        nextGenCell = self.cell.regenerate(liveNeighbours=3)
        self.assertAlive(nextGenCell)
コード例 #3
0
class DeadCellBehaviour(CommonCellBehaviour):
    def __init__(self, methodName='runTest'):
        CommonCellBehaviour.__init__(self, methodName=methodName)

    def setUp(self):
        self.cell = Cell("dead")

    def test_DeadCellWithoutTheMagicNumberOfNeighbours_remainsDead(self):
        for liveNeighbours in (0, 1, 2, 4, 5, 6, 7, 8):
            nextGenCell = self.cell.regenerate(liveNeighbours)
            self.assertDead(nextGenCell)

    def test_DeadCellWithExactlyThreeLiveNeighboursBecomesALiveCell(self):
        '''Reproduction'''
        nextGenCell = self.cell.regenerate(liveNeighbours=3)
        self.assertAlive(nextGenCell)
コード例 #4
0
ファイル: test_gol.py プロジェクト: doughgle/game_of_life
class DeadCellBehaviour(CommonCellBehaviour):

    def __init__(self, methodName='runTest'):
        CommonCellBehaviour.__init__(self, methodName=methodName)
        
    def setUp(self):
        self.cell = Cell("dead")
    
    def test_DeadCellWithoutTheMagicNumberOfNeighbours_remainsDead(self):
        for liveNeighbours in (0, 1, 2, 4, 5, 6, 7, 8):
            nextGenCell = self.cell.regenerate(liveNeighbours)
            self.assertDead(nextGenCell)
               
    def test_DeadCellWithExactlyThreeLiveNeighboursBecomesALiveCell(self):
        '''Reproduction'''
        nextGenCell = self.cell.regenerate(liveNeighbours=3)
        self.assertAlive(nextGenCell)
コード例 #5
0
def test_an_overcrowded_cell_dies(x, y, count):
    cell = Cell(x, y)
    board = setup_board_with_cell(cell, count)
    assert not cell in board.cells
コード例 #6
0
def test_a_happy_cell_survives(x, y, count):
    cell = Cell(x, y)
    board = setup_board_with_cell(cell, count)
    assert cell in board.cells
コード例 #7
0
def test_a_lonely_cell_dies(x, y, count):
    cell = Cell(x, y)
    board = setup_board_with_cell(cell, count)
    assert not cell in board.cells
コード例 #8
0
def test_a_cell_with_three_neighbours_spawns(x, y):
    cell = Cell(x, y)
    neighbours = list(cell.neighbours())
    board = Board(neighbours[:3])
    board = board.next_generation()
    assert cell in board.cells
コード例 #9
0
ファイル: test_gol.py プロジェクト: jonodrew/gol
def live_cell():
    """returns a live cell with no neighbours"""
    return Cell(alive=True)
コード例 #10
0
ファイル: test_gol.py プロジェクト: doughgle/game_of_life
 def setUp(self):
     self.cell = Cell("dead")
コード例 #11
0
ファイル: test_gol.py プロジェクト: doughgle/game_of_life
 def setUp(self):
     self.cell = Cell("alive")
コード例 #12
0
def test_a_cell_neighbours():
    "Testing that a cell has eight neighbours"
    c = Cell(1, 1)
    neighbours = set(c.neighbours())

    assert Cell(0, 0) in neighbours
    assert Cell(0, 1) in neighbours
    assert Cell(0, 2) in neighbours
    assert Cell(1, 0) in neighbours
    assert not Cell(1, 1) in neighbours
    assert Cell(1, 2) in neighbours
    assert Cell(2, 0) in neighbours
    assert Cell(2, 1) in neighbours
    assert Cell(2, 2) in neighbours
コード例 #13
0
def test_a_cell_can_be_placed_anywhere(x, y):
    c = Cell(x, y)
    neighbours = set(c.neighbours())

    assert 8 == len(neighbours)
コード例 #14
0
 def setUp(self):
     self.cell = Cell("dead")
コード例 #15
0
 def setUp(self):
     self.cell = Cell("alive")