Completed
Push — master ( c698df...2bf777 )
by Michael
03:54
created

StvElectionTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 5
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testNewElection() 0 22 2
A testElectionRunner() 0 5 1
A getSampleElection() 0 16 3
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);
0 ignored issues
show
Unused Code introduced by
$runner is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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