InitiativeFormulaParserTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 16
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateCharacter() 0 6 1
A testCalculateInitiative() 0 7 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
  protected function generateCharacter(int $id): Character {
16
    $stats = [
17
      "id" => $id, "name" => "Player $id", "level" => 1, "initiativeFormula" => "1d4+DEX/4", "strength" => 10,
18
      "dexterity" => 12, "constitution" => 10, "intelligence" => 10, "charisma" => 10
19
    ];
20
    return new Character($stats);
21
  }
22
  
23
  public function testCalculateInitiative(): void {
24
    $character = $this->generateCharacter(1);
25
    $parser = new InitiativeFormulaParser();
26
    for($i = 1; $i <= 10; $i++) {
27
      $initiative = $parser->calculateInitiative($character);
28
      Assert::true($initiative >= 4);
29
      Assert::true($initiative <= 8);
30
    }
31
  }
32
}
33
34
$test = new InitiativeFormulaParserTest();
35
$test->run();
36
?>