Ejemplo n.º 1
0
class TestFigures:
    def setup_class(self):
        self.r = Rook(4, 4)
        self.kn = Knight(4, 4)
        self.b = Bishop(4, 4)
        self.q = Queen(4, 4)
        self.k = King(4, 4)

    def test_Rook_is_attack_true_horiz(self):
        assert self.r.is_attack(4, 8)

    def test_Rook_is_attack_true_vert(self):
        assert self.r.is_attack(8, 4)

    def test_Rook_is_attack_false(self):
        assert self.r.is_attack(1, 2) is False

    def test_Knight_is_attack_true(self):
        fields = [(3, 2), (5, 2), (2, 3), (6, 3), (2, 5), (6, 5), (3, 6),
                  (5, 6)]
        res_table = [self.kn.is_attack(*field) for field in fields]
        assert all(res_table)

    def test_Knight_is_attack_false(self):
        fields = [(2, 2), (4, 3), (6, 2), (2, 4), (3, 4), (5, 4), (2, 6),
                  (4, 7)]
        res_table = [not self.kn.is_attack(*field) for field in fields]
        assert all(res_table)

    def test_bishop_is_attack_true(self):
        fields = [(3, 3), (5, 5), (5, 3), (3, 5), (2, 2), (6, 2)]
        res_table = [self.b.is_attack(*field) for field in fields]
        assert all(res_table)

    def test_bishop_is_attack_false(self):
        fields = [(4, 3), (5, 4), (4, 5), (3, 4), (4, 2), (3, 6)]
        res_table = [not self.b.is_attack(*field) for field in fields]
        assert all(res_table)

    def test_queen_is_attack_true(self):
        fields = [(3, 3), (5, 5), (5, 3), (3, 5), (2, 2), (6, 2), (8, 4),
                  (4, 8)]
        res_table = [self.q.is_attack(*field) for field in fields]
        assert all(res_table)

    def test_queen_is_attack_false(self):
        fields = [(1, 2), (2, 3), (3, 2), (5, 2), (6, 5), (5, 7), (2, 7)]
        res_table = [not self.q.is_attack(*field) for field in fields]
        assert all(res_table)

    def test_king_is_attack_true(self):
        fields = [(x, y) for x in range(3, 6) for y in range(3, 6)]
        res_table = [self.k.is_attack(*field) for field in fields]
        assert all(res_table)

    def test_king_is_attack_false(self):
        fields = [(2, 2), (5, 2), (4, 2), (4, 6), (6, 6)]
        res_table = [not self.k.is_attack(*field) for field in fields]
        assert all(res_table)
Ejemplo n.º 2
0
    def test_solution_for_board_3_and_2_kings_1_rook_fig(self):
        boards = solution(3, [King, King, Rook])
        b1 = Board(3)
        b1.figures = {King(1, 1), King(3, 1), Rook(2, 3)}

        b2 = Board(3)
        b2.figures = {King(1, 1), King(1, 3), Rook(3, 2)}

        b3 = Board(3)
        b3.figures = {King(3, 1), King(3, 3), Rook(1, 2)}

        b4 = Board(3)
        b4.figures = {King(1, 3), King(3, 3), Rook(2, 1)}

        assert boards == {b1, b2, b3, b4}
Ejemplo n.º 3
0
 def test_board_with_more_figures_then_fields_is_valid(self):
     board = Board(1)
     board.figures = [Rook(1, 1), King(1, 1)]
     assert board.is_valid() is False
Ejemplo n.º 4
0
 def test_loop_for_new_boards_over_board_with_two_rooks(self):
     board = Board(5)
     board.figures = [Rook(1, 1), Rook(5, 5)]
     rook = Rook
     boards = board.loop_for_new_boards(rook)
     assert len(boards) is 9
Ejemplo n.º 5
0
 def test_board_when_adding_rook_is_not_safe_on_board(self):
     board = Board(5)
     board.figures = [Knight(1, 1), Bishop(1, 5), King(5, 5)]
     rook = Rook(5, 4)
     assert board.is_safe_for(rook) is False
Ejemplo n.º 6
0
 def test_board_when_adding_rook_break_figure_on_board(self):
     board = Board(4)
     board.figures = [Knight(1, 1)]
     rook = Rook(1, 4)
     assert board.is_safe_for(rook) is False
Ejemplo n.º 7
0
 def test_board_with_queen_is_not_safe_for_rook(self):
     board = Board(4)
     board.figures = [Queen(1, 1)]
     rook = Rook(2, 2)
     assert board.is_safe_for(rook) is False
Ejemplo n.º 8
0
 def test_board_with_some_figures_is_safe_for_Rook(self):
     board = Board(5)
     board.figures = [Knight(1, 1), Bishop(1, 5), King(5, 5)]
     rook = Rook(4, 3)
     assert board.is_safe_for(rook)
Ejemplo n.º 9
0
 def test_board_with_no_figures_is_safe_for_Rook(self):
     board = Board(3)
     rook = Rook(1, 1)
     assert board.is_safe_for(rook)
Ejemplo n.º 10
0
 def setup_class(self):
     self.r = Rook(4, 4)
     self.kn = Knight(4, 4)
     self.b = Bishop(4, 4)
     self.q = Queen(4, 4)
     self.k = King(4, 4)