47 lines
1.9 KiB
PHP
47 lines
1.9 KiB
PHP
<?php
|
||
|
||
use App\Game\Economy\Population;
|
||
use App\Game\Economy\Production;
|
||
use App\Game\Economy\Settle;
|
||
|
||
it('gives full output at full staffing and about a tenth when empty', function () {
|
||
$production = new Production(gameConfig());
|
||
|
||
expect($production->staffingFactor(1.0))->toBe(1.0)
|
||
->and($production->staffingFactor(0.0))->toEqualWithDelta(0.1, 0.001)
|
||
->and($production->staffingFactor(0.5))->toEqualWithDelta(exp(-1.15), 1e-9);
|
||
});
|
||
|
||
it('adds buildings to the base trickle and nets food against upkeep', function () {
|
||
$config = gameConfig();
|
||
$buildings = [building(1, 'headquarters'), building(2, 'storage'), building(3, 'farm'), building(4, 'timber_camp')];
|
||
$workforce = (new Population($config))->workforce($buildings);
|
||
$rates = (new Production($config))->rates($buildings, $workforce);
|
||
|
||
expect($rates['wood'])->toBe(5.0 + 30.0)
|
||
->and($rates['clay'])->toBe(5.0)
|
||
->and($rates['iron'])->toBe(5.0)
|
||
->and($rates['food'])->toBe(30.0 - 24);
|
||
});
|
||
|
||
it('makes less in an understaffed building', function () {
|
||
$config = gameConfig();
|
||
// 24 villagers (80% of 30 food) for a timber camp needing round(2 × 1.12^30) = 60.
|
||
$buildings = [building(1, 'farm'), building(2, 'timber_camp', 30)];
|
||
$workforce = (new Population($config))->workforce($buildings);
|
||
$production = new Production($config);
|
||
|
||
$ratio = 22 / 60;
|
||
expect($workforce->ratio(2))->toBe($ratio)
|
||
->and($production->output($buildings[1], $workforce)['per_hour'])
|
||
->toEqualWithDelta(30 * 1.163 ** 30 * exp(2.3 * ($ratio - 1)), 1e-6);
|
||
});
|
||
|
||
it('settles stored amounts by rate and elapsed hours within the cap', function () {
|
||
$stored = ['wood' => 100.0, 'clay' => 990.0, 'iron' => 5.0, 'food' => 50.0];
|
||
$rates = ['wood' => 30.0, 'clay' => 30.0, 'iron' => -20.0, 'food' => 0.0];
|
||
|
||
expect(Settle::advance($stored, $rates, 1000.0, 0.5))
|
||
->toBe(['wood' => 115.0, 'clay' => 1000.0, 'iron' => 0.0, 'food' => 50.0]);
|
||
});
|