|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Michaelc\Voting; |
|
4
|
|
|
|
|
5
|
|
|
use Michaelc\Voting\STV\{Election, Candidate, Ballot}; |
|
6
|
|
|
|
|
7
|
|
|
class StvElectionTest extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
public function testNewElection() |
|
10
|
|
|
{ |
|
11
|
|
|
$winners = 2; |
|
12
|
|
|
$candidateCount = 6; |
|
13
|
|
|
|
|
14
|
|
|
$candidates = $ballots = []; |
|
15
|
|
|
|
|
16
|
|
|
for ($i=1; $i <= $candidateCount; $i++) { |
|
17
|
|
|
$candidates[$i] = new Candidate($i); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
$ballots[] = new Ballot([4, 5, 6]); |
|
21
|
|
|
$ballots[] = new Ballot([1, 2, 3]); |
|
22
|
|
|
|
|
23
|
|
|
$election = new Election($winners, $candidates, $ballots); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertEquals($candidates[3], $election->getCandidate(3)); |
|
26
|
|
|
$this->assertEquals($candidateCount, $election->getCandidateCount()); |
|
27
|
|
|
$this->assertEquals($candidateCount, $election->getActiveCandidateCount()); |
|
28
|
|
|
$this->assertEquals($winners, $election->getWinnersCount()); |
|
29
|
|
|
$this->assertEquals(2, $election->getNumBallots()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testElectionRunner() |
|
33
|
|
|
{ |
|
34
|
|
|
$election = $this->getSampleElection(); |
|
35
|
|
|
$runner = new \MichaelC\Voting\STV\VoteHandler($election); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function getSampleElection() |
|
39
|
|
|
{ |
|
40
|
|
|
$candidates = $ballots = []; |
|
41
|
|
|
|
|
42
|
|
|
for ($i=1; $i <= 20; $i++) { |
|
43
|
|
|
$candidates[$i] = new Candidate($i); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
for ($i=0; $i <= 40; $i++) { |
|
47
|
|
|
$ballots[] = new Ballot([random_int(1,20), random_int(1,20), random_int(1,20)]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$election = new Election(12, $candidates, $ballots); |
|
51
|
|
|
|
|
52
|
|
|
return $election; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.