parent
eb8144ab09
commit
90009f29b4
@ -0,0 +1,140 @@ |
||||
<?php |
||||
|
||||
namespace Coffee; |
||||
|
||||
/** |
||||
* Class Position |
||||
* |
||||
* @package Coffee |
||||
*/ |
||||
class Position { |
||||
|
||||
/** |
||||
* @var int |
||||
*/ |
||||
private $column = 0; |
||||
/** |
||||
* @var int |
||||
*/ |
||||
private $row = 0; |
||||
|
||||
/** |
||||
* @param $row |
||||
* @param $column |
||||
*/ |
||||
function __construct($row, $column) { |
||||
$this->column = $column; |
||||
$this->row = $row; |
||||
} |
||||
|
||||
/** |
||||
* @return int |
||||
*/ |
||||
public function getColumn() { |
||||
return $this->column; |
||||
} |
||||
|
||||
/** |
||||
* @return int |
||||
*/ |
||||
public function getRow() { |
||||
return $this->row; |
||||
} |
||||
|
||||
/** |
||||
* @param Position $position |
||||
* @return bool |
||||
*/ |
||||
public function isTheSameColumn(Position $position) { |
||||
return $this->getColumn() == $position->getColumn(); |
||||
} |
||||
|
||||
/** |
||||
* @param Position $position |
||||
* @return bool |
||||
*/ |
||||
public function isTheSameRow(Position $position) { |
||||
return $this->getRow() == $position->getRow(); |
||||
} |
||||
|
||||
/** |
||||
* @param Position $position |
||||
* @return bool |
||||
*/ |
||||
public function isTheSamePosition(Position $position) { |
||||
return $this->isTheSameColumn($position) && $this->isTheSameRow($position); |
||||
} |
||||
|
||||
/** |
||||
* @return Position |
||||
*/ |
||||
public function getNorthEastPosition() { |
||||
return new Position($this->getRow() - 1, $this->getColumn() + 1); |
||||
} |
||||
|
||||
/** |
||||
* @return Position |
||||
*/ |
||||
public function getEastPosition() { |
||||
return new Position($this->getRow(), $this->getColumn() + 1); |
||||
} |
||||
|
||||
/** |
||||
* @return Position |
||||
*/ |
||||
public function getSouthEastPosition() { |
||||
return new Position($this->getRow() + 1, $this->getColumn() + 1); |
||||
} |
||||
|
||||
/** |
||||
* @return Position |
||||
*/ |
||||
public function getSouthPosition() { |
||||
return new Position($this->getRow() + 1, $this->getColumn()); |
||||
} |
||||
|
||||
/** |
||||
* @return Position |
||||
*/ |
||||
public function getSouthWestPosition() { |
||||
return new Position($this->getRow() + 1, $this->getColumn() - 1); |
||||
} |
||||
|
||||
/** |
||||
* @return Position |
||||
*/ |
||||
public function getWestPosition() { |
||||
return new Position($this->getRow(), $this->getColumn() - 1); |
||||
} |
||||
|
||||
/** |
||||
* @return Position |
||||
*/ |
||||
public function getNorthWestPosition() { |
||||
return new Position($this->getRow() - 1, $this->getColumn() - 1); |
||||
} |
||||
|
||||
/** |
||||
* @return Position |
||||
*/ |
||||
public function getNorthPosition() { |
||||
return new Position($this->getRow() - 1, $this->getColumn()); |
||||
} |
||||
|
||||
/** |
||||
* @return array Neighbors of position from NE to N; CW direction |
||||
*/ |
||||
public function getNeighbors() { |
||||
return [ |
||||
$this->getNorthEastPosition(), |
||||
$this->getEastPosition(), |
||||
$this->getSouthEastPosition(), |
||||
$this->getSouthPosition(), |
||||
$this->getSouthWestPosition(), |
||||
$this->getWestPosition(), |
||||
$this->getNorthWestPosition(), |
||||
$this->getNorthPosition(), |
||||
]; |
||||
} |
||||
|
||||
} |
@ -1,140 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace Coffee; |
||||
|
||||
/** |
||||
* Class Tile |
||||
* |
||||
* @package Coffee |
||||
*/ |
||||
class Tile { |
||||
|
||||
/** |
||||
* @var int |
||||
*/ |
||||
private $column = 0; |
||||
/** |
||||
* @var int |
||||
*/ |
||||
private $row = 0; |
||||
|
||||
/** |
||||
* @param $row |
||||
* @param $column |
||||
*/ |
||||
function __construct($row, $column) { |
||||
$this->column = $column; |
||||
$this->row = $row; |
||||
} |
||||
|
||||
/** |
||||
* @return int |
||||
*/ |
||||
public function getColumn() { |
||||
return $this->column; |
||||
} |
||||
|
||||
/** |
||||
* @return int |
||||
*/ |
||||
public function getRow() { |
||||
return $this->row; |
||||
} |
||||
|
||||
/** |
||||
* @param Tile $tile |
||||
* @return bool |
||||
*/ |
||||
public function isTheSameColumn(Tile $tile) { |
||||
return $this->getColumn() == $tile->getColumn(); |
||||
} |
||||
|
||||
/** |
||||
* @param Tile $tile |
||||
* @return bool |
||||
*/ |
||||
public function isTheSameRow(Tile $tile) { |
||||
return $this->getRow() == $tile->getRow(); |
||||
} |
||||
|
||||
/** |
||||
* @param Tile $tile |
||||
* @return bool |
||||
*/ |
||||
public function isTheSameTile(Tile $tile) { |
||||
return $this->isTheSameColumn($tile) && $this->isTheSameRow($tile); |
||||
} |
||||
|
||||
/** |
||||
* @return Tile |
||||
*/ |
||||
public function getNorthEastTile() { |
||||
return new Tile($this->getRow() - 1, $this->getColumn() + 1); |
||||
} |
||||
|
||||
/** |
||||
* @return Tile |
||||
*/ |
||||
public function getEastTile() { |
||||
return new Tile($this->getRow(), $this->getColumn() + 1); |
||||
} |
||||
|
||||
/** |
||||
* @return Tile |
||||
*/ |
||||
public function getSouthEastTile() { |
||||
return new Tile($this->getRow() + 1, $this->getColumn() + 1); |
||||
} |
||||
|
||||
/** |
||||
* @return Tile |
||||
*/ |
||||
public function getSouthTile() { |
||||
return new Tile($this->getRow() + 1, $this->getColumn()); |
||||
} |
||||
|
||||
/** |
||||
* @return Tile |
||||
*/ |
||||
public function getSouthWestTile() { |
||||
return new Tile($this->getRow() + 1, $this->getColumn() - 1); |
||||
} |
||||
|
||||
/** |
||||
* @return Tile |
||||
*/ |
||||
public function getWestTile() { |
||||
return new Tile($this->getRow(), $this->getColumn() - 1); |
||||
} |
||||
|
||||
/** |
||||
* @return Tile |
||||
*/ |
||||
public function getNorthWestTile() { |
||||
return new Tile($this->getRow() - 1, $this->getColumn() - 1); |
||||
} |
||||
|
||||
/** |
||||
* @return Tile |
||||
*/ |
||||
public function getNorthTile() { |
||||
return new Tile($this->getRow() - 1, $this->getColumn()); |
||||
} |
||||
|
||||
/** |
||||
* @return array Neighbors of tile from NE to N; CW direction |
||||
*/ |
||||
public function getNeighbors() { |
||||
return [ |
||||
$this->getNorthEastTile(), |
||||
$this->getEastTile(), |
||||
$this->getSouthEastTile(), |
||||
$this->getSouthTile(), |
||||
$this->getSouthWestTile(), |
||||
$this->getWestTile(), |
||||
$this->getNorthWestTile(), |
||||
$this->getNorthTile(), |
||||
]; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,110 @@ |
||||
<?php |
||||
|
||||
namespace Coffee; |
||||
|
||||
// This is not necessary, since it is bootstrapped but serves for debugging purposes |
||||
require __DIR__ . '/../vendor/autoload.php'; |
||||
|
||||
class PositionTest extends \PHPUnit_Framework_TestCase { |
||||
|
||||
public function testTheSameX() { |
||||
$positionA = new Position(2, 2); |
||||
$positionB = new Position(2, 2); |
||||
|
||||
$this->assertTrue($positionA->isTheSameColumn($positionB)); |
||||
} |
||||
|
||||
public function testTheSameY() { |
||||
$positionA = new Position(2, 2); |
||||
$positionB = new Position(2, 2); |
||||
|
||||
$this->assertTrue($positionA->isTheSameRow($positionB)); |
||||
} |
||||
|
||||
public function testTheSamePosition() { |
||||
$positionA = new Position(2, 2); |
||||
$positionB = new Position(2, 2); |
||||
|
||||
$this->assertTrue($positionA->isTheSamePosition($positionB)); |
||||
} |
||||
|
||||
public function testNorthEastPosition() { |
||||
$position = new Position(2, 2); |
||||
$northEastPositionA = $position->getNorthEastPosition(); |
||||
$northEastPositionB = new Position(1, 3); |
||||
|
||||
$this->assertTrue($northEastPositionA->isTheSamePosition($northEastPositionB)); |
||||
} |
||||
|
||||
public function testEastPosition() { |
||||
$position = new Position(2, 2); |
||||
$northPositionA = $position->getEastPosition(); |
||||
$NorthPositionB = new Position(2, 3); |
||||
|
||||
$this->assertTrue($northPositionA->isTheSamePosition($NorthPositionB)); |
||||
} |
||||
|
||||
public function testSouthEastPosition() { |
||||
$position = new Position(2, 2); |
||||
$northPositionA = $position->getSouthEastPosition(); |
||||
$NorthPositionB = new Position(3, 3); |
||||
|
||||
$this->assertTrue($northPositionA->isTheSamePosition($NorthPositionB)); |
||||
} |
||||
|
||||
public function testSouthPosition() { |
||||
$position = new Position(2, 2); |
||||
$northPositionA = $position->getSouthPosition(); |
||||
$NorthPositionB = new Position(3, 2); |
||||
|
||||
$this->assertTrue($northPositionA->isTheSamePosition($NorthPositionB)); |
||||
} |
||||
|
||||
public function testsSouthWestPosition() { |
||||
$position = new Position(2, 2); |
||||
$northPositionA = $position->getSouthWestPosition(); |
||||
$NorthPositionB = new Position(3, 1); |
||||
|
||||
$this->assertTrue($northPositionA->isTheSamePosition($NorthPositionB)); |
||||
} |
||||
|
||||
public function testWestPosition() { |
||||
$position = new Position(2, 2); |
||||
$northPositionA = $position->getWestPosition(); |
||||
$NorthPositionB = new Position(2, 1); |
||||
|
||||
$this->assertTrue($northPositionA->isTheSamePosition($NorthPositionB)); |
||||
} |
||||
|
||||
public function testNorthWestPosition() { |
||||
$position = new Position(2, 2); |
||||
$northPositionA = $position->getNorthWestPosition(); |
||||
$NorthPositionB = new Position(1, 1); |
||||
|
||||
$this->assertTrue($northPositionA->isTheSamePosition($NorthPositionB)); |
||||
} |
||||
|
||||
public function testNorthPosition() { |
||||
$position = new Position(2, 2); |
||||
$northPositionA = $position->getNorthPosition(); |
||||
$NorthPositionB = new Position(1, 2); |
||||
|
||||
$this->assertTrue($northPositionA->isTheSamePosition($NorthPositionB)); |
||||
} |
||||
|
||||
public function testNeighbors() { |
||||
$position = new Position(2, 2); |
||||
$neighbours = [ |
||||
new Position(1, 3), |
||||
new Position(2, 3), |
||||
new Position(3, 3), |
||||
new Position(3, 2), |
||||
new Position(3, 1), |
||||
new Position(2, 1), |
||||
new Position(1, 1), |
||||
new Position(1, 2), |
||||
]; |
||||
|
||||
$this->assertEquals($neighbours, $position->getNeighbors()); |
||||
} |
||||
} |
@ -1,110 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace Coffee; |
||||
|
||||
// This is not necessary, sice it is bootstrapped but serves for debugging purposes |
||||
require __DIR__ . '/../vendor/autoload.php'; |
||||
|
||||
class TileTest extends \PHPUnit_Framework_TestCase { |
||||
|
||||
public function testTheSameX() { |
||||
$tileA = new Tile(2, 2); |
||||
$tileB = new Tile(2, 2); |
||||
|
||||
$this->assertTrue($tileA->isTheSameColumn($tileB)); |
||||
} |
||||
|
||||
public function testTheSameY() { |
||||
$tileA = new Tile(2, 2); |
||||
$tileB = new Tile(2, 2); |
||||
|
||||
$this->assertTrue($tileA->isTheSameRow($tileB)); |
||||
} |
||||
|
||||
public function testTheSameTile() { |
||||
$tileA = new Tile(2, 2); |
||||
$tileB = new Tile(2, 2); |
||||
|
||||
$this->assertTrue($tileA->isTheSameTile($tileB)); |
||||
} |
||||
|
||||
public function testNorthEastTile() { |
||||
$tile = new Tile(2, 2); |
||||
$northEastTileA = $tile->getNorthEastTile(); |
||||
$northEastTileB = new Tile(1, 3); |
||||
|
||||
$this->assertTrue($northEastTileA->isTheSameTile($northEastTileB)); |
||||
} |
||||
|
||||
public function testEastTile() { |
||||
$tile = new Tile(2, 2); |
||||
$northTileA = $tile->getEastTile(); |
||||
$NorthTileB = new Tile(2, 3); |
||||
|
||||
$this->assertTrue($northTileA->isTheSameTile($NorthTileB)); |
||||
} |
||||
|
||||
public function testSouthEastTile() { |
||||
$tile = new Tile(2, 2); |
||||
$northTileA = $tile->getSouthEastTile(); |
||||
$NorthTileB = new Tile(3, 3); |
||||
|
||||
$this->assertTrue($northTileA->isTheSameTile($NorthTileB)); |
||||
} |
||||
|
||||
public function testSouthTile() { |
||||
$tile = new Tile(2, 2); |
||||
$northTileA = $tile->getSouthTile(); |
||||
$NorthTileB = new Tile(3, 2); |
||||
|
||||
$this->assertTrue($northTileA->isTheSameTile($NorthTileB)); |
||||
} |
||||
|
||||
public function testsSouthWestTile() { |
||||
$tile = new Tile(2, 2); |
||||
$northTileA = $tile->getSouthWestTile(); |
||||
$NorthTileB = new Tile(3, 1); |
||||
|
||||
$this->assertTrue($northTileA->isTheSameTile($NorthTileB)); |
||||
} |
||||
|
||||
public function testWestTile() { |
||||
$tile = new Tile(2, 2); |
||||
$northTileA = $tile->getWestTile(); |
||||
$NorthTileB = new Tile(2, 1); |
||||
|
||||
$this->assertTrue($northTileA->isTheSameTile($NorthTileB)); |
||||
} |
||||
|
||||
public function testNorthWestTile() { |
||||
$tile = new Tile(2, 2); |
||||
$northTileA = $tile->getNorthWestTile(); |
||||
$NorthTileB = new Tile(1, 1); |
||||
|
||||
$this->assertTrue($northTileA->isTheSameTile($NorthTileB)); |
||||
} |
||||
|
||||
public function testNorthTile() { |
||||
$tile = new Tile(2, 2); |
||||
$northTileA = $tile->getNorthTile(); |
||||
$NorthTileB = new Tile(1, 2); |
||||
|
||||
$this->assertTrue($northTileA->isTheSameTile($NorthTileB)); |
||||
} |
||||
|
||||
public function testNeighbors() { |
||||
$tile = new Tile(2, 2); |
||||
$neighbours = [ |
||||
new Tile(1, 3), |
||||
new Tile(2, 3), |
||||
new Tile(3, 3), |
||||
new Tile(3, 2), |
||||
new Tile(3, 1), |
||||
new Tile(2, 1), |
||||
new Tile(1, 1), |
||||
new Tile(1, 2), |
||||
]; |
||||
|
||||
$this->assertEquals($neighbours, $tile->getNeighbors()); |
||||
} |
||||
} |
Loading…
Reference in new issue