我正在用python创建一个Connect 4的简单游戏,并将pygame用于GUI,但是我似乎找不到一种为同一单元编写单元测试的方法
这是我的python脚本script
的链接链接到我的project
对于类似方法,
def play(self, board, players, is_valid_move, make_move, is_winning_move):
"""Method to play the game in GUI using pygame
Note:
When playing with AI a mouse click is required to trigger AI move
Args:
board (numpy.ndarray): Game board
players (list): List of players
is_valid_move (function): Move validator
make_move (function): Makes move
is_winning_move (function): Ckeck for winning move"""
turn = random.randint(0, len(players) - 1)
while True:
self.draw(board)
for event in pygame.event.get():
if event.type == pygame.QUIT:
return None
if event.type == pygame.MOUSEMOTION:
self.draw_black_rec()
self.draw_player_coin(players[turn].p_id, event)
pygame.display.update()
if event.type == pygame.MOUSEBUTTONDOWN:
self.draw_black_rec()
if players[turn].name == "AI":
col = players[turn].get_move()
if is_valid_move(col):
row = make_move(col, players[turn].p_id)
turn = (turn + 1) % len(players)
我希望编写一个测试上述功能的单元测试,如果我不能仅对一部分方法进行整个方法的测试,它也将起作用。