|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
This file is part of WideImage. |
|
4
|
|
|
|
|
5
|
|
|
WideImage is free software; you can redistribute it and/or modify |
|
6
|
|
|
it under the terms of the GNU Lesser General Public License as published by |
|
7
|
|
|
the Free Software Foundation; either version 2.1 of the License, or |
|
8
|
|
|
(at your option) any later version. |
|
9
|
|
|
|
|
10
|
|
|
WideImage is distributed in the hope that it will be useful, |
|
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
GNU Lesser General Public License for more details. |
|
14
|
|
|
|
|
15
|
|
|
You should have received a copy of the GNU Lesser General Public License |
|
16
|
|
|
along with WideImage; if not, write to the Free Software |
|
17
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
18
|
|
|
**/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Test\WideImage; |
|
21
|
|
|
|
|
22
|
|
|
use WideImage\Coordinate; |
|
23
|
|
|
use Test\WideImage_TestCase; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @package Tests |
|
27
|
|
|
*/ |
|
28
|
|
|
class CoordinateTest extends WideImage_TestCase |
|
29
|
|
|
{ |
|
30
|
|
|
public function testEvaluate() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->assertSame(400, Coordinate::evaluate('+200%', 200)); |
|
33
|
|
|
$this->assertSame(-1, Coordinate::evaluate('-1', 200)); |
|
34
|
|
|
$this->assertSame(10, Coordinate::evaluate('+10', 200)); |
|
35
|
|
|
$this->assertSame(40, Coordinate::evaluate('+20%', 200)); |
|
36
|
|
|
$this->assertSame(-11, Coordinate::evaluate('-11.23', 200)); |
|
37
|
|
|
$this->assertSame(-30, Coordinate::evaluate('-15%', 200)); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testFix() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->assertSame(10, Coordinate::fix('10%', 100)); |
|
43
|
|
|
$this->assertSame(10, Coordinate::fix('10', 100)); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertSame(-10, Coordinate::fix('-10%', 100)); |
|
46
|
|
|
$this->assertSame(-1, Coordinate::fix('-1', 100)); |
|
47
|
|
|
$this->assertSame(-50, Coordinate::fix('-50%', 100)); |
|
48
|
|
|
$this->assertSame(-100, Coordinate::fix('-100%', 100)); |
|
49
|
|
|
$this->assertSame(-1, Coordinate::fix('-5%', 20)); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertSame(300, Coordinate::fix('150.12%', 200)); |
|
52
|
|
|
$this->assertSame(150, Coordinate::fix('150', 200)); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertSame(100, Coordinate::fix('100%-50%', 200)); |
|
55
|
|
|
$this->assertSame(200, Coordinate::fix('100%', 200)); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertSame(130, Coordinate::fix('50% -20', 300)); |
|
58
|
|
|
$this->assertSame(12, Coordinate::fix(' 12 - 0', 300)); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertSame(15, Coordinate::fix('50%', 30)); |
|
61
|
|
|
$this->assertSame(15, Coordinate::fix('50%-0', 30)); |
|
62
|
|
|
$this->assertSame(15, Coordinate::fix('50%+0', 30)); |
|
63
|
|
|
$this->assertSame(0, Coordinate::fix(' - 50% + 50%', 30)); |
|
64
|
|
|
$this->assertSame(30, Coordinate::fix(' 50% + 49.6666%', 30)); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testAlign() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->assertSame(0, Coordinate::fix('left', 300, 120)); |
|
70
|
|
|
$this->assertSame(90, Coordinate::fix('center', 300, 120)); |
|
71
|
|
|
$this->assertSame(180, Coordinate::fix('right', 300, 120)); |
|
72
|
|
|
$this->assertSame(0, Coordinate::fix('top', 300, 120)); |
|
73
|
|
|
$this->assertSame(90, Coordinate::fix('middle', 300, 120)); |
|
74
|
|
|
$this->assertSame(180, Coordinate::fix('bottom', 300, 120)); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertSame(200, Coordinate::fix('bottom+20', 300, 120)); |
|
77
|
|
|
$this->assertSame(178, Coordinate::fix('-2 + right', 300, 120)); |
|
78
|
|
|
$this->assertSame(90, Coordinate::fix('right - center', 300, 120)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testAlignWithoutSecondaryCoordinate() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->assertSame(0, Coordinate::fix('left', 300)); |
|
84
|
|
|
$this->assertSame(150, Coordinate::fix('center', 300)); |
|
85
|
|
|
$this->assertSame(300, Coordinate::fix('right', 300)); |
|
86
|
|
|
$this->assertSame(0, Coordinate::fix('top', 300)); |
|
87
|
|
|
$this->assertSame(150, Coordinate::fix('middle', 300)); |
|
88
|
|
|
$this->assertSame(300, Coordinate::fix('bottom', 300)); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertSame(320, Coordinate::fix('bottom+20', 300)); |
|
91
|
|
|
$this->assertSame(280, Coordinate::fix('-20 + right', 300)); |
|
92
|
|
|
$this->assertSame(150, Coordinate::fix('right - center', 300)); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function testMultipleOperands() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->assertSame(6, Coordinate::fix('100%-100+1 + 5', 100)); |
|
98
|
|
|
$this->assertSame(1, Coordinate::fix('right +1- 100 - 50%', 200)); |
|
99
|
|
|
$this->assertSame(200, Coordinate::fix('-right+right +100%', 200)); |
|
100
|
|
|
$this->assertSame(90, Coordinate::fix('100--++++-10', 200)); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @expectedException WideImage\Exception\InvalidCoordinateException |
|
105
|
|
|
*/ |
|
106
|
|
|
public function testInvalidSyntaxEndsWithOperator() |
|
107
|
|
|
{ |
|
108
|
|
|
Coordinate::fix('5+2+', 10); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|