Ejemplo n.º 1
0
 public function testCirconscriptionEuropeenne()
 {
     $pays = new Pays('France');
     $region = new Region($pays, 11, 'Île-de-France');
     $circo = new CirconscriptionEuropeenne($pays, 1, 'Île-de-France');
     $region->setCirconscriptionEuropeenne($circo);
     $this->assertEquals($circo, $region->getCirconscriptionEuropeenne());
     $this->assertContains($region, $circo->getRegions());
 }
 public function testSetSurCircoAndGetHigherScore()
 {
     $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');
     $region->setCirconscriptionEuropeenne($circoEuro);
     $circoEuro->addRegion($region);
     $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);
     $this->territoireRepository->add($circoEuro);
     $election = new ElectionUninominale($echeance, $departement);
     $election2 = new ElectionUninominale($echeance, $commune2);
     $candidat = new PersonneCandidate($election, 'FG', 'Naël', 'Ferret');
     $election->addCandidat($candidat);
     $candidat2 = new PersonneCandidate($election2, 'PG', 'Lea', 'Ferret');
     $election2->addCandidat($candidat2);
     $candidat3 = new PersonneCandidate($election2, 'FG', 'Leo', 'Ferret');
     $election2->addCandidat($candidat3);
     $voteInfo1 = new VoteInfo(1000, 900, 800);
     $election->setVoteInfo($voteInfo1);
     $voteInfo2 = new VoteInfo(100, 90, 80);
     $election2->setVoteInfo($voteInfo2);
     $election->setVoixCandidat(400, $candidat);
     $election2->setVoixCandidat(50, $candidat2);
     $election2->setVoixCandidat(10, $candidat3);
     $this->electionRepository->add($election);
     $this->electionRepository->add($election2);
     $this->electionRepository->save();
     $score = $this->electionRepository->getScore($echeance, $region, array($candidat, $candidat2, $candidat3));
     $scoreEuro = $this->electionRepository->getScore($echeance, $circoEuro, array($candidat, $candidat2, $candidat3));
     $this->assertEquals($score, $scoreEuro);
     $this->assertEquals(460, $score->toVoix());
     $this->assertTrue(abs(52.27 - $score->toPourcentage()) < 0.01);
     $score = $this->electionRepository->getScore($echeance, $region, new CandidatNuanceSpecification(array('FG', 'PG')));
     $scoreEuro = $this->electionRepository->getScore($echeance, $circoEuro, new CandidatNuanceSpecification(array('FG', 'PG')));
     $pays = $this->territoireRepository->getPays();
     $scorePays = $this->electionRepository->getScore($echeance, $pays, new CandidatNuanceSpecification(array('FG', 'PG')));
     $this->assertEquals($score, $scoreEuro);
     $this->assertEquals($score, $scorePays);
     $this->assertEquals(460, $score->toVoix());
     $this->assertTrue(abs(52.27 - $score->toPourcentage()) < 0.01);
 }