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

53 lines
1.9 KiB
PHP

<?php
use App\Game\Economy\Population;
it('feeds as many villagers as the farms make food at full staffing', function () {
$population = new Population(gameConfig());
$workforce = $population->workforce([building(1, 'farm'), building(2, 'farm', 1)]);
expect($workforce->foodBudget)->toBe(30 + 30 * 1.17)
->and($workforce->villagers)->toBe(65)
->and($workforce->upkeep)->toEqual(65);
});
it('leaves soldiers upkeep out of the villagers budget', function () {
$workforce = (new Population(gameConfig()))->workforce([building(1, 'farm')], soldierUpkeep: 10);
expect($workforce->villagers)->toBe(20)
->and($workforce->upkeep)->toEqual(30);
});
it('staffs farms first, then by priority', function () {
// Farm 0 makes 30 food, so 30 villagers: the farm takes 2, priority 9 the other 28.
$buildings = [
building(1, 'timber_camp', 30, priority: 1),
building(2, 'clay_pit', 30, priority: 9),
building(3, 'farm', 0, priority: 0),
];
$workforce = (new Population(gameConfig()))->workforce($buildings);
expect($workforce->assigned)->toBe([1 => 0, 2 => 28, 3 => 2])
->and($workforce->workers())->toBe(30);
});
it('splits villagers evenly between buildings of equal priority', function () {
// 30 villagers: farm takes 2, the two level-20 camps (19 each) share 28.
$buildings = [
building(1, 'farm'),
building(2, 'timber_camp', 20),
building(3, 'clay_pit', 20),
];
$workforce = (new Population(gameConfig()))->workforce($buildings);
expect($workforce->assigned)->toBe([1 => 2, 2 => 14, 3 => 14])
->and($workforce->ratio(2))->toBe(14 / 19);
});
it('counts buildings that need nobody as fully staffed', function () {
$workforce = (new Population(gameConfig()))->workforce([building(1, 'hiding_place')]);
expect($workforce->villagers)->toBe(0)
->and($workforce->ratio(1))->toBe(1.0);
});