|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace SmrTest\lib\DefaultGame; |
|
4
|
|
|
|
|
5
|
|
|
use AbstractSmrShip; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use SmrForce; |
|
8
|
|
|
use SmrTest\TestUtils; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers SmrForce |
|
12
|
|
|
*/ |
|
13
|
|
|
class SmrForceTest extends TestCase { |
|
14
|
|
|
|
|
15
|
|
|
private SmrForce $force; |
|
16
|
|
|
|
|
17
|
|
|
protected function setUp(): void { |
|
18
|
|
|
// Create an arbitrary empty force (we avoid using `getForce` for now |
|
19
|
|
|
// because of the call to the complicated function `tidyUpForces`). |
|
20
|
|
|
$this->force = TestUtils::constructPrivateClass(SmrForce::class, 1, 2, 3); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function test_constructor_properties(): void { |
|
24
|
|
|
self::assertSame(1, $this->force->getGameID()); |
|
25
|
|
|
self::assertSame(2, $this->force->getSectorID()); |
|
26
|
|
|
self::assertSame(3, $this->force->getOwnerID()); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @dataProvider provider_getBumpTurnCost |
|
31
|
|
|
*/ |
|
32
|
|
|
public function test_getBumpTurnCost(int $mines, bool $hasDCS, int $expected): void { |
|
33
|
|
|
$this->force->setMines($mines); |
|
34
|
|
|
$ship = $this->createPartialMock(AbstractSmrShip::class, ['hasDCS', 'isFederal']); |
|
35
|
|
|
$ship->method('hasDCS')->willReturn($hasDCS); |
|
36
|
|
|
$ship->method('isFederal')->willReturn(false); // redundant with hasDCS |
|
37
|
|
|
self::assertSame($expected, $this->force->getBumpTurnCost($ship)); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return array<array{int, bool, int}> |
|
|
|
|
|
|
42
|
|
|
*/ |
|
43
|
|
|
public function provider_getBumpTurnCost(): array { |
|
44
|
|
|
return [ |
|
45
|
|
|
[0, false, 0], |
|
46
|
|
|
[0, true, 0], |
|
47
|
|
|
[9, false, 1], |
|
48
|
|
|
[9, true, 0], |
|
49
|
|
|
[24, false, 2], |
|
50
|
|
|
[24, true, 1], |
|
51
|
|
|
[25, false, 3], |
|
52
|
|
|
[25, true, 2], |
|
53
|
|
|
]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @dataProvider provider_getAttackTurnCost |
|
58
|
|
|
*/ |
|
59
|
|
|
public function test_getAttackTurnCost(bool $hasDCS, int $expected): void { |
|
60
|
|
|
$ship = $this->createPartialMock(AbstractSmrShip::class, ['hasDCS', 'isFederal']); |
|
61
|
|
|
$ship->method('hasDCS')->willReturn($hasDCS); |
|
62
|
|
|
$ship->method('isFederal')->willReturn(false); // redundant with hasDCS |
|
63
|
|
|
self::assertSame($expected, $this->force->getAttackTurnCost($ship)); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return array<array{bool, int}> |
|
|
|
|
|
|
68
|
|
|
*/ |
|
69
|
|
|
public function provider_getAttackTurnCost(): array { |
|
70
|
|
|
return [ |
|
71
|
|
|
[false, 3], |
|
72
|
|
|
[true, 2], |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function test_add_and_take_SDs(): void { |
|
77
|
|
|
self::assertSame(0, $this->force->getSDs()); |
|
78
|
|
|
self::assertFalse($this->force->hasSDs()); |
|
79
|
|
|
$this->force->addSDs(SmrForce::MAX_SDS); |
|
80
|
|
|
self::assertSame(SmrForce::MAX_SDS, $this->force->getSDs()); |
|
81
|
|
|
self::assertTrue($this->force->hasSDs()); |
|
82
|
|
|
self::assertTrue($this->force->hasMaxSDs()); |
|
83
|
|
|
$this->force->takeSDs(1); |
|
84
|
|
|
self::assertSame(SmrForce::MAX_SDS - 1, $this->force->getSDs()); |
|
85
|
|
|
self::assertTrue($this->force->hasSDs()); |
|
86
|
|
|
self::assertFalse($this->force->hasMaxSDs()); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function test_add_and_take_CDs(): void { |
|
90
|
|
|
self::assertSame(0, $this->force->getCDs()); |
|
91
|
|
|
self::assertFalse($this->force->hasCDs()); |
|
92
|
|
|
$this->force->addCDs(SmrForce::MAX_CDS); |
|
93
|
|
|
self::assertSame(SmrForce::MAX_CDS, $this->force->getCDs()); |
|
94
|
|
|
self::assertTrue($this->force->hasCDs()); |
|
95
|
|
|
self::assertTrue($this->force->hasMaxCDs()); |
|
96
|
|
|
$this->force->takeCDs(1); |
|
97
|
|
|
self::assertSame(SmrForce::MAX_CDS - 1, $this->force->getCDs()); |
|
98
|
|
|
self::assertTrue($this->force->hasCDs()); |
|
99
|
|
|
self::assertFalse($this->force->hasMaxCDs()); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function test_add_and_take_mines(): void { |
|
103
|
|
|
self::assertSame(0, $this->force->getMines()); |
|
104
|
|
|
self::assertFalse($this->force->hasMines()); |
|
105
|
|
|
$this->force->addMines(SmrForce::MAX_MINES); |
|
106
|
|
|
self::assertSame(SmrForce::MAX_MINES, $this->force->getMines()); |
|
107
|
|
|
self::assertTrue($this->force->hasMines()); |
|
108
|
|
|
self::assertTrue($this->force->hasMaxMines()); |
|
109
|
|
|
$this->force->takeMines(1); |
|
110
|
|
|
self::assertSame(SmrForce::MAX_MINES - 1, $this->force->getMines()); |
|
111
|
|
|
self::assertTrue($this->force->hasMines()); |
|
112
|
|
|
self::assertFalse($this->force->hasMaxMines()); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
|