def test_rook(): piece = Rook(Color.BLACK, Position(x=3, y=3)) assert piece.can_move_to(Position(x=7, y=3)) assert piece.can_move_to(Position(x=3, y=7)) # Bishop assert not piece.can_move_to(Position(x=1, y=1)) # Knight assert not piece.can_move_to(Position(x=4, y=5)) assert not piece.can_move_to(Position(x=2, y=5)) assert not piece.can_move_to(Position(x=4, y=1)) assert not piece.can_move_to(Position(x=2, y=1)) assert not piece.can_move_to(Position(x=1, y=2)) assert not piece.can_move_to(Position(x=1, y=4)) assert not piece.can_move_to(Position(x=5, y=2)) assert not piece.can_move_to(Position(x=5, y=4)) assert not piece.was_move piece.move_to(Position(x=5, y=3)) assert piece.was_move
class TestPawn(unittest.TestCase): def setUp(self): self.coords = Coordinates('d', 4) self.rook = Rook(self.coords, 'white') def test_rook_initialization(self): self.assertEqual(self.rook.coordinates, self.coords) def test_rook_position(self): self.assertTupleEqual((3, 3), self.rook.position) def test_rook_resource_name(self): self.assertEqual('white_rook.png', self.rook.resource_name) def test_rook_can_move_ahead(self): new_coord = Coordinates('d', 5) self.assertTrue(self.rook.can_move_to(new_coord)) def test_rook_can_move_behind(self): new_coord = Coordinates('d', 3) self.assertTrue(self.rook.can_move_to(new_coord)) def test_rook_can_move_to_left(self): new_coord = Coordinates('c', 4) self.assertTrue(self.rook.can_move_to(new_coord)) def test_rook_can_move_to_right(self): new_coord = Coordinates('e', 4) self.assertTrue(self.rook.can_move_to(new_coord)) def test_rook_can_move_more_than_one_tile(self): new_coord = Coordinates('d', 8) self.assertTrue(self.rook.can_move_to(new_coord)) def test_rook_cant_move_diagonally(self): new_coord = Coordinates('e', 5) self.assertFalse(self.rook.can_move_to(new_coord))