mirror of
https://github.com/solcloud/Counter-Strike.git
synced 2025-02-24 03:42:39 +01:00
Grinding 100% test coverage
This commit is contained in:
parent
f9be1895d6
commit
824dc5d2a7
@ -33,12 +33,12 @@ final class DynamicFloor extends Floor
|
||||
|
||||
public function getHitAntiForce(Point $point): int
|
||||
{
|
||||
return $this->hitAntiForce;
|
||||
throw new GameException('Should not be here');
|
||||
}
|
||||
|
||||
public function getPlane(): string
|
||||
{
|
||||
return 'xz';
|
||||
throw new GameException('Should not be here');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,9 @@ namespace cs\Core;
|
||||
class GameFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function createDefaultCompetitive(): Game
|
||||
{
|
||||
$properties = new GameProperty();
|
||||
|
@ -608,8 +608,9 @@ class World
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int,array<string,mixed>>
|
||||
* @internal
|
||||
* @codeCoverageIgnore
|
||||
* @return array<int,array<string,mixed>>
|
||||
*/
|
||||
public function getWalls(): array
|
||||
{
|
||||
@ -626,8 +627,9 @@ class World
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int,array<string,mixed>>
|
||||
* @internal
|
||||
* @codeCoverageIgnore
|
||||
* @return array<int,array<string,mixed>>
|
||||
*/
|
||||
public function getFloors(): array
|
||||
{
|
||||
|
@ -3,7 +3,10 @@
|
||||
namespace Test\Shooting;
|
||||
|
||||
use cs\Core\GameState;
|
||||
use cs\Core\Player;
|
||||
use cs\Core\Util;
|
||||
use cs\Enum\BuyMenuItem;
|
||||
use cs\Enum\Color;
|
||||
use cs\Enum\InventorySlot;
|
||||
use cs\Enum\RoundEndReason;
|
||||
use cs\Event\PlantEvent;
|
||||
@ -56,4 +59,57 @@ class BombTest extends BaseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
protected function _testBombPlantRound(bool $shouldDefuse): void
|
||||
{
|
||||
$properties = $this->createNoPauseGameProperty();
|
||||
$properties->bomb_plant_time_ms = 1;
|
||||
$properties->bomb_defuse_time_ms = 1600;
|
||||
$properties->bomb_explode_time_ms = 1000;
|
||||
|
||||
$game = $this->createTestGame(null, $properties);
|
||||
$defender = new Player(2, Color::BLUE, false);
|
||||
$game->addPlayer($defender);
|
||||
$defender->getSight()->lookAt(180, -90);
|
||||
|
||||
$roundEndEvent = null;
|
||||
$game->onTick(function (GameState $state) {
|
||||
if ($state->getTickId() === 1) {
|
||||
$state->getPlayer(1)->equip(InventorySlot::SLOT_BOMB);
|
||||
return;
|
||||
}
|
||||
$state->getPlayer(1)->attack();
|
||||
$state->getPlayer(2)->use();
|
||||
});
|
||||
$game->onEvents(function (array $events) use (&$roundEndEvent) {
|
||||
foreach ($events as $event) {
|
||||
if (!$roundEndEvent && $event instanceof RoundEndEvent) {
|
||||
$roundEndEvent = $event;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if ($shouldDefuse) {
|
||||
$defender->buyItem(BuyMenuItem::DEFUSE_KIT);
|
||||
}
|
||||
$game->start();
|
||||
|
||||
$this->assertInstanceOf(RoundEndEvent::class, $roundEndEvent);
|
||||
$this->assertSame($shouldDefuse ? RoundEndReason::BOMB_DEFUSED : RoundEndReason::BOMB_EXPLODED, $roundEndEvent->reason);
|
||||
if ($shouldDefuse) {
|
||||
$this->assertTrue($game->getScore()->defendersIsWinning());
|
||||
$this->assertFalse($game->getScore()->attackersIsWinning());
|
||||
} else {
|
||||
$this->assertTrue($game->getScore()->attackersIsWinning());
|
||||
$this->assertFalse($game->getScore()->defendersIsWinning());
|
||||
}
|
||||
$this->assertFalse($game->getScore()->isTie());
|
||||
}
|
||||
|
||||
public function testBombPlantDefuse(): void
|
||||
{
|
||||
$this->_testBombPlantRound(false);
|
||||
$this->_testBombPlantRound(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -48,7 +48,10 @@ class PlayerKillTest extends BaseTestCase
|
||||
$this->assertCount(2, $hits);
|
||||
$headHit = $hits[0];
|
||||
$this->assertInstanceOf(HitBox::class, $headHit);
|
||||
$this->assertInstanceOf(Wall::class, $hits[1]);
|
||||
$wall = $hits[1];
|
||||
$this->assertInstanceOf(Wall::class, $wall);
|
||||
$this->assertFalse($wall->playerWasKilled());
|
||||
$this->assertGreaterThan(0, $wall->getHitAntiForce(new Point()));
|
||||
|
||||
$playerOne = $headHit->getPlayer();
|
||||
$this->assertInstanceOf(Player::class, $playerOne);
|
||||
|
@ -4,6 +4,7 @@ namespace Test\Unit;
|
||||
|
||||
use cs\Core\Box;
|
||||
use cs\Core\Floor;
|
||||
use cs\Core\GameException;
|
||||
use cs\Core\Point;
|
||||
use cs\Core\Wall;
|
||||
use Test\BaseTest;
|
||||
@ -58,6 +59,22 @@ class BoxTest extends BaseTest
|
||||
$this->assertPositionSame($point->clone()->addX($width), $rightWall->getStart());
|
||||
$pointEnd = $point->clone()->addX($width)->addZ($depth)->addY($height);
|
||||
$this->assertPositionSame($pointEnd, $rightWall->getEnd());
|
||||
|
||||
$this->assertSame([
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'depth' => $depth,
|
||||
'x' => $point->x,
|
||||
'y' => $point->y,
|
||||
'z' => $point->z,
|
||||
], $box->toArray());
|
||||
}
|
||||
|
||||
public function testBoxWithoutSideThrow(): void
|
||||
{
|
||||
$this->expectException(GameException::class);
|
||||
$this->expectExceptionMessage('Choose at least one box side');
|
||||
new Box(new Point(), 1,1,1, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use cs\Core\GameProperty;
|
||||
use cs\Core\GameState;
|
||||
use cs\Core\Player;
|
||||
use cs\Enum\Color;
|
||||
use cs\Map\TestMap;
|
||||
use cs\Net\PlayerControl;
|
||||
use cs\Net\Protocol;
|
||||
use cs\Net\ProtocolReader;
|
||||
@ -53,4 +54,68 @@ class ProtocolTest extends BaseTest
|
||||
$this->assertSame([], $protocol->parsePlayerControlCommands("lookAt 1"));
|
||||
}
|
||||
|
||||
public function testSerialization(): void
|
||||
{
|
||||
$player = new Player(1, Color::BLUE, true);
|
||||
$game = new Game(new GameProperty());
|
||||
$game->loadMap(new TestMap());
|
||||
$game->addPlayer($player);
|
||||
$player->getSight()->lookAt(12.45, 1.09);
|
||||
$protocol = new Protocol\TextProtocol();
|
||||
|
||||
$playerSerializedExpected = [
|
||||
'id' => 1,
|
||||
'color' => 1,
|
||||
'money' => 800,
|
||||
'item' => [
|
||||
'id' => 2,
|
||||
'slot' => 2,
|
||||
],
|
||||
'canAttack' => false,
|
||||
'canBuy' => true,
|
||||
'canPlant' => false,
|
||||
'slots' => [
|
||||
0 => [
|
||||
'id' => 1,
|
||||
'slot' => 0,
|
||||
],
|
||||
2 => [
|
||||
'id' => 2,
|
||||
'slot' => 2,
|
||||
],
|
||||
3 => [
|
||||
'id' => 50,
|
||||
'slot' => 3,
|
||||
],
|
||||
],
|
||||
'health' => 100,
|
||||
'position' => [
|
||||
'x' => 0,
|
||||
'y' => 0,
|
||||
'z' => 0,
|
||||
],
|
||||
'look' => [
|
||||
'horizontal' => 12.45,
|
||||
'vertical' => 1.09,
|
||||
],
|
||||
'isAttacker' => true,
|
||||
'sight' => 180,
|
||||
'armor' => 0,
|
||||
'armorType' => 0,
|
||||
'ammo' => 12,
|
||||
'ammoReserve' => 120,
|
||||
'isReloading' => false,
|
||||
];
|
||||
$this->assertSame($playerSerializedExpected, $player->serialize());
|
||||
|
||||
$expected = [
|
||||
'players' => [
|
||||
$playerSerializedExpected,
|
||||
],
|
||||
'events' => [],
|
||||
];
|
||||
$actual = $protocol->serialize($game->getPlayers(), []);
|
||||
$this->assertSame($expected, json_decode($actual, true));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -70,6 +70,39 @@ class WallTest extends BaseTestCase
|
||||
$this->assertNotNull($world->checkXSideWallCollision(new Point($x, 0, 0), 12, 20));
|
||||
}
|
||||
|
||||
public function testWallSerialization(): void
|
||||
{
|
||||
$wall = new Wall(new Point(1, 2, 3), true, 10, 20);
|
||||
$this->assertSame([
|
||||
's' => [
|
||||
'x' => 1,
|
||||
'y' => 2,
|
||||
'z' => 3,
|
||||
],
|
||||
'e' =>[
|
||||
'x' => 11,
|
||||
'y' => 22,
|
||||
'z' => 3,
|
||||
],
|
||||
'p' => 'xy',
|
||||
], $wall->toArray());
|
||||
|
||||
$wall = new Wall(new Point(1, 2, 3), false, 10, 20);
|
||||
$this->assertSame([
|
||||
's' => [
|
||||
'x' => 1,
|
||||
'y' => 2,
|
||||
'z' => 3,
|
||||
],
|
||||
'e' =>[
|
||||
'x' => 1,
|
||||
'y' => 22,
|
||||
'z' => 13,
|
||||
],
|
||||
'p' => 'zy',
|
||||
], $wall->toArray());
|
||||
}
|
||||
|
||||
public function testRampGenerate(): void
|
||||
{
|
||||
$stepDepth = 2;
|
||||
|
Loading…
x
Reference in New Issue
Block a user