45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace BattleForge\Tests\Unit\Domain;
|
|
|
|
use BattleForge\Domain\Battlefield;
|
|
use BattleForge\Domain\Position;
|
|
use BattleForge\Domain\Terrain;
|
|
use InvalidArgumentException;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class BattlefieldTest extends TestCase
|
|
{
|
|
public function testItRejectsDimensionsOutsideTheSupportedRange(): void
|
|
{
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
new Battlefield(7, 16);
|
|
}
|
|
|
|
public function testItFindsReachableTilesUsingTerrainCostsAndObstacles(): void
|
|
{
|
|
$battlefield = new Battlefield(8, 8, [
|
|
'1:0' => Terrain::Forest,
|
|
'0:1' => Terrain::Rough,
|
|
'2:0' => Terrain::Water,
|
|
'1:1' => Terrain::Blocking,
|
|
]);
|
|
|
|
$reachable = $battlefield->reachable(
|
|
new Position(0, 0),
|
|
2,
|
|
[new Position(0, 2)],
|
|
);
|
|
|
|
self::assertSame(0, $reachable['0:0']);
|
|
self::assertSame(2, $reachable['1:0']);
|
|
self::assertSame(2, $reachable['0:1']);
|
|
self::assertArrayNotHasKey('2:0', $reachable);
|
|
self::assertArrayNotHasKey('1:1', $reachable);
|
|
self::assertArrayNotHasKey('0:2', $reachable);
|
|
}
|
|
}
|