1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* (c) 2018 Douglas Reith. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Reith\ToyRobot\Domain\Space; |
11
|
|
|
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
class BoundaryConditionTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @dataProvider getPassingBounds |
18
|
|
|
*/ |
19
|
|
|
public static function testPositiveBoundaryConditions($bounds, $value) |
20
|
|
|
{ |
21
|
|
|
// For a 10 x 10 space, for example |
22
|
|
|
$condition = BoundaryCondition::create($bounds); |
23
|
|
|
|
24
|
|
|
self::assertInstanceOf(BoundaryCondition::class, $condition); |
25
|
|
|
self::assertTrue($condition->test($value)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getPassingBounds(): array |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
|
|
// 10 would be part of a 10 x 10 space, 8 falls within it |
32
|
|
|
// bounds, value to check |
33
|
|
|
[10, 8], |
34
|
|
|
[10, 0], |
35
|
|
|
[10, 9], |
36
|
|
|
[10, 1], |
37
|
|
|
[100, 99], |
38
|
|
|
[1, 0], |
39
|
|
|
[23, 16], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @dataProvider getFailingBounds |
45
|
|
|
* @expectedException \Reith\ToyRobot\Domain\Space\Exception\BoundaryTestException |
46
|
|
|
*/ |
47
|
|
|
public static function testNegativeBoundaryConditions($bounds, $value) |
48
|
|
|
{ |
49
|
|
|
// For a 10 x 10 space, for example |
50
|
|
|
$condition = BoundaryCondition::create($bounds); |
51
|
|
|
|
52
|
|
|
self::assertInstanceOf(BoundaryCondition::class, $condition); |
53
|
|
|
self::assertTrue($condition->test($value)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getFailingBounds(): array |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
[10, 10], |
60
|
|
|
[10, -1], |
61
|
|
|
[100, 1000000], |
62
|
|
|
[1, 1], |
63
|
|
|
[1, -100], |
64
|
|
|
]; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|