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

69 lines
2.8 KiB
PHP

<?php
use App\Game\Buildings\BuildingRules;
it('costs the base at level 0 and grows by the factor per level', function () {
$rules = new BuildingRules(gameConfig());
expect($rules->cost('timber_camp', 0))->toBe(['wood' => 50, 'clay' => 60, 'iron' => 40])
->and($rules->cost('timber_camp', 2))->toBe([
'wood' => (int) round(50 * 1.25 ** 2),
'clay' => (int) round(60 * 1.25 ** 2),
'iron' => (int) round(40 * 1.25 ** 2),
]);
});
it('makes later instances of a type more expensive', function () {
$rules = new BuildingRules(gameConfig());
expect($rules->cost('farm', 0, 1))->toBe(['wood' => 68, 'clay' => 60, 'iron' => 45])
->and($rules->cost('headquarters', 0, 3))->toBe($rules->cost('headquarters', 0));
});
it('divides build time by world speed, headquarters level and staffing', function () {
$rules = new BuildingRules(gameConfig());
$fast = new BuildingRules(gameConfig(['world' => ['speed' => 100]]));
expect($rules->buildSeconds('timber_camp', 0, 0, 1.0))->toBe(90)
->and($rules->buildSeconds('timber_camp', 1, 0, 1.0))->toBe(108)
->and($rules->buildSeconds('timber_camp', 0, 10, 1.0))->toBe(60)
->and($rules->buildSeconds('timber_camp', 0, 0, 0.5))->toBe(180)
->and($fast->buildSeconds('timber_camp', 0, 0, 1.0))->toBe(1);
});
it('takes half the time and refunds half the cost when demolishing', function () {
$rules = new BuildingRules(gameConfig());
expect($rules->demolishSeconds('timber_camp', 1, 0, 1.0))->toBe(54)
->and($rules->demolishRefund('timber_camp', 0))->toBe(['wood' => 25, 'clay' => 30, 'iron' => 20]);
});
it('rounds workers and scales output with world speed', function () {
$rules = new BuildingRules(gameConfig());
$fast = new BuildingRules(gameConfig(['world' => ['speed' => 2]]));
expect($rules->workers('timber_camp', 0))->toBe(2)
->and($rules->workers('timber_camp', 10))->toBe((int) round(2 * 1.12 ** 10))
->and($rules->workers('hiding_place', 5))->toBe(0)
->and($rules->output('timber_camp', 0))->toBe(['resource' => 'wood', 'per_hour' => 30.0])
->and($fast->output('farm', 0))->toBe(['resource' => 'food', 'per_hour' => 60.0])
->and($rules->output('storage', 3))->toBeNull();
});
it('gives storage capacity only to storage', function () {
$rules = new BuildingRules(gameConfig());
expect($rules->capacity('storage', 0))->toBe(1000.0)
->and($rules->capacity('storage', 1))->toBe(1230.0)
->and($rules->capacity('farm', 1))->toBe(0.0);
});
it('adds builders at the configured headquarters levels', function () {
$rules = new BuildingRules(gameConfig());
expect($rules->builders(0))->toBe(2)
->and($rules->builders(9))->toBe(2)
->and($rules->builders(10))->toBe(3)
->and($rules->builders(20))->toBe(4);
});