Ejemplo n.º 1
0
 def rellena_partidos():
     if Jornadas.objects.all().exists():
         Jornadas.objects.all().delete()
     equipos = Equipos.objects.all().order_by('id_equipo')
     lista_equipos = equipos.values_list('nombre')
     lista_equipos = [lista_equipos[i][0] for i,v in enumerate(lista_equipos)]
     scheduler = DoubleRoundRobinScheduler(lista_equipos)
     lista_partidos = scheduler.generate_schedule()
     for indice,partidos_jornada in enumerate(lista_partidos):
         jornada = Jornadas.objects.create(num_jornada=indice+1)
         for partido in partidos_jornada:
             if None not in partido:
                 Partidos.objects.create(equipo_local=Equipos.objects.get(nombre=partido[0]),
                                         equipo_visitante=Equipos.objects.get(nombre=partido[1]), jornada=jornada)
 def test_schedule_generation(self):
     """Test double round-robin schedule generation."""
     scheduler = DoubleRoundRobinScheduler(8)
     # Failed attempt
     random.seed(5)
     self.assertRaises(ScheduleGenerationFailed,
                       scheduler.generate_schedule, try_once=True)
     # Successful attempt
     random.seed(2)
     if PY2:
         expected_schedule = [
             [(5, 6), (7, 4), (3, 8), (1, 2)],
             [(5, 1), (8, 4), (3, 6), (2, 7)],
             [(3, 1), (6, 5), (4, 8), (7, 2)],
             [(8, 5), (3, 2), (1, 4), (7, 6)],
             [(1, 8), (7, 3), (2, 6), (4, 5)],
             [(8, 1), (6, 3), (5, 7), (4, 2)],
             [(6, 1), (2, 5), (4, 3), (8, 7)],
             [(2, 4), (6, 8), (7, 5), (1, 3)],
             [(5, 4), (2, 1), (8, 6), (3, 7)],
             [(4, 7), (2, 8), (3, 5), (1, 6)],
             [(4, 6), (1, 7), (2, 3), (5, 8)],
             [(5, 3), (7, 8), (6, 2), (4, 1)],
             [(7, 1), (5, 2), (6, 4), (8, 3)],
             [(1, 5), (3, 4), (8, 2), (6, 7)]
         ]
     elif PY3:
         expected_schedule = [
             [(3, 2), (4, 1), (8, 5), (6, 7)],
             [(3, 8), (1, 6), (7, 5), (2, 4)],
             [(6, 8), (4, 7), (2, 3), (5, 1)],
             [(2, 1), (5, 7), (3, 6), (8, 4)],
             [(5, 4), (6, 2), (3, 7), (1, 8)],
             [(4, 3), (7, 2), (5, 6), (8, 1)],
             [(3, 1), (5, 2), (8, 6), (7, 4)],
             [(7, 1), (6, 4), (5, 3), (2, 8)],
             [(8, 7), (4, 6), (3, 5), (1, 2)],
             [(3, 4), (7, 8), (6, 1), (2, 5)],
             [(1, 4), (7, 3), (5, 8), (2, 6)],
             [(1, 3), (2, 7), (4, 8), (6, 5)],
             [(4, 5), (8, 2), (6, 3), (1, 7)],
             [(1, 5), (4, 2), (7, 6), (8, 3)]
         ]
     schedule = scheduler.generate_schedule(try_once=True)
     self.assertListEqual(expected_schedule, schedule,
                          ('Wrong schedule created for '
                           'double round-robin competition'))
 def test_schedule_generation(self):
     """Test double round-robin schedule generation."""
     scheduler = DoubleRoundRobinScheduler(8)
     # Failed attempt
     random.seed(5)
     self.assertRaises(ScheduleGenerationFailed,
                       scheduler.generate_schedule,
                       try_once=True)
     # Successful attempt
     random.seed(2)
     if PY2:
         expected_schedule = [[(5, 6), (7, 4), (3, 8), (1, 2)],
                              [(5, 1), (8, 4), (3, 6), (2, 7)],
                              [(3, 1), (6, 5), (4, 8), (7, 2)],
                              [(8, 5), (3, 2), (1, 4), (7, 6)],
                              [(1, 8), (7, 3), (2, 6), (4, 5)],
                              [(8, 1), (6, 3), (5, 7), (4, 2)],
                              [(6, 1), (2, 5), (4, 3), (8, 7)],
                              [(2, 4), (6, 8), (7, 5), (1, 3)],
                              [(5, 4), (2, 1), (8, 6), (3, 7)],
                              [(4, 7), (2, 8), (3, 5), (1, 6)],
                              [(4, 6), (1, 7), (2, 3), (5, 8)],
                              [(5, 3), (7, 8), (6, 2), (4, 1)],
                              [(7, 1), (5, 2), (6, 4), (8, 3)],
                              [(1, 5), (3, 4), (8, 2), (6, 7)]]
     elif PY3:
         expected_schedule = [[(3, 2), (4, 1), (8, 5), (6, 7)],
                              [(3, 8), (1, 6), (7, 5), (2, 4)],
                              [(6, 8), (4, 7), (2, 3), (5, 1)],
                              [(2, 1), (5, 7), (3, 6), (8, 4)],
                              [(5, 4), (6, 2), (3, 7), (1, 8)],
                              [(4, 3), (7, 2), (5, 6), (8, 1)],
                              [(3, 1), (5, 2), (8, 6), (7, 4)],
                              [(7, 1), (6, 4), (5, 3), (2, 8)],
                              [(8, 7), (4, 6), (3, 5), (1, 2)],
                              [(3, 4), (7, 8), (6, 1), (2, 5)],
                              [(1, 4), (7, 3), (5, 8), (2, 6)],
                              [(1, 3), (2, 7), (4, 8), (6, 5)],
                              [(4, 5), (8, 2), (6, 3), (1, 7)],
                              [(1, 5), (4, 2), (7, 6), (8, 3)]]
     schedule = scheduler.generate_schedule(try_once=True)
     self.assertListEqual(expected_schedule, schedule,
                          ('Wrong schedule created for '
                           'double round-robin competition'))
 def test_repeated_schedule_generation(self):
     """Test repeated double round-robin schedule generation."""
     scheduler = DoubleRoundRobinScheduler(8)
     random.seed(5)
     if PY2:
         expected_schedule = [
             [(8, 4), (3, 7), (1, 6), (2, 5)],
             [(7, 1), (6, 4), (8, 2), (5, 3)],
             [(1, 8), (2, 4), (7, 6), (3, 5)],
             [(2, 6), (5, 7), (4, 3), (8, 1)],
             [(8, 5), (1, 3), (7, 4), (6, 2)],
             [(2, 7), (4, 8), (5, 1), (3, 6)],
             [(1, 7), (6, 5), (2, 8), (3, 4)],
             [(1, 4), (8, 3), (5, 2), (6, 7)],
             [(2, 3), (4, 1), (6, 8), (7, 5)],
             [(1, 2), (5, 8), (7, 3), (4, 6)],
             [(4, 2), (6, 3), (1, 5), (7, 8)],
             [(4, 5), (8, 7), (3, 2), (6, 1)],
             [(2, 1), (4, 7), (3, 8), (5, 6)],
             [(7, 2), (8, 6), (5, 4), (3, 1)]
         ]
     elif PY3:
         expected_schedule = [
             [(4, 3), (8, 2), (6, 7), (5, 1)],
             [(5, 6), (2, 4), (3, 8), (1, 7)],
             [(6, 5), (4, 8), (1, 3), (7, 2)],
             [(8, 4), (1, 2), (5, 3), (7, 6)],
             [(8, 5), (2, 3), (7, 1), (4, 6)],
             [(4, 5), (8, 6), (2, 7), (3, 1)],
             [(2, 8), (3, 5), (1, 6), (7, 4)],
             [(6, 2), (1, 8), (3, 4), (7, 5)],
             [(5, 4), (8, 7), (2, 1), (6, 3)],
             [(8, 1), (3, 6), (4, 7), (2, 5)],
             [(4, 1), (5, 2), (7, 3), (6, 8)],
             [(6, 4), (7, 8), (1, 5), (3, 2)],
             [(8, 3), (5, 7), (2, 6), (1, 4)],
             [(5, 8), (3, 7), (6, 1), (4, 2)]
         ]
     schedule = scheduler.generate_schedule()
     self.assertListEqual(expected_schedule, schedule,
                          ('Wrong schedule created for repeated '
                           'double round-robin competition'))
Ejemplo n.º 5
0
    def __init__(self, match_class, teams):
        """Constructor.

        @param match_class: The class of the match simulator.
        @type match_class: A Match-like object.
        @param teams: The teams competing in this league.
        @type teams: list of Team-like objects.
        """
        super(DoubleRoundRobinLeague, self).__init__(match_class=match_class,
                                                     teams=teams)
        self._schedule = DoubleRoundRobinScheduler(
            self._teams).generate_schedule()
 def test_repeated_schedule_generation(self):
     """Test repeated double round-robin schedule generation."""
     scheduler = DoubleRoundRobinScheduler(8)
     random.seed(5)
     if PY2:
         expected_schedule = [[(8, 4), (3, 7), (1, 6), (2, 5)],
                              [(7, 1), (6, 4), (8, 2), (5, 3)],
                              [(1, 8), (2, 4), (7, 6), (3, 5)],
                              [(2, 6), (5, 7), (4, 3), (8, 1)],
                              [(8, 5), (1, 3), (7, 4), (6, 2)],
                              [(2, 7), (4, 8), (5, 1), (3, 6)],
                              [(1, 7), (6, 5), (2, 8), (3, 4)],
                              [(1, 4), (8, 3), (5, 2), (6, 7)],
                              [(2, 3), (4, 1), (6, 8), (7, 5)],
                              [(1, 2), (5, 8), (7, 3), (4, 6)],
                              [(4, 2), (6, 3), (1, 5), (7, 8)],
                              [(4, 5), (8, 7), (3, 2), (6, 1)],
                              [(2, 1), (4, 7), (3, 8), (5, 6)],
                              [(7, 2), (8, 6), (5, 4), (3, 1)]]
     elif PY3:
         expected_schedule = [[(4, 3), (8, 2), (6, 7), (5, 1)],
                              [(5, 6), (2, 4), (3, 8), (1, 7)],
                              [(6, 5), (4, 8), (1, 3), (7, 2)],
                              [(8, 4), (1, 2), (5, 3), (7, 6)],
                              [(8, 5), (2, 3), (7, 1), (4, 6)],
                              [(4, 5), (8, 6), (2, 7), (3, 1)],
                              [(2, 8), (3, 5), (1, 6), (7, 4)],
                              [(6, 2), (1, 8), (3, 4), (7, 5)],
                              [(5, 4), (8, 7), (2, 1), (6, 3)],
                              [(8, 1), (3, 6), (4, 7), (2, 5)],
                              [(4, 1), (5, 2), (7, 3), (6, 8)],
                              [(6, 4), (7, 8), (1, 5), (3, 2)],
                              [(8, 3), (5, 7), (2, 6), (1, 4)],
                              [(5, 8), (3, 7), (6, 1), (4, 2)]]
     schedule = scheduler.generate_schedule()
     self.assertListEqual(expected_schedule, schedule,
                          ('Wrong schedule created for repeated '
                           'double round-robin competition'))