1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Michaelc\Voting; |
4
|
|
|
|
5
|
|
|
use Michaelc\Voting\STV\Candidate; |
6
|
|
|
|
7
|
|
|
class StvCandidateTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
public function testNewCandidateValues() |
10
|
|
|
{ |
11
|
|
|
$id = 12; |
12
|
|
|
$candidate = new Candidate($id); |
13
|
|
|
$this->assertEquals($candidate->getId(), 12); |
14
|
|
|
$this->assertEquals($candidate->getVotes(), 0.0); |
15
|
|
|
$this->assertEquals($candidate->getState(), Candidate::RUNNING); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testCandidateStates() |
19
|
|
|
{ |
20
|
|
|
$candidate = new Candidate(random_int(0,10)); |
21
|
|
|
|
22
|
|
|
$candidate->setState(Candidate::ELECTED); |
23
|
|
|
$this->assertEquals($candidate->getState(), Candidate::ELECTED); |
24
|
|
|
|
25
|
|
|
$candidate->setState(Candidate::RUNNING); |
26
|
|
|
$this->assertEquals($candidate->getState(), Candidate::RUNNING); |
27
|
|
|
|
28
|
|
|
$candidate->setState(Candidate::DEFEATED); |
29
|
|
|
$this->assertEquals($candidate->getState(), Candidate::DEFEATED); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testCandidateVotes() |
33
|
|
|
{ |
34
|
|
|
$candidate = new Candidate(random_int(0,10)); |
35
|
|
|
|
36
|
|
|
$this->assertEquals($candidate->getVotes(), 0.0); |
37
|
|
|
|
38
|
|
|
$candidate->addVotes(4); |
39
|
|
|
$this->assertEquals($candidate->getVotes(), 4.0); |
40
|
|
|
|
41
|
|
|
$candidate->addVotes(0.11112); |
42
|
|
|
$this->assertEquals($candidate->getVotes(), 4.11112); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|