-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
515 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
root = true | ||
|
||
[*] | ||
ij_php_block_brace_style = end_of_line | ||
ij_php_class_brace_style = end_of_line | ||
ij_php_for_brace_force = always | ||
ij_php_if_brace_force = if_multiline | ||
ij_php_method_brace_style = end_of_line | ||
ij_php_space_after_type_cast = true | ||
ij_php_space_after_colon_in_return_type = true | ||
ij_php_blank_lines_after_imports = 1 | ||
ij_php_blank_lines_before_imports = 1 | ||
ij_php_align_class_constants = true | ||
ij_php_align_assignments = true | ||
ij_php_align_inline_comments = true | ||
ij_php_align_key_value_pairs = true | ||
ij_php_align_group_field_declarations = true | ||
ij_php_align_multiline_array_initializer_expression = true | ||
ij_php_align_multiline_for = true | ||
ij_php_align_phpdoc_comments = true | ||
ij_php_align_phpdoc_param_names = true | ||
ij_php_import_sorting = alphabetic | ||
ij_php_blank_lines_after_class_header = 1 | ||
ij_php_blank_lines_before_class_end = 1 | ||
ij_php_else_if_style = separate | ||
ij_any_else_on_new_line = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,42 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Dogan Ucar, <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
namespace doganoo\PHPAlgorithmsTest\Cache; | ||
|
||
use doganoo\PHPAlgorithms\common\Exception\InvalidKeyTypeException; | ||
use doganoo\PHPAlgorithms\common\Exception\UnsupportedKeyTypeException; | ||
use doganoo\PHPAlgorithms\Datastructure\Cache\LRUCache; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class LRUCacheTest extends \PHPUnit\Framework\TestCase { | ||
class LRUCacheTest extends TestCase { | ||
|
||
/** | ||
* @throws InvalidKeyTypeException | ||
* @throws UnsupportedKeyTypeException | ||
*/ | ||
public function testCache() { | ||
$cache = new LRUCache(); | ||
$cache->put("a", 1); | ||
|
@@ -19,6 +51,10 @@ public function testCache() { | |
$this->assertTrue($last === "b"); | ||
} | ||
|
||
/** | ||
* @throws InvalidKeyTypeException | ||
* @throws UnsupportedKeyTypeException | ||
*/ | ||
public function testCacheWithSize() { | ||
$cache = new LRUCache(2); | ||
$cache->put("a", 1); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,62 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Dogan Ucar, <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
namespace doganoo\PHPAlgorithmsTest\Comparator; | ||
|
||
use doganoo\PHPAlgorithms\Common\Util\Comparator; | ||
use doganoo\PHPAlgorithms\Datastructure\Graph\Graph\Node; | ||
use doganoo\PHPAlgorithms\Datastructure\Lists\ArrayLists\ArrayList; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ComparatorTest extends \PHPUnit\Framework\TestCase { | ||
class ComparatorTest extends TestCase { | ||
|
||
public function testComparator() { | ||
$node = new Node(1); | ||
$node = new Node(1); | ||
$node2 = new Node(2); | ||
$this->assertTrue(Comparator::equals($node, $node2) === false); | ||
|
||
|
||
$node = new Node(1); | ||
$node = new Node(1); | ||
$node2 = new Node(1); | ||
$this->assertTrue(Comparator::equals($node, $node2) === true); | ||
|
||
|
||
$node = new Node(1); | ||
$node = new Node(1); | ||
$value = "test"; | ||
$this->assertTrue(Comparator::equals($node, $value) === false); | ||
|
||
$node = "test"; | ||
$node = "test"; | ||
$value = "test"; | ||
$this->assertTrue(Comparator::equals($node, $value) === true); | ||
|
||
$node = "1"; | ||
$node = "1"; | ||
$value = 1; | ||
$this->assertTrue(Comparator::equals($node, $value) === true); | ||
|
||
$node = new Node(1); | ||
$node = new Node(1); | ||
$value = new ArrayList(); | ||
$this->assertTrue(Comparator::equals($node, $value) === false); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,52 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Dogan Ucar, <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
namespace doganoo\PHPAlgorithmsTest\Graph\graph; | ||
|
||
|
||
use doganoo\PHPAlgorithms\Datastructure\Graph\Graph\DirectedGraph; | ||
use doganoo\PHPAlgorithms\Datastructure\Graph\Graph\Node; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DirectedGraphTest extends \PHPUnit\Framework\TestCase { | ||
class DirectedGraphTest extends TestCase { | ||
|
||
public function testAdd() { | ||
$graph = new DirectedGraph(); | ||
$this->assertTrue($graph->addNode(new Node(1)) === true); | ||
} | ||
|
||
public function testSubGraphSize() { | ||
$one = new Node(1); | ||
$one = new Node(1); | ||
$nine = new Node(9); | ||
$five = new Node(5); | ||
|
||
$one->addAdjacent($nine); | ||
$one->addAdjacent($five); | ||
|
||
$two = new Node(2); | ||
$two = new Node(2); | ||
$four = new Node(4); | ||
|
||
$two->addAdjacent($four); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
<?php | ||
|
||
use doganoo\PHPAlgorithms\Algorithm\Traversal\PreOrder; | ||
use doganoo\PHPAlgorithms\Datastructure\Graph\Tree\AVLTree as AVLTreee; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
declare(strict_types=1); | ||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Dogan Ucar | ||
* Copyright (c) 2018 Dogan Ucar, <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -28,6 +24,10 @@ | |
* SOFTWARE. | ||
*/ | ||
|
||
namespace doganoo\PHPAlgorithmsTest\Graph\trees; | ||
|
||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class AVLTree extends TestCase { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Dogan Ucar | ||
* Copyright (c) 2018 Dogan Ucar, <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -23,23 +24,27 @@ | |
* SOFTWARE. | ||
*/ | ||
|
||
namespace doganoo\PHPAlgorithmsTest\Graph\trees; | ||
|
||
use doganoo\PHPAlgorithms\Algorithm\Traversal\InOrder; | ||
use doganoo\PHPAlgorithms\Algorithm\Traversal\PostOrder; | ||
use doganoo\PHPAlgorithms\Algorithm\Traversal\PreOrder; | ||
use doganoo\PHPAlgorithms\Common\Interfaces\IComparable; | ||
use doganoo\PHPAlgorithms\Datastructure\Graph\Tree\BinarySearchTree; | ||
use doganoo\PHPAlgorithmsTest\Util\TreeUtil; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class BinaryTreeTest | ||
*/ | ||
class BinarySearchTreeTest extends \PHPUnit\Framework\TestCase { | ||
class BinarySearchTreeTest extends TestCase { | ||
|
||
/** | ||
* tests addition and height | ||
*/ | ||
public function testAdd() { | ||
/** @var BinarySearchTree $bst */ | ||
$bst = \TreeUtil::getBinarySearchTree(); | ||
$bst = TreeUtil::getBinarySearchTree(); | ||
$node = $bst->search(1); | ||
$this->assertTrue($node !== null); | ||
$this->assertTrue($bst->height() === 3); | ||
|
@@ -61,8 +66,8 @@ public function testMinimumHeight() { | |
* tests in order Traversal | ||
*/ | ||
public function testInOrder() { | ||
$bst = \TreeUtil::getBinarySearchTree(); | ||
$array = []; | ||
$bst = TreeUtil::getBinarySearchTree(); | ||
$array = []; | ||
$traversal = new InOrder($bst); | ||
$traversal->setCallable(function ($value) use (&$array) { | ||
$array[] = $value; | ||
|
@@ -75,8 +80,8 @@ public function testInOrder() { | |
* tests pre order Traversal | ||
*/ | ||
public function testPreOrder() { | ||
$bst = \TreeUtil::getBinarySearchTree(); | ||
$array = []; | ||
$bst = TreeUtil::getBinarySearchTree(); | ||
$array = []; | ||
$traversal = new PreOrder($bst); | ||
$traversal->setCallable(function ($value) use (&$array) { | ||
$array[] = $value; | ||
|
@@ -89,8 +94,8 @@ public function testPreOrder() { | |
* tests post order Traversal | ||
*/ | ||
public function testPostOrder() { | ||
$bst = \TreeUtil::getBinarySearchTree(); | ||
$array = []; | ||
$bst = TreeUtil::getBinarySearchTree(); | ||
$array = []; | ||
$traversal = new PostOrder($bst); | ||
$traversal->setCallable(function ($value) use (&$array) { | ||
$array[] = $value; | ||
|
@@ -100,7 +105,7 @@ public function testPostOrder() { | |
} | ||
|
||
public function testWithObjects() { | ||
$tree = new BinarySearchTree(); | ||
$tree = new BinarySearchTree(); | ||
$upper = 10; | ||
for ($i = 0; $i < $upper; $i++) { | ||
$x = new TestNode($i); | ||
|
@@ -113,9 +118,11 @@ public function testWithObjects() { | |
$this->assertTrue($node === null); | ||
|
||
} | ||
|
||
} | ||
|
||
class TestNode implements IComparable { | ||
|
||
private $id = 0; | ||
|
||
public function __construct($id) { | ||
|
@@ -138,6 +145,7 @@ public function compareTo($object): int { | |
public function getId(): int { | ||
return $this->id; | ||
} | ||
|
||
} | ||
|
||
; |
Oops, something went wrong.