1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace OSS\CoreBundle\Tests\Entity;
|
4
|
|
|
|
5
|
|
|
use OSS\CoreBundle\Entity\Manager;
|
6
|
|
|
use OSS\CoreBundle\Entity\Player;
|
7
|
|
|
use OSS\CoreBundle\Entity\PlayerSkills;
|
8
|
|
|
use OSS\CoreBundle\Entity\Team;
|
9
|
|
|
use OSS\CoreBundle\Transfer\ScoreCalculator;
|
10
|
|
|
|
11
|
|
|
class ScoreCalculatorTest extends \PHPUnit_Framework_TestCase
|
12
|
|
|
{
|
13
|
|
|
/**
|
14
|
|
|
* @var ScoreCalculator
|
15
|
|
|
*/
|
16
|
|
|
private $scoreCalculator;
|
17
|
|
|
|
18
|
|
|
/**
|
19
|
|
|
* @var Player
|
20
|
|
|
*/
|
21
|
|
|
private $player;
|
22
|
|
|
|
23
|
|
|
public function setUp()
|
24
|
|
|
{
|
25
|
|
|
$manager = new Manager();
|
26
|
|
|
$manager->setTeam(new Team());
|
27
|
|
|
for ($i = 1; $i <= 20; $i++) {
|
28
|
|
|
$manager->getTeam()->addPlayer(new Player());
|
29
|
|
|
}
|
30
|
|
|
$this->scoreCalculator = new ScoreCalculator($manager);
|
31
|
|
|
$this->player = new Player();
|
32
|
|
|
$this->player->setSkills(new PlayerSkills());
|
33
|
|
|
}
|
34
|
|
|
|
35
|
|
|
public function tearDown()
|
36
|
|
|
{
|
37
|
|
|
$this->scoreCalculator = null;
|
38
|
|
|
$this->player = null;
|
39
|
|
|
}
|
40
|
|
|
|
41
|
|
|
public function testCalculateSkill1()
|
42
|
|
|
{
|
43
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(15625000);
|
44
|
|
|
$this->player->getSkills()->setAll(50);
|
45
|
|
|
$this->assertEquals(50, $this->scoreCalculator->calculateBuyScore($this->player));
|
46
|
|
|
}
|
47
|
|
|
|
48
|
|
|
public function testCalculateSkill2()
|
49
|
|
|
{
|
50
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(15625000);
|
51
|
|
|
$this->player->getSkills()->setAll(50);
|
52
|
|
|
$this->player->getSkills()->setTackling(100);
|
53
|
|
|
$this->player->getSkills()->setDribbling(100);
|
54
|
|
|
$this->assertEquals(20, $this->scoreCalculator->calculateBuyScore($this->player));
|
55
|
|
|
}
|
56
|
|
|
|
57
|
|
|
public function testCalculateSkill3()
|
58
|
|
|
{
|
59
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(15625000);
|
60
|
|
|
$this->scoreCalculator->getManager()->setTransferFactorTackling(20);
|
61
|
|
|
$this->scoreCalculator->getManager()->setTransferFactorCrossing(0);
|
62
|
|
|
$this->player->getSkills()->setAll(50);
|
63
|
|
|
$this->player->getSkills()->setTackling(100);
|
64
|
|
|
$this->player->getSkills()->setCrossing(0);
|
65
|
|
|
$this->assertEquals(60, $this->scoreCalculator->calculateBuyScore($this->player));
|
66
|
|
|
}
|
67
|
|
|
|
68
|
|
|
public function testCalculateSkill4()
|
69
|
|
|
{
|
70
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(1000000000);
|
71
|
|
|
$this->player->getSkills()->setAll(100);
|
72
|
|
|
$this->assertEquals(100, $this->scoreCalculator->calculateBuyScore($this->player));
|
73
|
|
|
}
|
74
|
|
|
|
75
|
|
|
public function testCalculateSkillMoney1()
|
76
|
|
|
{
|
77
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(500000000);
|
78
|
|
|
$this->player->getSkills()->setAll(100);
|
79
|
|
|
$this->assertEquals(50, $this->scoreCalculator->calculateBuyScore($this->player));
|
80
|
|
|
}
|
81
|
|
|
|
82
|
|
View Code Duplication |
public function testCalculateSkillMoney2()
|
|
|
|
|
83
|
|
|
{
|
84
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(500000000);
|
85
|
|
|
$this->scoreCalculator->getManager()->setMoneyBehaviour(Manager::MONEY_BEHAVIOUR_DEFENSIVE);
|
86
|
|
|
$this->player->getSkills()->setAll(100);
|
87
|
|
|
$this->assertEquals(25, $this->scoreCalculator->calculateBuyScore($this->player));
|
88
|
|
|
}
|
89
|
|
|
|
90
|
|
View Code Duplication |
public function testCalculateSkillMoney3()
|
|
|
|
|
91
|
|
|
{
|
92
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(2000000000);
|
93
|
|
|
$this->scoreCalculator->getManager()->setMoneyBehaviour(Manager::MONEY_BEHAVIOUR_DEFENSIVE);
|
94
|
|
|
$this->player->getSkills()->setAll(100);
|
95
|
|
|
$this->assertEquals(100, $this->scoreCalculator->calculateBuyScore($this->player));
|
96
|
|
|
}
|
97
|
|
|
|
98
|
|
View Code Duplication |
public function testCalculateSkillMoney4()
|
|
|
|
|
99
|
|
|
{
|
100
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(500000000);
|
101
|
|
|
$this->scoreCalculator->getManager()->setMoneyBehaviour(Manager::MONEY_BEHAVIOUR_OFFENSIVE);
|
102
|
|
|
$this->player->getSkills()->setAll(100);
|
103
|
|
|
$this->assertEquals(100, $this->scoreCalculator->calculateBuyScore($this->player));
|
104
|
|
|
}
|
105
|
|
|
|
106
|
|
View Code Duplication |
public function testCalculateSkillMoney5()
|
|
|
|
|
107
|
|
|
{
|
108
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(2000000000);
|
109
|
|
|
$this->scoreCalculator->getManager()->setMoneyBehaviour(Manager::MONEY_BEHAVIOUR_OFFENSIVE);
|
110
|
|
|
$this->player->getSkills()->setAll(100);
|
111
|
|
|
$this->assertEquals(400, $this->scoreCalculator->calculateBuyScore($this->player));
|
112
|
|
|
}
|
113
|
|
|
|
114
|
|
|
public function testCalculateSkillMoneySell1()
|
115
|
|
|
{
|
116
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(500000000);
|
117
|
|
|
$this->player->getSkills()->setAll(100);
|
118
|
|
|
$this->assertEquals(400, $this->scoreCalculator->calculateSellScore($this->player));
|
119
|
|
|
}
|
120
|
|
|
|
121
|
|
View Code Duplication |
public function testCalculateSkillMoneySell2()
|
|
|
|
|
122
|
|
|
{
|
123
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(500000000);
|
124
|
|
|
$this->scoreCalculator->getManager()->setMoneyBehaviour(Manager::MONEY_BEHAVIOUR_DEFENSIVE);
|
125
|
|
|
$this->player->getSkills()->setAll(100);
|
126
|
|
|
$this->assertEquals(800, $this->scoreCalculator->calculateSellScore($this->player));
|
127
|
|
|
}
|
128
|
|
|
|
129
|
|
View Code Duplication |
public function testCalculateSkillMoneySell3()
|
|
|
|
|
130
|
|
|
{
|
131
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(2000000000);
|
132
|
|
|
$this->scoreCalculator->getManager()->setMoneyBehaviour(Manager::MONEY_BEHAVIOUR_DEFENSIVE);
|
133
|
|
|
$this->player->getSkills()->setAll(100);
|
134
|
|
|
$this->assertEquals(200, $this->scoreCalculator->calculateSellScore($this->player));
|
135
|
|
|
}
|
136
|
|
|
|
137
|
|
View Code Duplication |
public function testCalculateSkillMoneySell4()
|
|
|
|
|
138
|
|
|
{
|
139
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(500000000);
|
140
|
|
|
$this->scoreCalculator->getManager()->setMoneyBehaviour(Manager::MONEY_BEHAVIOUR_OFFENSIVE);
|
141
|
|
|
$this->player->getSkills()->setAll(100);
|
142
|
|
|
$this->assertEquals(200, $this->scoreCalculator->calculateSellScore($this->player));
|
143
|
|
|
}
|
144
|
|
|
|
145
|
|
View Code Duplication |
public function testCalculateSkillMoneySell5()
|
|
|
|
|
146
|
|
|
{
|
147
|
|
|
$this->scoreCalculator->getManager()->getTeam()->setMoney(2000000000);
|
148
|
|
|
$this->scoreCalculator->getManager()->setMoneyBehaviour(Manager::MONEY_BEHAVIOUR_OFFENSIVE);
|
149
|
|
|
$this->player->getSkills()->setAll(100);
|
150
|
|
|
$this->assertEquals(50, $this->scoreCalculator->calculateSellScore($this->player));
|
151
|
|
|
}
|
152
|
|
|
|
153
|
|
|
public function testCalculateSellWithLessThan11Players()
|
154
|
|
|
{
|
155
|
|
|
$team = new Team();
|
156
|
|
|
$team->setMoney(1000000);
|
157
|
|
|
$this->scoreCalculator->getManager()->setTeam($team);
|
158
|
|
|
$this->player->getSkills()->setAll(100);
|
159
|
|
|
$this->assertEquals(-1, $this->scoreCalculator->calculateSellScore($this->player));
|
160
|
|
|
}
|
161
|
|
|
|
162
|
|
|
public function testGetMoneyPercentage()
|
163
|
|
|
{
|
164
|
|
|
$this->assertEquals(0.1, $this->scoreCalculator->getMoneyPercentage(10, 100));
|
165
|
|
|
$this->assertEquals(1, $this->scoreCalculator->getMoneyPercentage(100, 100));
|
166
|
|
|
$this->assertEquals(0, $this->scoreCalculator->getMoneyPercentage(100, 0));
|
167
|
|
|
}
|
168
|
|
|
}
|
169
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.