RandomSuccessCalculatorTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 24
dl 0
loc 39
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testHasHit() 0 18 2
A testHasHealed() 0 3 1
A generateCharacter() 0 6 1
A setUp() 0 2 1
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 RandomSuccessCalculatorTest extends \Tester\TestCase {
15
  protected RandomSuccessCalculator $calculator;
16
  
17
  protected function setUp() {
18
    $this->calculator = new RandomSuccessCalculator();
19
  }
20
  
21
  protected function generateCharacter(int $id): Character {
22
    $stats = [
23
      "id" => $id, "name" => "Player $id", "level" => 1, "initiativeFormula" => "1d2+DEX/4", "strength" => 10,
24
      "dexterity" => 10, "constitution" => 10, "intelligence" => 10, "charisma" => 10
25
    ];
26
    return new Character($stats);
27
  }
28
  
29
  public function testHasHit(): void {
30
    $character1 = $this->generateCharacter(1);
31
    $character2 = $this->generateCharacter(2);
32
    Assert::type("bool", $this->calculator->hasHit($character1, $character2));
33
    $skillData = [
34
      "id" => 1, "name" => "Skill Attack", "baseDamage" => "120%", "damageGrowth" => "2%", "levels" => 5,
35
      "target" => SkillAttack::TARGET_SINGLE, "strikes" => 1, "hitRate" => "100%",
36
    ];
37
    $skill = new SkillAttack($skillData);
38
    $characterSkill = new CharacterAttackSkill($skill, 1);
39
    Assert::type("bool", $this->calculator->hasHit($character1, $character2, $characterSkill));
40
    $character2->effects[] = new CharacterEffect([
41
      "id" => "stunEffect", "type" => SkillSpecial::TYPE_STUN, "valueAbsolute" => false,
42
      "duration" => CharacterEffect::DURATION_COMBAT,
43
    ]);
44
    for($i = 1; $i <= 10; $i++) {
45
      Assert::true($this->calculator->hasHit($character1, $character2));
46
      Assert::true($this->calculator->hasHit($character1, $character2, $characterSkill));
47
    }
48
  }
49
  
50
  public function testHasHealed(): void {
51
    $character1 = $this->generateCharacter(1);
52
    Assert::type("bool", $this->calculator->hasHealed($character1));
53
  }
54
}
55
56
$test = new RandomSuccessCalculatorTest();
57
$test->run();
58
?>