Completed
Push — master ( af3c22...fbabbd )
by Douglas
01:45
created

RobotTest::robotCanMove()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
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\Robot;
11
12
use PHPUnit\Framework\TestCase;
13
use Reith\ToyRobot\Domain\Space\Table;
14
15
class RobotTest extends TestCase
16
{
17
    public static function testCreatingARobot()
18
    {
19
        // This is an example of a 5x5 table
20
        $table = Table::create(5);
21
22
        // To create (or reset) a robot it must be placed in a space.
23
        // Default placement is 0,0 (for 2 dimensions)
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
24
        $robot = $table->placeRobot();
25
26
        self::assertInstanceOf(Robot::class, $robot);
27
    }
28
29
    /**
30
     * @test
31
     */
32
    public static function robotCanMove()
33
    {
34
        $table = Table::create(5);
35
        $robot = $table->placeRobot();
36
37
        // From origin, 0,0, robot can move northward
38
        $place = $robot->moveNorthward()->getPlacement();
39
40
        // Now it should be at 0,1
41
        self::assertEquals([0, 1], $place->getVector());
42
43
        $place = $robot->moveSouthward()->getPlacement();
44
45
        // Now it should be back at origin
46
        self::assertEquals([0, 0], $place->getVector());
47
48
        // Let's get it dancing
49
        $place = $robot
50
            ->moveEastward()
51
            ->moveEastward()
52
            ->moveNorthward()
53
            ->moveNorthward()
54
            ->moveWestward()
55
            ->moveNorthward()
56
            ->getPlacement()
57
        ;
58
59
        self::assertEquals([1, 3], $place->getVector());
60
    }
61
62
    /**
63
     * @test
64
     * @expectedException \Assert\AssertionFailedException
65
     */
66
    public static function robotCannotStartWithABadDirection()
67
    {
68
        $table = Table::create(3);
0 ignored issues
show
Unused Code introduced by
$table is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
69
70
        Robot::create(
71
            Table::create(4),
72
            Place::create([0, 1]),
73
            'U'
74
        );
75
    }
76
77
    /**
78
     * @test
79
     * @expectedException \Reith\ToyRobot\Domain\Space\Exception\BoundaryTestException
80
     */
81
    public static function robotCannotFallOffTheSouthSide()
82
    {
83
        $table = Table::create(5);
84
        $robot = $table->placeRobot();
85
86
        $robot->moveSouthward();
87
    }
88
89
    /**
90
     * @test
91
     * @expectedException \Reith\ToyRobot\Domain\Space\Exception\BoundaryTestException
92
     */
93
    public static function robotCannotFallOffTheWestSide()
94
    {
95
        $table = Table::create(5);
96
        $robot = $table->placeRobot();
97
98
        $robot->moveWestward();
99
    }
100
101
    /**
102
     * @test
103
     * @expectedException \Reith\ToyRobot\Domain\Space\Exception\BoundaryTestException
104
     */
105
    public static function robotCannotFallOffTheNorthSide()
106
    {
107
        // Smaller 3 x 3 table
108
        $table = Table::create(3);
109
        $robot = $table->placeRobot();
110
111
        $robot
112
            ->moveNorthward()
113
            ->moveNorthward()
114
            ->moveNorthward()
115
        ;
116
    }
117
}
118