test: strengthen battlefield boundary coverage
This commit is contained in:
@@ -19,6 +19,22 @@ final class BattlefieldTest extends TestCase
|
||||
new Battlefield(7, 16);
|
||||
}
|
||||
|
||||
public function testItAcceptsMinimumAndMaximumDimensions(): void
|
||||
{
|
||||
$minimum = new Battlefield(8, 8);
|
||||
$maximum = new Battlefield(16, 16);
|
||||
|
||||
self::assertSame([8, 8], [$minimum->width, $minimum->height]);
|
||||
self::assertSame([16, 16], [$maximum->width, $maximum->height]);
|
||||
}
|
||||
|
||||
public function testItRejectsDimensionsAboveTheSupportedRange(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
new Battlefield(16, 17);
|
||||
}
|
||||
|
||||
public function testItRejectsNonCanonicalTerrainCoordinates(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
@@ -37,9 +53,8 @@ final class BattlefieldTest extends TestCase
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
$terrain = ['0:0' => 'forest'];
|
||||
|
||||
new Battlefield(8, 8, $terrain);
|
||||
// @phpstan-ignore argument.type
|
||||
new Battlefield(8, 8, ['0:0' => 'forest']);
|
||||
}
|
||||
|
||||
public function testReachableRejectsAStartOutsideTheBattlefield(): void
|
||||
@@ -90,4 +105,17 @@ final class BattlefieldTest extends TestCase
|
||||
'0:1' => 2,
|
||||
], $reachable);
|
||||
}
|
||||
|
||||
public function testReachableReplacesAHighCostRouteWithALowerCostDetour(): void
|
||||
{
|
||||
$battlefield = new Battlefield(8, 8, [
|
||||
'1:0' => Terrain::Forest,
|
||||
'2:0' => Terrain::Forest,
|
||||
'3:0' => Terrain::Forest,
|
||||
]);
|
||||
|
||||
$reachable = $battlefield->reachable(new Position(0, 0), 7, []);
|
||||
|
||||
self::assertSame(6, $reachable['4:0']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user