32 lines
1.5 KiB
PHP
32 lines
1.5 KiB
PHP
<?php
|
|
|
|
use App\Game\ConfigLint;
|
|
use App\Game\Military\Wounds;
|
|
|
|
it('brings half of each fallen unit back wounded, rounded down', function () {
|
|
$wounds = new Wounds(gameConfig());
|
|
|
|
expect($wounds->admit(['spear' => 10, 'sword' => 5, 'archer' => 1], 100))->toBe(['spear' => 5, 'sword' => 2])
|
|
->and($wounds->admit([], 100))->toBe([]);
|
|
});
|
|
|
|
it('shares scarce beds evenly, the leftover bed to the largest remainder', function () {
|
|
$wounds = new Wounds(gameConfig());
|
|
|
|
// 20 spear and 6 sword wounded for 13 beds: 10 and 3 exactly.
|
|
expect($wounds->admit(['spear' => 40, 'sword' => 12], 13))->toBe(['spear' => 10, 'sword' => 3])
|
|
// 10 and 3 for 5 beds: 3.85 and 1.15 → 3 and 1, the fifth bed to spear.
|
|
->and($wounds->admit(['spear' => 20, 'sword' => 6], 5))->toBe(['spear' => 4, 'sword' => 1])
|
|
->and($wounds->admit(['spear' => 20], 0))->toBe([]);
|
|
});
|
|
|
|
it('heals after four hours at world speed 1', function () {
|
|
expect((new Wounds(gameConfig()))->healSeconds())->toBe(14400)
|
|
->and((new Wounds(gameConfig(['world' => ['speed' => 100]])))->healSeconds())->toBe(144);
|
|
});
|
|
|
|
it('lints a share outside 0..1 and a heal time of 0', function () {
|
|
expect(ConfigLint::check(gameConfig(['combat' => ['hospital' => ['share' => 1.5]]])))->toContain('[combat.hospital.share] must be between 0 and 1, or more come back than fell.')
|
|
->and(ConfigLint::check(gameConfig(['combat' => ['hospital' => ['heal_time' => 0]]])))->toContain('[combat.hospital.heal_time] must be more than 0 seconds.');
|
|
});
|