tests: added test case

This commit is contained in:
korzepadawid 2022-04-04 21:23:32 +02:00
parent bef17bccd1
commit f06ea9e5b0
3 changed files with 18 additions and 3 deletions

View File

@ -5,6 +5,19 @@ from models.knight import Knight
class KnightsQueueTest(unittest.TestCase): class KnightsQueueTest(unittest.TestCase):
def test_should_make_valid_next_turn(self):
knight1 = Knight(None)
knight1.health = 222
knight2 = Knight(None)
knight2.health = 1
knights_queue = KnightsQueue([knight1], [knight2])
previous_turn = knights_queue.team_idx_turn
knights_queue.dequeue_knight()
current_turn = knights_queue.team_idx_turn
self.assertNotEqual(previous_turn, current_turn)
def test_should_raise_when_team_has_dead_knights(self): def test_should_raise_when_team_has_dead_knights(self):
with self.assertRaises(Exception): with self.assertRaises(Exception):
knight1 = Knight(None) knight1 = Knight(None)

View File

@ -5,6 +5,7 @@ import pygame
from common.colors import FONT_DARK, WHITE from common.colors import FONT_DARK, WHITE
from common.constants import * from common.constants import *
from common.helpers import draw_text from common.helpers import draw_text
from logic.knights_queue import KnightsQueue
from models.castle import Castle from models.castle import Castle
from models.knight import Knight from models.knight import Knight
from models.monster import Monster from models.monster import Monster
@ -87,7 +88,6 @@ class Game:
stats = Stats() stats = Stats()
logs = Logs() logs = Logs()
knights_sprite_group = pygame.sprite.Group() knights_sprite_group = pygame.sprite.Group()
monsters_sprite_group = pygame.sprite.Group() monsters_sprite_group = pygame.sprite.Group()
castle_sprite_group = pygame.sprite.Group() castle_sprite_group = pygame.sprite.Group()
@ -95,6 +95,8 @@ class Game:
knights_left = self.generate_knights_team(knights_sprite_group) knights_left = self.generate_knights_team(knights_sprite_group)
knights_right = self.generate_knights_team(knights_sprite_group) knights_right = self.generate_knights_team(knights_sprite_group)
knights_queue = KnightsQueue(knights_left, knights_right)
spawn_left_team = Spawner(grid, knights_left, width=KNIGHTS_SPAWN_WIDTH, height=KNIGHTS_SPAWN_HEIGHT, spawn_left_team = Spawner(grid, knights_left, width=KNIGHTS_SPAWN_WIDTH, height=KNIGHTS_SPAWN_HEIGHT,
pos_row=KNIGHTS_SPAWN_FIRST_ROW, pos_column=KNIGHTS_SPAWN_FIRST_COL) pos_row=KNIGHTS_SPAWN_FIRST_ROW, pos_column=KNIGHTS_SPAWN_FIRST_COL)
spawn_right_team = Spawner(grid, knights_right, width=KNIGHTS_SPAWN_WIDTH, height=KNIGHTS_SPAWN_HEIGHT, spawn_right_team = Spawner(grid, knights_right, width=KNIGHTS_SPAWN_WIDTH, height=KNIGHTS_SPAWN_HEIGHT,

View File

@ -14,12 +14,12 @@ class KnightsQueue:
self.dequeue_knight() self.dequeue_knight()
else: else:
self.queues[self.team_idx_turn].append(knight) self.queues[self.team_idx_turn].append(knight)
self.next_round() self.next_turn()
return knight return knight
raise Exception('Game has just ended') raise Exception('Game has just ended')
def both_teams_alive(self): def both_teams_alive(self):
return len(self.queues[0]) > 0 and len(self.queues[1]) > 0 return len(self.queues[0]) > 0 and len(self.queues[1]) > 0
def next_round(self): def next_turn(self):
self.team_idx_turn = (self.team_idx_turn + 1) % 2 self.team_idx_turn = (self.team_idx_turn + 1) % 2