InitiativeFormulaParserTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 19
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateCharacter() 0 7 1
A testCalculateInitiative() 0 8 2
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
require __DIR__ . "/../../bootstrap.php";
7
8
use Tester\Assert;
9
10
/**
11
 * @author Jakub Konečný
12
 * @testCase
13
 */
14
final class InitiativeFormulaParserTest extends \Tester\TestCase
15
{
16
    private function generateCharacter(int $id): Character
17
    {
18
        $stats = [
19
            "id" => $id, "name" => "Player $id", "level" => 1, "initiativeFormula" => "1d4+DEX/4", "strength" => 10,
20
            "dexterity" => 12, "constitution" => 10, "intelligence" => 10, "charisma" => 10
21
        ];
22
        return new Character($stats);
23
    }
24
25
    public function testCalculateInitiative(): void
26
    {
27
        $character = $this->generateCharacter(1);
28
        $parser = new InitiativeFormulaParser();
29
        for ($i = 1; $i <= 10; $i++) {
30
            $initiative = $parser->calculateInitiative($character);
31
            Assert::true($initiative >= 4);
32
            Assert::true($initiative <= 8);
33
        }
34
    }
35
}
36
37
$test = new InitiativeFormulaParserTest();
38
$test->run();
39