Skip to content

Commit

Permalink
Fix Functor
Browse files Browse the repository at this point in the history
  • Loading branch information
webeweb committed May 27, 2018
1 parent 77a8a16 commit 7e7114a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
namespace WBW\Library\Core\Algorithm\Sorting;

/**
* Fonctor interface.
* Functor interface.
*
* @author webeweb <https://github.com/webeweb/>
* @package WBW\Library\Core\Algorithm\Sorting
*/
interface FonctorInterface {
interface FunctorInterface {

/**
* Compare two values.
Expand Down
28 changes: 14 additions & 14 deletions Algorithm/Sorting/QuickSort.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
class QuickSort {

/**
* Fonctor.
* Functor.
*
* @var FonctorInterface
* @var FunctorInterface
*/
private $fonctor;
private $functor;

/**
* Values.
Expand All @@ -37,20 +37,20 @@ class QuickSort {
* Constructor.
*
* @param array $values The values.
* @param FonctorInterface $fonctor The fonctor.
* @param FunctorInterface $functor The fonctor.
*/
public function __construct(array $values, FonctorInterface $fonctor) {
$this->setFonctor($fonctor);
public function __construct(array $values, FunctorInterface $functor) {
$this->setFunctor($functor);
$this->setValues($values);
}

/**
* Get the fonctor.
*
* @return Fonctor Returns the fonctor.
* @return Functor Returns the fonctor.
*/
public function getFonctor() {
return $this->fonctor;
public function getFunctor() {
return $this->functor;
}

/**
Expand Down Expand Up @@ -78,11 +78,11 @@ private function quickSort($min, $max) {

while ($i <= $j) {

while (true === $this->fonctor->compare($this->values[$i], $pivot)) {
while (true === $this->functor->compare($this->values[$i], $pivot)) {
++$i;
}

while (true === $this->fonctor->compare($pivot, $this->values[$j])) {
while (true === $this->functor->compare($pivot, $this->values[$j])) {
--$j;
}

Expand All @@ -104,11 +104,11 @@ private function quickSort($min, $max) {
/**
* Set the fonctor.
*
* @param FonctorInterface $fonctor The fonctor.
* @param FunctorInterface $fonctor The fonctor.
* @return QuickSort Returns this quick sort.
*/
public function setFonctor(FonctorInterface $fonctor) {
$this->fonctor = $fonctor;
public function setFunctor(FunctorInterface $fonctor) {
$this->functor = $fonctor;
return $this;
}

Expand Down
12 changes: 6 additions & 6 deletions Tests/Algorithm/Sorting/QuickSortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace WBW\Library\Core\Tests\Algorithm\Sorting;

use PHPUnit_Framework_TestCase;
use WBW\Library\Core\Algorithm\Sorting\FonctorInterface;
use WBW\Library\Core\Algorithm\Sorting\FunctorInterface;
use WBW\Library\Core\Algorithm\Sorting\QuickSort;
use WBW\Library\Core\Tests\Fixtures\Algorithm\Sorting\IntegerFonctor;
use WBW\Library\Core\Tests\Fixtures\Algorithm\Sorting\IntegerFunctor;

/**
* Quick sort test.
Expand All @@ -26,9 +26,9 @@
final class QuickSortTest extends PHPUnit_Framework_TestCase {

/**
* Fonctor.
* Functor.
*
* @var FonctorInterface
* @var FunctorInterface
*/
private $fonctor;

Expand All @@ -45,7 +45,7 @@ final class QuickSortTest extends PHPUnit_Framework_TestCase {
protected function setUp() {

// Set the fonctor mock.
$this->fonctor = new IntegerFonctor();
$this->fonctor = new IntegerFunctor();

// Set the values mock.
$this->values = [12, 98, 21, 89, 23, 87, 32, 78, 34, 76, 43, 67, 45, 65, 54, 56,];
Expand All @@ -60,7 +60,7 @@ public function testConstruct() {

$obj = new QuickSort($this->values, $this->fonctor);

$this->assertSame($this->fonctor, $obj->getFonctor());
$this->assertSame($this->fonctor, $obj->getFunctor());
$this->assertSame($this->values, $obj->getValues());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

namespace WBW\Library\Core\Tests\Fixtures\Algorithm\Sorting;

use WBW\Library\Core\Algorithm\Sorting\FonctorInterface;
use WBW\Library\Core\Algorithm\Sorting\FunctorInterface;

/**
* Integer fonctor.
* Integer functor.
*
* @author webeweb <https://github.com/webeweb/>
* @package WBW\Library\Core\Tests\Fixtures\Node
* @final
*/
final class IntegerFonctor implements FonctorInterface {
final class IntegerFunctor implements FunctorInterface {

/**
* {@inheritdoc}
Expand Down

0 comments on commit 7e7114a

Please sign in to comment.