Commit 95ab13f4 authored by Aleksandr Galkin's avatar Aleksandr Galkin
Browse files

Обновил code style

parent 72ab3797
<?php
require_once 'Figure.php';
require_once __DIR__ . '/Figure.php';
class Bishop extends Figure
{
public function __toString()
{
class Bishop extends Figure {
public function __toString() {
return $this->isBlack ? '♝' : '♗';
}
}
<?php
class Desk
{
private $figures = array();
class Desk {
private $figures = [];
public function __construct()
{
public function __construct() {
$this->figures['a'][1] = new Rook(false);
$this->figures['b'][1] = new Knight(false);
$this->figures['c'][1] = new Bishop(false);
......@@ -43,16 +41,15 @@ class Desk
$this->figures['h'][8] = new Rook(true);
}
public function move($move)
{
public function move($move) {
if (!preg_match('/^([a-h])(\d)-([a-h])(\d)$/', $move, $match)) {
throw new \Exception("Incorrect move");
}
$xFrom = $match[1];
$yFrom = $match[2];
$xTo = $match[3];
$yTo = $match[4];
$xTo = $match[3];
$yTo = $match[4];
if (isset($this->figures[$xFrom][$yFrom])) {
$this->figures[$xTo][$yTo] = $this->figures[$xFrom][$yFrom];
......@@ -60,8 +57,7 @@ class Desk
unset($this->figures[$xFrom][$yFrom]);
}
public function dump()
{
public function dump() {
for ($y = 8; $y >= 1; $y--) {
echo "$y ";
for ($x = 'a'; $x <= 'h'; $x++) {
......
<?php
class Figure
{
class Figure {
protected $isBlack;
public function __construct($isBlack)
{
public function __construct($isBlack) {
$this->isBlack = $isBlack;
}
/** @noinspection PhpToStringReturnInspection */
public function __toString()
{
public function __toString() {
throw new \Exception("Not implemented");
}
}
<?php
class King extends Figure
{
public function __toString()
{
class King extends Figure {
public function __toString() {
return $this->isBlack ? '♚' : '♔';
}
}
<?php
class Knight extends Figure
{
public function __toString()
{
class Knight extends Figure {
public function __toString() {
return $this->isBlack ? '♞' : '♘';
}
}
<?php
class Pawn extends Figure
{
public function __toString()
{
class Pawn extends Figure {
public function __toString() {
return $this->isBlack ? '♟' : '♙';
}
}
<?php
class Queen extends Figure
{
public function __toString()
{
class Queen extends Figure {
public function __toString() {
return $this->isBlack ? '♛' : '♕';
}
}
<?php
class Rook extends Figure
{
public function __toString()
{
class Rook extends Figure {
public function __toString() {
return $this->isBlack ? '♜' : '♖';
}
}
<?php
class Test extends \PHPUnit_Framework_TestCase
{
class Test extends \PHPUnit_Framework_TestCase {
/**
* @group rotation
* @group pawn
*/
public function testNoMoves()
{
public function testNoMoves() {
$this->runFile('tests/001-no-moves.test');
}
/**
* @group pawn
*/
public function testSimpleError()
{
public function testSimpleError() {
$this->runFile('tests/011-simple-error.test');
}
......@@ -23,16 +20,14 @@ class Test extends \PHPUnit_Framework_TestCase
* @group rotation
* @group pawn
*/
public function testSimple()
{
public function testSimple() {
$this->runFile('tests/012-simple-move.test');
}
/**
* @group rotation
*/
public function testColorRotationError()
{
public function testColorRotationError() {
$this->runFile('tests/013-color-rotation-error.test');
}
......@@ -40,8 +35,7 @@ class Test extends \PHPUnit_Framework_TestCase
* @group rotation
* @group pawn
*/
public function testColorRotationCorrect()
{
public function testColorRotationCorrect() {
$this->runFile('tests/014-color-rotation-correct.test');
}
......@@ -49,8 +43,7 @@ class Test extends \PHPUnit_Framework_TestCase
* @group rotation
* @group pawn
*/
public function testPawnMovesOneSquareVertically()
{
public function testPawnMovesOneSquareVertically() {
$this->runFile('tests/021-pawn-moves-one-square-vertically.test');
}
......@@ -58,16 +51,14 @@ class Test extends \PHPUnit_Framework_TestCase
* @group rotation
* @group pawn
*/
public function testPawnCanMoveTwoSquaresOnFirstMove()
{
public function testPawnCanMoveTwoSquaresOnFirstMove() {
$this->runFile('tests/022-pawn-can-move-two-squares-on-first-move.test');
}
/**
* @group pawn
*/
public function testPawnCanNotMoveDiagonally()
{
public function testPawnCanNotMoveDiagonally() {
$this->runFile('tests/023-pawn-can-not-move-diagonally.test');
}
......@@ -75,32 +66,28 @@ class Test extends \PHPUnit_Framework_TestCase
* @group rotation
* @group pawn
*/
public function testPawnCapturesDiagonally()
{
public function testPawnCapturesDiagonally() {
$this->runFile('tests/024-pawn-captures-diagonally.test');
}
/**
* @group pawn
*/
public function testPawnCanNotCaptureVertically()
{
public function testPawnCanNotCaptureVertically() {
$this->runFile('tests/025-pawn-can-not-capture-vertically.test');
}
/**
* @group pawn
*/
public function testPawnCanNotMoveFartherOneSquare()
{
public function testPawnCanNotMoveFartherOneSquare() {
$this->runFile('tests/026-pawn-can-not-move-farther-one-square.test');
}
/**
* @group pawn
*/
public function testPawnCanNotMoveAcrossFigure()
{
public function testPawnCanNotMoveAcrossFigure() {
$this->runFile('tests/027-pawn-can-not-move-across-figure.test');
}
......@@ -114,10 +101,9 @@ class Test extends \PHPUnit_Framework_TestCase
*
* @param string $file
*/
private function runFile($file)
{
$lines = file($file);
$moves = trim($lines[0]);
private function runFile($file) {
$lines = file($file);
$moves = trim($lines[0]);
$movesDesc = $moves ?: '(no moves)';
unset($lines[0]);
......@@ -131,7 +117,7 @@ class Test extends \PHPUnit_Framework_TestCase
$noColor = "\033[m";
}
$out = array();
$out = [];
exec('php chess.php ' . $moves, $out, $err);
if ($isCorrect) {
$this->assertEquals(0, $err, $redColor . "Moves are correct, but chess.php thinks there is an error:\n" . $movesDesc . $noColor . "\n");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment