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); } }