def setUp(self): self.image_repo = ImageRepositoryStub() self.repository = GameRepository(database_connection, self.image_repo) self.repository.clear() round1 = Round([("Koira", "[koira]"), ("Kissa", "[kissa]")]) round2 = Round([("Pöytä", "[pöytä]")]) self.game = Game("Peli", [round1, round2])
def load_test_game(): """ Load a hardcoded test game Returns: A `Game`. """ koira = Image.load_from_file("data/koira.jpg") kissa = Image.load_from_file("data/kissa.jpg") aurinko = Image.load_from_file("data/aurinko.jpg") return Game("Esimerkkipeli", [ Round([("Koira", koira), ("Kissa", kissa)]), Round([("Aurinko", aurinko)]), ])
def test_if_compare_best_announcements_works_when_all_announcements_check_out(self): player1 = Player(name='Marto') player2 = Player(name='Rado') player1.set_hand(['Jh', 'Qh', 'Kh']) player2.set_hand(['10d', 'Jd', 'Qd', 'Kd']) team1 = Team(team_name='Mechetata', player1=player1, player2=player2) player3 = Player(name='Gosho') player4 = Player(name='Pesho') player3.set_hand(['Js', 'Qs', 'Ks']) player4.set_hand(['10c', 'Jc', 'Qc', 'Kc']) team2 = Team(team_name='Kotetata', player1=player3, player2=player4) r = Round(round_id=1, team1=team1, team2=team2) r.compare_best_announcements() self.assertEqual(team1.player1.get_announcements(), ['belot']) self.assertEqual(team2.player2.get_announcements(), ['belot'])
def add_round(game, pairs): """ Add a round to a game. Args: game: Game to operate on. pairs: Pairs describing the new round. """ game.rounds.append(Round(pairs))
def test_if_constructor_sets_attributes_correctly(self): player1 = Player(name='Marto') player2 = Player(name='Rado') team1 = Team(player1=player1, player2=player2) player3 = Player(name='Gosho') player4 = Player(name='Pesho') team2 = Team(player1=player1, player2=player2) r = Round(round_id=1, team1=team1, team2=team2) self.assertEqual(r.round_id, 'round 1') self.assertEqual(r.team1, team1) self.assertEqual(r.team2, team2)
def all(self): """ Get all games stored in the repository. Returns: Array of Game entities, sorted by creation time. """ games = {} cursor = self._db.cursor() cursor.execute("SELECT id, name FROM game ORDER BY id;") for row in cursor.fetchall(): game = Game(row["name"], []) game.id = row["id"] games[game.id] = game rounds = {} cursor.execute( "SELECT id, game_id FROM round ORDER BY game_id, position;") for row in cursor.fetchall(): g_round = Round([]) g_round.id = row["id"] games[row["game_id"]].rounds.append(g_round) rounds[g_round.id] = g_round images = [] cursor.execute("SELECT round_id, caption, image_id FROM image_pair;") for row in cursor.fetchall(): image = self._image_repository.get_lazy(row["image_id"]) images.append(image) pair = (row["caption"], image) rounds[row["round_id"]].pairs.append(pair) # self._image_repository.load_thumbnails(images) return list(games.values())
def play_game(self, write_to_txt, write_to_json): round_id = 1 while not is_game_won(self.team1, self.team2): contract = self.set_contract() r = Round(round_id=round_id, team1=self.team1, team2=self.team2, contract=contract) r.compare_best_announcements() write_to_txt.write_results(self.team1.team_points, self.team2.team_points, round_id) self.dicts[r.round_id] = r.to_dict() r.clear_scoring_for_round() round_id += 1 write_to_txt.write_game_end_output(self.team1, self.team2) write_to_json.add_game(self.game_id, self.to_dict()) clear_team_points(self.team1, self.team2)
def test_if_clear_announcements_for_round_works_as_expected(self): player1 = Player(name='Marto') player2 = Player(name='Rado') player1.set_hand(['Jh', 'Qh', 'Kh']) player2.set_hand(['10d', 'Jd', 'Qd', 'Kd']) team1 = Team(team_name='Mechetata', player1=player1, player2=player2) player3 = Player(name='Gosho') player4 = Player(name='Pesho') player3.set_hand(['Js', 'Qs', 'Ks']) player4.set_hand(['9c', '10c', 'Jc', 'Qc', 'Kc']) team2 = Team(team_name='Kotetata', player1=player3, player2=player4) r = Round(round_id=1, team1=team1, team2=team2) r.compare_best_announcements() r.clear_scoring_for_round() self.assertEqual(team2.player1.belots, []) self.assertEqual(team2.player1.trieces, []) self.assertEqual(team2.player2.belots, []) self.assertEqual(team2.player2.quintes, [])
def test_game_factory(): return Game("Testipeli", [ Round([("Koira", "[Koira]"), ("Kissa", "[Kissa]")]), Round([("Aurinko", "[Aurinko]")]), ])
def setUp(self): seeded_random = random.Random(12) self.service = PlayService(shuffle=seeded_random.shuffle) round1 = Round([("Koira", "[koira]"), ("Kissa", "[kissa]")]) round2 = Round([("Pöytä", "[pöytä]")]) self.game = Game("Peli", [round1, round2])