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))
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
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
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 })
def __init__(self): self.cells = [[Cell(), Cell(), Cell()], [Cell(), Cell(), Cell()], [Cell(), Cell(), Cell()]]
def setUp(self): self.cell = Cell(1, 1)
def test_init_cell(self): cell = Cell() self.assertIsNotNone(cell)
def test_that_an_filled_cell_know_its_fullness(self): player = PlayerX('test') cell = Cell() cell.fill(player) self.assertFalse(cell.is_empty())
def test_that_an_empty_cell_know_its_emptiness(self): cell = Cell() self.assertTrue(cell.is_empty())
def test_filled_cell_can_not_be_overriden(self): cell = Cell() px = PlayerX('romain') cell.fill(px) with self.assertRaises(AlreadyFilledCellException): cell.fill(px)
def test_empty_cell_can_be_filled_by_a_user(self): cell = Cell() player = PlayerX('romain') cell.fill(player) self.assertEqual(player, cell.player)
def test_empty_cell_have_no_user(self): cell = Cell() self.assertIsNotNone(cell) self.assertIsNone(cell.player)
def test_init(self): c = Cell(0, (1, 1), Grid(4, 3)) self.assertEqual(c.pos, (1, 1))