initial commit
This commit is contained in:
commit
e8c3f9862a
193 files changed
+29795
No files matched your search
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Game;
|
||||
|
||||
use App\Game\Entities\Zombie;
|
||||
use App\Game\EntityList;
|
||||
use App\Game\Room;
|
||||
use App\Game\Vector2;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class EntityListTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function appendAndCount(): void
|
||||
{
|
||||
$room = new Room('r');
|
||||
$list = new EntityList();
|
||||
$zombie = new Zombie(0.0, 0.0, $list, $room);
|
||||
$list->append($zombie);
|
||||
$this->assertCount(1, $list);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function removeRemovesInstance(): void
|
||||
{
|
||||
$room = new Room('r');
|
||||
$list = new EntityList();
|
||||
$a = new Zombie(0.0, 0.0, $list, $room);
|
||||
$b = new Zombie(10.0, 0.0, $list, $room);
|
||||
$list->append($a);
|
||||
$list->append($b);
|
||||
$list->remove($a);
|
||||
$this->assertCount(1, $list);
|
||||
$this->assertSame($b, $list[1]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function removeLeavesNoGapsAfterManyRemovals(): void
|
||||
{
|
||||
$room = new Room('r');
|
||||
$list = new EntityList();
|
||||
$items = [];
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
$items[] = new Zombie((float) $i, 0.0, $list, $room);
|
||||
}
|
||||
foreach ($items as $item) {
|
||||
$list->append($item);
|
||||
}
|
||||
foreach ([10, 3, 17, 0] as $index) {
|
||||
$list->remove($items[$index]);
|
||||
}
|
||||
$this->assertSame(16, $list->count());
|
||||
$this->assertFalse($list->offsetExists(10));
|
||||
$this->assertTrue($list->offsetExists(2));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function findByKindFilters(): void
|
||||
{
|
||||
$room = new Room('r');
|
||||
$list = new EntityList();
|
||||
$list->append(new Zombie(0.0, 0.0, $list, $room));
|
||||
$list->append(new Zombie(10.0, 0.0, $list, $room));
|
||||
$found = $list->findByKind('zombie');
|
||||
$this->assertCount(2, $found);
|
||||
$this->assertSame([], $list->findByKind('player'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function copyReturnsDetachedArray(): void
|
||||
{
|
||||
$room = new Room('r');
|
||||
$list = new EntityList();
|
||||
$list->append(new Zombie(0.0, 0.0, $list, $room));
|
||||
$snapshot = $list->copy();
|
||||
$list->append(new Zombie(1.0, 1.0, $list, $room));
|
||||
$this->assertCount(1, $snapshot);
|
||||
$this->assertCount(2, $list);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user