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
|
|
|
} |