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

PlaceTest::testCoordinates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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\Robot;
11
12
use PHPUnit\Framework\TestCase;
13
14
class PlaceTest extends TestCase
15
{
16
    public static function testCreatingAPlace()
17
    {
18
        // Create a placement at 3,2
19
        $place = Place::create([3, 2]);
20
21
        self::assertInstanceOf(Place::class, $place);
22
    }
23
24
    /**
25
     * @dataProvider provideBadCoordinates
26
     * @expectedException \Assert\AssertionFailedException
27
     *
28
     * @param array $badCoords
29
     */
30
    public static function testCoordinates(array $badCoords)
31
    {
32
        Place::create($badCoords);
33
    }
34
35
    public static function provideBadCoordinates(): array
36
    {
37
        return [
38
            [[]], // empty
39
            [['a']], // chars
40
            [[3, 3, 3, 4.5]], // float
41
        ];
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public static function canMapPlaceCoords()
48
    {
49
        $place = Place::create([1, 2, 3]);
50
        $result = $place->map(function ($coord) {
51
            return $coord * 2;
52
        });
53
54
        self::assertEquals([2, 4, 6], $result);
55
    }
56
}
57