public function testHasDateAndTypeAndTour()
 {
     $date = new \DateTime();
     $echeance = new Echeance($date, Echeance::CANTONALES, true);
     $this->assertEquals($date, $echeance->getDate());
     $this->assertEquals('Cantonales ' . $date->format('Y') . ' (second tour)', $echeance->getNom());
     $this->assertEquals('Cantonales ' . $date->format('Y') . ' (second tour)', $echeance->__toString());
     $this->assertTrue($echeance->isSecondTour());
 }
Пример #2
0
 /**
  * Récupérer le nombre de sièges d'un candidat à l'élection. Retourne
  * null si le calcul est impossible ou le nombre total de sièges est
  * inconnu.
  *
  * @param CandidatInterface $candidat Le candidat.
  *
  * @return int Le nombre de sièges.
  */
 public function getSiegesCandidat(CandidatInterface $candidat)
 {
     if (!$this->sieges) {
         return;
     }
     if (Echeance::EUROPEENNES === $this->echeance->getType()) {
         $scores = array();
         $candidats = array();
         foreach ($this->getCandidats() as $c) {
             $score = $this->getScoreCandidat($c);
             for ($i = 1; $i <= $this->sieges; $i++) {
                 if ($score instanceof Score && (null === $score->toPourcentage() || 5 < $score->toPourcentage())) {
                     $scores[] = $score->toVoix() / $i;
                     $candidats[] = $c;
                 }
             }
         }
         arsort($scores);
         $listeSieges = array_slice($scores, 0, $this->sieges, true);
         $sieges = 0;
         foreach ($listeSieges as $key => $score) {
             if ($candidats[$key] === $candidat) {
                 $sieges++;
             }
         }
         return $sieges;
     }
 }