Exemple #1
0
    def test_multiple_games(self):
        """Teste que gagner en étant équipe 1 ou 2 n'a pas d'importance"""
        elos = [1900, 2100]
        persons = [factories.PersonFactory(init_elo=elo) for elo in elos]
        identities = [factories.IdentityFactory(person=p) for p in persons]
        players = [
            factories.PlayerFactory(identity=identity)
            for identity in identities
        ]

        # p1 gagne en équipe 1
        factories.GameFactory.create(team1=[players[0]],
                                     team2=[players[1]],
                                     winner="team1")

        # p2 gagne en équipe 2
        factories.GameFactory.create(team1=[players[0]],
                                     team2=[players[1]],
                                     winner="team2")

        update_elo()
        persons[0].refresh_from_db()
        persons[1].refresh_from_db()

        elo_p1_1 = players[0].get_elo()
        elo_p2_1 = players[1].get_elo()

        # Reset
        persons = [factories.PersonFactory(init_elo=elo) for elo in elos]
        identities = [factories.IdentityFactory(person=p) for p in persons]
        players = [
            factories.PlayerFactory(identity=identity)
            for identity in identities
        ]

        # p1 gagne en équipe 2
        factories.GameFactory.create(team1=[players[1]],
                                     team2=[players[0]],
                                     winner="team2")

        # p2 gagne en équipe 1
        factories.GameFactory.create(team1=[players[1]],
                                     team2=[players[0]],
                                     winner="team1")

        update_elo()
        persons[0].refresh_from_db()
        persons[1].refresh_from_db()

        elo_p1_2 = players[0].get_elo()
        elo_p2_2 = players[1].get_elo()

        self.assertNotEqual(elo_p1_1, elos[0])
        self.assertNotEqual(elo_p2_1, elos[1])
        self.assertEqual(elo_p1_1, elo_p1_2)
        self.assertEqual(elo_p2_1, elo_p2_2)
Exemple #2
0
    def test_balancing_teams_alt(self):
        elos = [2300, 1503, 1502, 1501, 1400]
        players = [factories.PersonFactory(init_elo=elo) for elo in elos]

        team_balancer = TeamBalancer(players)
        bteams = team_balancer.get_balanced_teams()

        self.assertEqual(set(bteams[0]), set([players[0], players[-1]]))
Exemple #3
0
    def test_balancing_teams(self):
        elos = [2001, 1500, 2000, 1499]
        players = [factories.PersonFactory(init_elo=elo) for elo in elos]

        team_balancer = TeamBalancer(players)
        teams = team_balancer.get_teams()

        self.assertEqual(set([players[0], players[3]]), set(teams[0]))
        self.assertEqual(set([players[1], players[2]]), set(teams[1]))
Exemple #4
0
 def setUp(self):
     elos = [2000, 1500, 2100, 1900, 2500, 1500, 1400, 1200]
     self.persons = [factories.PersonFactory(init_elo=elo) for elo in elos]
     self.identities = [
         factories.IdentityFactory(person=p) for p in self.persons
     ]
     self.players = [
         factories.PlayerFactory(identity=identity)
         for identity in self.identities
     ]
Exemple #5
0
 def test_elo(self):
     person = factories.PersonFactory(name="Toto", init_elo=2000)
     self.assertEqual(person.get_elo(), 2000)
Exemple #6
0
 def test_str_person(self):
     person = factories.PersonFactory(name="Foo")
     self.assertEqual(str(person), "Foo")