You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
use PHPUnit\Framework\TestCase;
|
|
require_once '../Direction.php';
|
|
|
|
class Directiontest extends TestCase {
|
|
public function invalidStrings() {
|
|
return array(
|
|
array('jhgjhg'),
|
|
array('X+'),
|
|
array(4)
|
|
);
|
|
}
|
|
/**
|
|
* @dataProvider invalidStrings
|
|
* @expectedException invalidDirectionException
|
|
*/
|
|
public function testRejectInvalidString($invalidString){
|
|
Direction::make($invalidString);
|
|
}
|
|
public function validStrings(){
|
|
return array(
|
|
array('x+'),
|
|
array('y+'),
|
|
array('x-'),
|
|
array('y-'),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider validStrings
|
|
*/
|
|
public function testAcceptValidString($validString){
|
|
$this->assertInstanceOf(Direction::class,Direction::make($validString));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider validStrings
|
|
*/
|
|
public function testDeltaXY($validString){
|
|
$dir = Direction::make($validString);
|
|
$this->assertTrue($dir->deltaX != 0 || $dir->deltaY != 0);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider validStrings
|
|
*/
|
|
public function testToString($validString){
|
|
$this->assertTrue(Direction::make($validString) == $validString);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider validStrings
|
|
*/
|
|
public function testOpposite($validString){
|
|
$dir = Direction::make($validString);
|
|
$op = $dir->opposite();
|
|
|
|
$this->assertInstanceOf(Direction::class,$op);
|
|
$this->assertFalse($dir == $op);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider validStrings
|
|
*/
|
|
public function testOppositeOpposite($validString){
|
|
$dir = Direction::make($validString);
|
|
$opop = $dir->opposite()->opposite();
|
|
$this->assertTrue($dir == $opop);
|
|
}
|
|
|
|
} |