Exemplo n.º 1
0
    def test_new_cell(self):
        cell = Cell(x=10, y=20)
        self.assertEqual(cell.x, 10)
        self.assertEqual(cell.y, 20)
        self.assertEqual(cell.value, -1)

        cell.value = 1
        self.assertEqual(cell.value, 1)
        self.assertEqual(cell.coords(), (10, 20))
Exemplo n.º 2
0
 def initialize_grid(self):
     array_grid = []
     for i in range(self.height):
         array_grid.append([])
         for j in range(self.width):
             array_grid[i].append(Cell(0, (i, j), self))
     return array_grid
Exemplo n.º 3
0
 def import_level(level):
     level_imported = level
     size = len(level_imported[0]), len(level_imported)
     grid = Grid(*size)
     array_grid = []
     for i in range(size[1]):
         array_grid.append([])
         for j in range(size[0]):
             ijstate = level_imported[i][j]['state']
             array_grid[i].append(Cell(ijstate, (i, j), grid))
     return array_grid
Exemplo n.º 4
0
class TestCell(unittest.TestCase):
    def setUp(self):
        self.cell = Cell(1, 1)

    def test_cell_to_string(self):
        self.assertEqual(str(self.cell), "{'neighbors': '[]'}")

    def test_cell_to_json(self):
        self.assertEqual(self.cell._json_repr(), {
            "neighbors": [],
            "filled": False
        })
Exemplo n.º 5
0
class TestCell(unittest.TestCase):
    def setUp(self):
        self.cell = Cell(1, 1)

    def test_cell_to_string(self):
        self.assertEqual(str(self.cell), "{'neighbors': '[]'}")

    def test_cell_to_json(self):
        self.assertEqual(self.cell._json_repr(), {
            "neighbors": [],
            "filled": False
        })
Exemplo n.º 6
0
Arquivo: grid.py Projeto: 0b11stan/lab
 def __init__(self):
     self.cells = [[Cell(), Cell(), Cell()], [Cell(),
                                              Cell(),
                                              Cell()],
                   [Cell(), Cell(), Cell()]]
Exemplo n.º 7
0
 def setUp(self):
     self.cell = Cell(1, 1)
Exemplo n.º 8
0
 def test_init_cell(self):
     cell = Cell()
     self.assertIsNotNone(cell)
Exemplo n.º 9
0
 def test_that_an_filled_cell_know_its_fullness(self):
     player = PlayerX('test')
     cell = Cell()
     cell.fill(player)
     self.assertFalse(cell.is_empty())
Exemplo n.º 10
0
 def test_that_an_empty_cell_know_its_emptiness(self):
     cell = Cell()
     self.assertTrue(cell.is_empty())
Exemplo n.º 11
0
 def test_filled_cell_can_not_be_overriden(self):
     cell = Cell()
     px = PlayerX('romain')
     cell.fill(px)
     with self.assertRaises(AlreadyFilledCellException):
         cell.fill(px)
Exemplo n.º 12
0
 def test_empty_cell_can_be_filled_by_a_user(self):
     cell = Cell()
     player = PlayerX('romain')
     cell.fill(player)
     self.assertEqual(player, cell.player)
Exemplo n.º 13
0
 def test_empty_cell_have_no_user(self):
     cell = Cell()
     self.assertIsNotNone(cell)
     self.assertIsNone(cell.player)
Exemplo n.º 14
0
 def setUp(self):
     self.cell = Cell(1, 1)
Exemplo n.º 15
0
 def test_init(self):
     c = Cell(0, (1, 1), Grid(4, 3))
     self.assertEqual(c.pos, (1, 1))