RandomSuccessCalculatorTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 24
c 1
b 0
f 0
dl 0
loc 44
rs 10

4 Methods

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