game-village-politics-backend/tests/Unit/Game/VillageGridTest.php

40 lines
1.3 KiB
PHP
Raw Normal View History

<?php
use App\Game\Buildings\VillageGrid;
it('keeps footprints inside the bounds', function () {
$grid = new VillageGrid(10, 5);
expect($grid->fits(3, 3, 0, 0))->toBeTrue()
->and($grid->fits(3, 3, 7, 2))->toBeTrue()
->and($grid->fits(3, 3, 8, 0))->toBeFalse()
->and($grid->fits(2, 2, 0, 4))->toBeFalse()
->and($grid->fits(1, 1, -1, 0))->toBeFalse();
});
it('rejects overlapping footprints', function () {
$grid = VillageGrid::with(10, 5, [['x' => 0, 'y' => 0, 'w' => 3, 'h' => 3]]);
expect($grid->fits(2, 2, 2, 2))->toBeFalse()
->and($grid->fits(2, 2, 3, 0))->toBeTrue();
});
it('finds the first free slot row by row', function () {
$grid = VillageGrid::with(10, 5, [
['x' => 0, 'y' => 0, 'w' => 3, 'h' => 3],
['x' => 3, 'y' => 0, 'w' => 2, 'h' => 2],
]);
expect($grid->freeSlot(2, 2))->toBe(['x' => 5, 'y' => 0])
->and($grid->freeSlot(1, 1))->toBe(['x' => 5, 'y' => 0])
->and($grid->freeSlot(10, 3))->toBeNull();
});
it('lets the wall fit without taking cells', function () {
$full = VillageGrid::with(2, 2, [['x' => 0, 'y' => 0, 'w' => 2, 'h' => 2]]);
expect($full->fits(0, 0, 0, 0))->toBeTrue()
->and($full->freeSlot(0, 0))->toBe(['x' => 0, 'y' => 0])
->and($full->freeSlot(1, 1))->toBeNull();
});