def test_can_not_mark_dot_in_already_marked_cell(self): field = Field.Field(5, 5) player = Player(1, field) another = Player(2, field) field.mark_dot(0, 0, player) field.mark_dot(0, 0, another) self.assertEqual(field.field_array[0][0].owner, player)
def test_can_not_mark_dot_inside_others_occupied_area(self): field = Field.Field(5, 5) player = Player(1, field) field.mark_dot(0, 1, player) # _x field.mark_dot(1, 0, player) # xzx field.mark_dot(2, 1, player) # _x field.mark_dot(1, 2, player) # Cycles.find_occupied_dots(field) success = field.mark_dot(1, 1, Player(2, field)) self.assertFalse(success)
def test_can_not_mark_at_the_edge(self): field = Field.Field(5, 5) player = Player(1, field) field.mark_dot(-1, -1, player) field.mark_dot(5, 5, player) field.mark_dot(-1, 5, player) field.mark_dot(5, -1, player) self.assertTrue(is_empty(field))
def test_group_by_x_3_dots_in_line_vertically(self): player = occupier = Player(-1) c1 = Cell.Cell(0, 0, player, occupier) c2 = Cell.Cell(0, 1, player, occupier) c3 = Cell.Cell(0, 2, player, occupier) cells = {c1, c2, c3} expected = {} self.assertEqual(expected, Cell.group_by_x(cells))
def test_group_by_x_3_dots_in_line_horizontally(self): player = occupier = Player(-1) c1 = Cell.Cell(0, 0, player, occupier) c2 = Cell.Cell(1, 0, player, occupier) c3 = Cell.Cell(2, 0, player, occupier) cells = {c1, c2, c3} expected = {1: {c2}} self.assertEqual(expected, Cell.group_by_x(cells))
def test_cell_marked_as_occupied_staggered_layout_with_enemy(self): field = Field.Field(3, 3) player_x = Player(1, field) player_z = Player(2, field) field.mark_dot(0, 1, player_z) # xzx field.mark_dot(1, 0, player_z) # zxz field.mark_dot(2, 1, player_z) # xzx field.mark_dot(1, 2, player_z) # field.mark_dot(0, 0, player_x) field.mark_dot(0, 2, player_x) field.mark_dot(2, 2, player_x) field.mark_dot(2, 0, player_x) field.mark_dot(1, 1, player_x) Cycles.find_occupied_dots(field) self.assertEqual(field.field_array[1][1].occupier, player_z)
def test_occupied_cell_marked_as_occupied(self): field = Field.Field(5, 5) occupier = Player(1, field) field.mark_dot(0, 1, occupier) # _x field.mark_dot(1, 0, occupier) # xzx field.mark_dot(2, 1, occupier) # _x field.mark_dot(1, 2, occupier) # Cycles.find_occupied_dots(field) self.assertEqual(field.field_array[1][1].occupier, occupier)
def test_cell_marked_as_occupied_staggered_layout_with_empty(self): field = Field.Field(3, 3) occupier = Player(1, field) field.mark_dot(0, 1, occupier) # _x field.mark_dot(1, 0, occupier) # xzx field.mark_dot(2, 1, occupier) # _x field.mark_dot(1, 2, occupier) # Cycles.find_occupied_dots(field) self.assertEqual(field.field_array[1][1].occupier, occupier)
def test_belongs(self): field = Field.Field(5, 5) player = Player(1, field) field.mark_dot(0, 1, player) # _x field.mark_dot(1, 0, player) # xzx field.mark_dot(2, 1, player) # _x field.mark_dot(1, 2, player) # actually = field.field_array[1][1].belongs_smb() self.assertFalse(actually)
def test_can_mark_dot_inside_its_own_occupied_area(self): field = Field.Field(5, 5) player = Player(1, field) field.mark_dot(0, 1, player) # _x field.mark_dot(1, 0, player) # xzx field.mark_dot(2, 1, player) # _x field.mark_dot(1, 2, player) # Cycles.find_occupied_dots(field) success = field.mark_dot(1, 1, player) self.assertTrue(success)
def test_dot_inside_occupied_area(self): field = Field.Field(5, 5) player = Player(1, field) field.mark_dot(0, 1, player) # _x field.mark_dot(1, 0, player) # xzx field.mark_dot(2, 1, player) # _x field.mark_dot(1, 2, player) # Cycles.find_occupied_dots(field) occ_b_enm = field.field_array[1][1].occupied_by_enemy() self.assertTrue(occ_b_enm)
def test_dot_outside_occupied_area_do_not_contact_with_area(self): field = Field.Field(6, 6) player = Player(1, field) field.mark_dot(0, 1, player) # _x___z field.mark_dot(1, 0, player) # x_x field.mark_dot(2, 1, player) # _x field.mark_dot(1, 2, player) # _ = Cycles.find_occupied_dots(field) not_occ = field.field_array[5][0].occupied_by_enemy() self.assertFalse(not_occ)
def test_hard_occupy_single_enemy_dot(self): field = Field(3, 3) enemy = Player(0) field.field_array[1][1] = Cell(1, 1, enemy) hard_bot = HardBot(1) for i in range(4): hard_bot.act(field) Cycles.find_occupied_dots(field) self.assertEqual(field.field_array[1][0].owner, hard_bot) self.assertEqual(field.field_array[0][1].owner, hard_bot) self.assertEqual(field.field_array[2][1].owner, hard_bot) self.assertEqual(field.field_array[1][2].owner, hard_bot)
def test_raises_exception_if_owner_is_int_but_not_player_obj(self): player = Player(1) cell = Cell.Cell(0, 0, player) self.assertRaises(TypeError, cell.belongs, player=1)
def test_nobodys_cell_is_not_enemys_cell(self): player = Player(1) cells = {Cell.Cell(0, 0, owner=None)} self.assertFalse(Cell.contains_enemy(cells, player))
def test_others_cell_is_enemy_cell(self): player = Player(1) other = Player(2) cells = {Cell.Cell(0, 0, player)} self.assertTrue(Cell.contains_enemy(cells, other))
def test_players_cell_is_not_enemy_cell(self): player = Player(1) cells = {Cell.Cell(0, 0, player)} self.assertFalse(Cell.contains_enemy(cells, player))
def test_doesnt_belongs_to_others_owner(self): player = Player(1) other = Player(2) cell = Cell.Cell(0, 0, player) self.assertFalse(cell.belongs(other))
def test_belongs_to_its_owner(self): player = Player(-1) cell = Cell.Cell(0, 0, player) self.assertTrue(cell.belongs(player))
def test_3_cells_with_gap_vertically_middle(self): player = occupier = Player(-1) cell = Cell.Cell(0, 1, player, occupier) cells = {Cell.Cell(0, 0, player, occupier), cell, Cell.Cell(0, 2, player, occupier)} self.assertFalse(Cell.is_between_cells(cell, cells))
def test_3_cells_in_line_horizontally_right(self): player = occupier = Player(-1) cell = Cell.Cell(2, 0, player, occupier) cells = {Cell.Cell(1, 0, player, occupier), cell, Cell.Cell(0, 0, player, occupier)} self.assertFalse(Cell.is_between_cells(cell, cells))
def add_human(self): self.players.append(Player(self.next_number, None, self.ui))
def test_occupied_cell_without_owner(self): player = Player(_id=0) cell = Cell(0, 0, owner=None, occupier=player) cell.drenched = True color = UI.get_color_pair(cell) self.assertEqual(1, color)
def test_can_mark_dot(self): field = Field.Field(5, 5) player = Player(1, field) field.mark_dot(2, 3, player) self.assertEqual(field.field_array[2][3].owner, player)