DifferenceTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 46
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B itCalculatesBoundariesAndPercentages() 0 40 1
1
<?php
2
3
namespace Undemanding\Difference\Test;
4
5
use Undemanding\Difference\Image;
6
use Undemanding\Difference\Method\EuclideanDistance;
7
8
/**
9
 * @covers Undemanding\Difference\Difference
10
 */
11
class DifferenceTest extends Test
12
{
13
    /**
14
     * @test
15
     */
16
    public function itCalculatesBoundariesAndPercentages()
17
    {
18
        $image1 = new Image(__DIR__ . "/fixtures/fez-1.png");
19
        $image2 = new Image(__DIR__ . "/fixtures/fez-2.png"); // with text
20
        $image3 = new Image(__DIR__ . "/fixtures/fez-3.png"); // 1% transparent, with text
21
22
        $difference1 = $image1->difference($image2, new EuclideanDistance());
23
24
        $bitmap = $difference1->getBitmap();
25
26
        $this->assertInternalType("array", $bitmap);
27
        $this->assertEquals(300, count($bitmap));
28
29
        $boundary1 = [
30
            "left" => 122,
31
            "top" => 188,
32
            "width" => 138,
33
            "height" => 53,
34
        ];
35
36
        $this->assertEquals($boundary1, $difference1->boundary());
37
        $this->assertEquals(2.145, $difference1->percentage());
38
39
        $difference2 = $image1->difference($image3, new EuclideanDistance());
40
41
        $boundary2 = [
42
            "left" => 62,
43
            "top" => 0,
44
            "width" => 282,
45
            "height" => 286,
46
        ];
47
48
        $this->assertEquals($boundary2, $difference2->boundary());
49
        $this->assertEquals(34.1, round($difference2->percentage(), 1));
50
51
        $difference3 = $difference2->withScale(10)->withReducedStandardDeviation();
52
53
        $this->assertEquals($boundary1, $difference3->boundary());
54
        $this->assertEquals(2.0, round($difference3->percentage(), 1));
55
    }
56
}