Completed
Branch master (597d40)
by Douglas
02:41 queued 01:20
created

BoundaryConditionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testPositiveBoundaryConditions() 0 8 1
A getPassingBounds() 0 14 1
A testNegativeBoundaryConditions() 0 8 1
A getFailingBounds() 0 10 1
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