CoordinateGeometryTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 70
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testAxisLength() 0 9 1
A testScaleSize() 0 20 1
A testAspectRatio() 0 5 1
A testIsInside() 0 10 1
A testRoundAll() 0 12 1
1
<?php
2
/**
3
 * This file is part of the IrishDan\ResponsiveImageBundle package.
4
 *
5
 * (c) Daniel Byrne <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source
8
 * code.
9
 */
10
11
namespace IrishDan\ResponsiveImageBundle\Tests\ImageProcessing;
12
13
use IrishDan\ResponsiveImageBundle\ImageProcessing\CoordinateGeometry;
14
15
class CoordinateGeometryTest extends \PHPUnit_Framework_TestCase
16
{
17
    protected $geometry;
18
19
    public function setUp()
20
    {
21
        $this->geometry = new CoordinateGeometry(10, 20, 90, 100);
22
    }
23
24
    public function testAxisLength()
25
    {
26
        $this->assertEquals(80, $this->geometry->axisLength('x'));
27
        $this->assertEquals(80, $this->geometry->axisLength('y'));
28
29
        $this->geometry->setPoints(283, 397, 991, 1289);
30
        $this->assertEquals(708, $this->geometry->axisLength('x'));
31
        $this->assertEquals(892, $this->geometry->axisLength('y'));
32
    }
33
34
    public function testScaleSize()
35
    {
36
        // Scale with same proportions
37
        $scaledSize = $this->geometry->scaleSize(40, 40);
38
39
        $this->assertEquals(40, $scaledSize['width']);
40
        $this->assertEquals(40, $scaledSize['height']);
41
42
        // Scale with longer width
43
        $scaledSize = $this->geometry->scaleSize(80, 40);
44
45
        $this->assertEquals(40, $scaledSize['width']);
46
        $this->assertEquals(40, $scaledSize['height']);
47
48
        // Scale with longer height
49
        $scaledSize = $this->geometry->scaleSize(40, 80);
50
51
        $this->assertEquals(40, $scaledSize['width']);
52
        $this->assertEquals(40, $scaledSize['height']);
53
    }
54
55
    public function testAspectRatio()
56
    {
57
        $this->assertEquals(1, $this->geometry->aspectRatio());
58
        $this->assertEquals(2, $this->geometry->aspectRatio(50, 100));
59
    }
60
61
    public function testIsInside()
62
    {
63
        $this->assertTrue($this->geometry->isInside(11, 21, 89, 99));
64
        $this->assertTrue($this->geometry->isInside(10, 20, 90, 100));
65
        // One coordinate falls outside
66
        $this->assertFalse($this->geometry->isInside(9, 21, 89, 99));
67
        $this->assertFalse($this->geometry->isInside(11, 19, 89, 99));
68
        $this->assertFalse($this->geometry->isInside(11, 21, 91, 99));
69
        $this->assertFalse($this->geometry->isInside(11, 21, 89, 101));
70
    }
71
72
    public function testRoundAll()
73
    {
74
        $data = [
75
            'key1' => 3.870000007,
76
            'key2' => .9000099993,
77
        ];
78
79
        $rounded = $this->geometry->roundAll($data);
80
81
        $this->assertEquals(4, $rounded['key1']);
82
        $this->assertEquals(1, $rounded['key2']);
83
    }
84
}