public function testHasNom()
 {
     $pays = new Pays('France');
     $circo = new CirconscriptionEuropeenne($pays, 1, 'Nom');
     $this->assertEquals('Nom', $circo->getNom());
     $this->assertEquals(1, $circo->getCode());
     $this->assertEquals($pays, $circo->getPays());
 }
Пример #2
0
 /**
  * Régler la circonscription européenne.
  *
  * @param CirconscriptionEuropeenne $circonscription La circonscription
  */
 public function setCirconscriptionEuropeenne(CirconscriptionEuropeenne $circonscription)
 {
     if (!$this->circonscriptionEuropeenne) {
         $this->circonscriptionEuropeenne = $circonscription;
         $circonscription->addRegion($this);
         return $this;
     }
     throw new Exception('On ne peut pas changer la circonscription européenne d\'une région');
 }
 public function testSetSurSmallerAndGetCircoScore()
 {
     $date = new \DateTime();
     $echeance = new Echeance($date, Echeance::CANTONALES);
     $pays = new Pays();
     $region = new Region($pays, 11, 'Île-de-France');
     $circoEuro = new CirconscriptionEuropeenne($pays, 1, 'Test');
     $circoEuro->addRegion($region);
     $region->setCirconscriptionEuropeenne($circoEuro);
     $departement = new Departement($region, 93, 'Seine-Saint-Denis');
     $departement2 = new Departement($region, 92, 'Hauts-de-Seine');
     $commune2 = new Commune($departement2, 20, 'Jesaispas');
     $this->territoireRepository->add($departement);
     $this->territoireRepository->add($commune2);
     $this->territoireRepository->add($region);
     $election = new ElectionUninominale($echeance, $region);
     $candidat = new PersonneCandidate($election, 'FG', 'Naël', 'Ferret');
     $election->addCandidat($candidat);
     $voteInfo1 = new VoteInfo(1000, 900, 800);
     $election->setVoteInfo($voteInfo1, $departement);
     $voteInfo2 = new VoteInfo(100, 90, 80);
     $election->setVoteInfo($voteInfo2, $commune2);
     $election->setVoixCandidat(400, $candidat, $departement);
     $election->setVoixCandidat(50, $candidat, $commune2);
     $this->electionRepository->add($election);
     $this->electionRepository->save();
     $this->assertContains($departement, $region->getDepartements());
     $this->assertContains($departement2, $region->getDepartements());
     $score = $this->electionRepository->getScore($echeance, $region, $candidat);
     $this->assertEquals(450, $score->toVoix());
     $this->assertTrue(abs(51.13 - $score->toPourcentage()) < 0.01);
     $score = $this->electionRepository->getScore($echeance, $departement2, $candidat);
     $this->assertEquals(50, $score->toVoix());
     $this->assertTrue(abs(62.5 - $score->toPourcentage()) < 0.01);
     // prendre directement les résultats du département s'ils sont dispo
     // et ne pas tenir compte de ceux de la commune
     $voteInfo3 = new VoteInfo(110, 100, 90);
     $election->setVoteInfo($voteInfo3, $departement2);
     $election->setVoixCandidat(60, $candidat, $departement2);
     $this->electionRepository->save();
     $score = $this->electionRepository->getScore($echeance, $region, $candidat);
     $score2 = $this->electionRepository->getScore($echeance, $circoEuro, $candidat);
     $voteInfo = $this->electionRepository->getVoteInfo($echeance, $region);
     $this->assertEquals(890, $voteInfo->getExprimes());
     $this->assertEquals($score, $score2);
     $this->assertEquals(460, $score->toVoix());
     $this->assertTrue(abs(51.68 - $score->toPourcentage()) < 0.01);
 }