1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cgi\Calc\Tests\Field; |
4
|
|
|
|
5
|
|
|
use Cgi\Calc\Field\RectangularFromTwoPoints; |
6
|
|
|
use Cgi\Calc\Point; |
7
|
|
|
|
8
|
|
|
class RectangularFromTwoPointsTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
public function count_provider() |
11
|
|
|
{ |
12
|
|
|
return [ |
13
|
|
|
[new Point(1,1), new Point(1, 1), 1], |
14
|
|
|
[new Point(1,1), new Point(2, 2), 4], |
15
|
|
|
[new Point(1,1), new Point(3, 3), 9], |
16
|
|
|
|
17
|
|
|
[new Point(1,1), new Point(4, 3), 12], |
18
|
|
|
]; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @dataProvider count_provider |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
public function test_count(Point $lowerLeft, Point $upperRight, $expectedCount) |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$producer = new RectangularFromTwoPoints($lowerLeft, $upperRight); |
27
|
|
|
$field = $producer->produce(); |
28
|
|
|
|
29
|
|
|
$actualCount = $field->count(); |
30
|
|
|
static::assertEquals($expectedCount, $actualCount); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function point_belongs_to_rectangular_provider() |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
|
|
[new Point(1,1), new Point(4, 3), new Point(1,1), true], |
37
|
|
|
[new Point(1,1), new Point(4, 3), new Point(2,2), true], |
38
|
|
|
[new Point(1,1), new Point(4, 3), new Point(3,3), true], |
39
|
|
|
[new Point(1,1), new Point(4, 3), new Point(4,3), true], |
40
|
|
|
|
41
|
|
|
[new Point(1,1), new Point(4, 3), new Point(0,0), false], |
42
|
|
|
[new Point(1,1), new Point(4, 3), new Point(0,4), false], |
43
|
|
|
[new Point(1,1), new Point(4, 3), new Point(4,4), false], |
44
|
|
|
[new Point(1,1), new Point(4, 3), new Point(4,0), false], |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @dataProvider point_belongs_to_rectangular_provider |
50
|
|
|
*/ |
51
|
|
View Code Duplication |
public function test_point_belongs_to_rectangular(Point $lowerLeft, Point $upperRight, Point $testPoint, $expectedIn) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$producer = new RectangularFromTwoPoints($lowerLeft, $upperRight); |
54
|
|
|
$field = $producer->produce(); |
55
|
|
|
|
56
|
|
|
$actualIn = $field->contains($testPoint); |
57
|
|
|
static::assertEquals($expectedIn, $actualIn); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.