tests unitaires
parent
b2c96795f9
commit
02457de1fe
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
class Coords{
|
||||
public $x;
|
||||
public $y;
|
||||
public function __construct(int $x = 0, int $y = 0) {
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
return $this->x.",".$this->y;
|
||||
}
|
||||
public function addDirection(Direction $dir){
|
||||
return new Coords(
|
||||
$this->x + $dir->deltaX,
|
||||
$this->y + $dir->deltaY
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
require_once '../Coords.php';
|
||||
require_once '../Direction.php';
|
||||
|
||||
class CoordsTest extends TestCase {
|
||||
|
||||
|
||||
public function testCirculaire(){
|
||||
$startCoord = new Coords(15,3);
|
||||
$endCoord = $startCoord->addDirection(Direction::make('x+'))
|
||||
->addDirection(Direction::make('y-'))
|
||||
->addDirection(Direction::make('x-'))
|
||||
->addDirection(Direction::make('y+'));
|
||||
|
||||
|
||||
|
||||
$this->assertTrue($endCoord == $startCoord);
|
||||
}
|
||||
public function testIsDifferent(){
|
||||
$startCoord = new Coords(15,3);
|
||||
$endCoord = $startCoord->addDirection(Direction::make('x+'));
|
||||
fwrite(STDERR, $startCoord ."\n");
|
||||
fwrite(STDERR, $endCoord ."\n");
|
||||
$this->assertFalse($endCoord == $startCoord);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue