Example #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)
Example #2
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)
Example #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)
Example #4
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)
Example #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
Example #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
Example #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
Example #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
Example #9
0
def live_cell():
    """returns a live cell with no neighbours"""
    return Cell(alive=True)
Example #10
0
 def setUp(self):
     self.cell = Cell("dead")
Example #11
0
 def setUp(self):
     self.cell = Cell("alive")
Example #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
Example #13
0
def test_a_cell_can_be_placed_anywhere(x, y):
    c = Cell(x, y)
    neighbours = set(c.neighbours())

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