1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace HeroesofAbenez\Combat; |
5
|
|
|
|
6
|
|
|
require __DIR__ . "/../../bootstrap.php"; |
7
|
|
|
|
8
|
|
|
use Tester\Assert; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Jakub Konečný |
12
|
|
|
* @testCase |
13
|
|
|
*/ |
14
|
|
|
final class TeamTest extends \Tester\TestCase { |
15
|
|
|
protected function generateCharacter(int $id): Character { |
16
|
|
|
$stats = [ |
17
|
|
|
"id" => $id, "name" => "Player $id", "level" => 1, "initiativeFormula" => "1d2+DEX/4", "strength" => 10, |
18
|
|
|
"dexterity" => 10, "constitution" => 10, "intelligence" => 10, "charisma" => 10 |
19
|
|
|
]; |
20
|
|
|
return new Character($stats); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testGetName(): void { |
24
|
|
|
$name = "Team 1"; |
25
|
|
|
$team = new Team($name); |
26
|
|
|
Assert::same($name, $team->name); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testMaxRowSize(): void { |
30
|
|
|
$team = new Team(""); |
31
|
|
|
$team->maxRowSize = 1; |
32
|
|
|
Assert::same(1, $team->maxRowSize); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetAliveMembers(): void { |
36
|
|
|
$team = new Team(""); |
37
|
|
|
Assert::count(0, $team->aliveMembers); |
38
|
|
|
$team[] = $this->generateCharacter(1); |
39
|
|
|
Assert::count(1, $team->aliveMembers); |
40
|
|
|
$team[] = $this->generateCharacter(2); |
41
|
|
|
Assert::count(2, $team->aliveMembers); |
42
|
|
|
$team[0]->harm($team[0]->maxHitpoints); |
43
|
|
|
Assert::count(1, $team->aliveMembers); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testGetUsableMembers(): void { |
47
|
|
|
$team = new Team(""); |
48
|
|
|
Assert::count(0, $team->usableMembers); |
49
|
|
|
$team[] = $this->generateCharacter(1); |
50
|
|
|
Assert::count(1, $team->usableMembers); |
51
|
|
|
$team[] = $this->generateCharacter(2); |
52
|
|
|
Assert::count(2, $team->usableMembers); |
53
|
|
|
$team[0]->harm($team[0]->maxHitpoints); |
54
|
|
|
Assert::count(1, $team->usableMembers); |
55
|
|
|
$stunEffect = [ |
56
|
|
|
"id" => "stunEffect", "type" => SkillSpecial::TYPE_STUN, "valueAbsolute" => false, |
57
|
|
|
"value" => 0, "duration" => CharacterEffect::DURATION_FOREVER, "stat" => "", |
58
|
|
|
]; |
59
|
|
|
$team[1]->effects[] = new CharacterEffect($stunEffect); |
60
|
|
|
$team[1]->recalculateStats(); |
61
|
|
|
Assert::count(0, $team->usableMembers); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testHasAliveMembers(): void { |
65
|
|
|
$team = new Team(""); |
66
|
|
|
Assert::false($team->hasAliveMembers()); |
67
|
|
|
$team[] = $this->generateCharacter(1); |
68
|
|
|
Assert::true($team->hasAliveMembers()); |
69
|
|
|
$team[0]->harm($team[0]->maxHitpoints); |
70
|
|
|
Assert::false($team->hasAliveMembers()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testSetCharacterPosition(): void { |
74
|
|
|
$team = new Team(""); |
75
|
|
|
$team[] = $this->generateCharacter(1); |
76
|
|
|
$team->setCharacterPosition(1, 1, 1); |
77
|
|
|
Assert::same(1, $team[0]->positionRow); |
78
|
|
|
Assert::same(1, $team[0]->positionColumn); |
79
|
|
|
Assert::exception(function() use($team) { |
80
|
|
|
$team->setCharacterPosition(2, 1, 1); |
81
|
|
|
}, \OutOfBoundsException::class); |
82
|
|
|
$team[] = $this->generateCharacter(2); |
83
|
|
|
Assert::exception(function() use($team) { |
84
|
|
|
$team->setCharacterPosition(2, 1, 1); |
85
|
|
|
}, InvalidCharacterPositionException::class, null, InvalidCharacterPositionException::POSITION_OCCUPIED); |
86
|
|
|
Assert::exception(function() use($team) { |
87
|
|
|
$team->maxRowSize = 1; |
88
|
|
|
$team->setCharacterPosition(2, 1, 2); |
89
|
|
|
}, InvalidCharacterPositionException::class, null, InvalidCharacterPositionException::ROW_FULL); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testGetRandomCharacter(): void { |
93
|
|
|
$team = new Team(""); |
94
|
|
|
Assert::null($team->getRandomCharacter()); |
95
|
|
|
$team[] = $this->generateCharacter(1); |
96
|
|
|
Assert::same($team[0], $team->getRandomCharacter()); |
97
|
|
|
$team[] = $this->generateCharacter(2); |
98
|
|
|
Assert::type(Character::class, $team->getRandomCharacter()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testGetLowestHpCharacter(): void { |
102
|
|
|
$team = new Team(""); |
103
|
|
|
Assert::null($team->getLowestHpCharacter()); |
104
|
|
|
$team[] = $this->generateCharacter(1); |
105
|
|
|
Assert::null($team->getLowestHpCharacter()); |
106
|
|
|
$team[0]->harm(10); |
107
|
|
|
Assert::same($team[0], $team->getLowestHpCharacter(0.8)); |
108
|
|
|
Assert::null($team->getLowestHpCharacter()); |
109
|
|
|
$team[0]->harm(20); |
110
|
|
|
Assert::same($team[0], $team->getLowestHpCharacter()); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testGetRowToAttack(): void { |
114
|
|
|
$team = new Team(""); |
115
|
|
|
Assert::null($team->rowToAttack); |
116
|
|
|
$team[] = $character1 = $this->generateCharacter(1); |
117
|
|
|
$character1->positionRow = 1; |
118
|
|
|
$team[] = $character2 = $this->generateCharacter(2); |
119
|
|
|
$character2->positionRow = 2; |
120
|
|
|
Assert::same(1, $team->rowToAttack); |
121
|
|
|
$character1->harm($character1->maxHitpoints); |
122
|
|
|
Assert::same(2, $team->rowToAttack); |
123
|
|
|
$character2->harm($character2->maxHitpoints); |
124
|
|
|
Assert::null($team->rowToAttack); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$test = new TeamTest(); |
129
|
|
|
$test->run(); |
130
|
|
|
?> |