You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.1 KiB
110 lines
2.1 KiB
<?php
|
|
|
|
namespace Coffee;
|
|
|
|
// This is not necessary, since it is bootstrapped but serves for debugging purposes
|
|
require __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
class MapTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
public function testDescribedByArray() {
|
|
$description = [
|
|
[1, 0],
|
|
[0, 1],
|
|
];
|
|
|
|
$map = new Map($description);
|
|
$this->assertEquals($description, $map->describedByArray());
|
|
}
|
|
|
|
public function testHeight() {
|
|
$description = [
|
|
[0, 1, 0, 1],
|
|
[1, 0, 0, 0],
|
|
[0, 0, 0, 1],
|
|
[0, 0, 0, 1]
|
|
];
|
|
|
|
$map = new Map($description);
|
|
$this->assertEquals(4, $map->getHeight());
|
|
}
|
|
|
|
public function testWidth() {
|
|
// Even the non-rectangular map descriptions are possible
|
|
$description = [
|
|
[0, 1, 0],
|
|
[1, 0, 0, 0],
|
|
[0, 0, 0,],
|
|
[0, 0, 0]
|
|
];
|
|
|
|
$map = new Map($description);
|
|
$this->assertEquals(4, $map->getWidth());
|
|
}
|
|
|
|
public function testValidPosition() {
|
|
$description = [
|
|
[0, 1, 0, 1],
|
|
[1, 0, 0, 0],
|
|
[0, 0, 0, 1],
|
|
[0, 0, 0, 1]
|
|
];
|
|
|
|
$map = new Map($description);
|
|
$this->assertTrue($map->isValidPosition(3, 0));
|
|
}
|
|
|
|
public function testInvalidPosition() {
|
|
$description = [
|
|
[0, 1, 0, 1],
|
|
[1, 0, 0, 0],
|
|
[0, 0, 0, 1],
|
|
[0, 0, 0, 1]
|
|
];
|
|
|
|
$map = new Map($description);
|
|
$this->assertFalse($map->isValidPosition(3, 4));
|
|
}
|
|
|
|
public function testVisitedPosition() {
|
|
$description = [
|
|
[0, 1, 0, 1],
|
|
[1, 0, 0, 0],
|
|
[0, 0, 0, 1],
|
|
[0, 0, 0, 1]
|
|
];
|
|
|
|
$map = new Map($description);
|
|
$map->visitPosition(0, 0);
|
|
$this->assertTrue($map->isVisitedPosition(0, 0));
|
|
}
|
|
|
|
public function testUnvisitedPosition() {
|
|
$description = [
|
|
[0, 1, 0, 1],
|
|
[1, 0, 0, 0],
|
|
[0, 0, 0, 1],
|
|
[0, 0, 0, 1]
|
|
];
|
|
|
|
$map = new Map($description);
|
|
$map->visitPosition(0, 0);
|
|
$this->assertFalse($map->isVisitedPosition(4, 0));
|
|
}
|
|
|
|
// public function testNextUnvisitedPosition() {
|
|
// $description = [
|
|
// [0, 1, 0, 1],
|
|
// [1, 0, 0, 0],
|
|
// [0, 0, 0, 1],
|
|
// [0, 0, 0, 1]
|
|
// ];
|
|
//
|
|
// $map = new Map($description);
|
|
// $map->visitPosition(0, 0);
|
|
// $map->visitPosition(0, 1);
|
|
//
|
|
// $position = new Position(0, 2);
|
|
// $this->assertEquals($position, $map->getNextUnvisitedPosition());
|
|
// }
|
|
}
|
|
|