11<?php
2+ declare (strict_types=1 );
23/**
34 * MIT License
45 *
5- * Copyright (c) 2018 Dogan Ucar
6+ * Copyright (c) 2018 Dogan Ucar, <dogan@dogan-ucar.de>
67 *
78 * Permission is hereby granted, free of charge, to any person obtaining a copy
89 * of this software and associated documentation files (the "Software"), to deal
2324 * SOFTWARE.
2425 */
2526
27+ namespace doganoo \PHPAlgorithmsTest \Graph \trees ;
28+
2629use doganoo \PHPAlgorithms \Algorithm \Traversal \InOrder ;
2730use doganoo \PHPAlgorithms \Algorithm \Traversal \PostOrder ;
2831use doganoo \PHPAlgorithms \Algorithm \Traversal \PreOrder ;
2932use doganoo \PHPAlgorithms \Common \Interfaces \IComparable ;
3033use doganoo \PHPAlgorithms \Datastructure \Graph \Tree \BinarySearchTree ;
34+ use doganoo \PHPAlgorithmsTest \Util \TreeUtil ;
35+ use PHPUnit \Framework \TestCase ;
3136
3237/**
3338 * Class BinaryTreeTest
3439 */
35- class BinarySearchTreeTest extends \ PHPUnit \ Framework \ TestCase {
40+ class BinarySearchTreeTest extends TestCase {
3641
3742 /**
3843 * tests addition and height
3944 */
4045 public function testAdd () {
4146 /** @var BinarySearchTree $bst */
42- $ bst = \ TreeUtil::getBinarySearchTree ();
47+ $ bst = TreeUtil::getBinarySearchTree ();
4348 $ node = $ bst ->search (1 );
4449 $ this ->assertTrue ($ node !== null );
4550 $ this ->assertTrue ($ bst ->height () === 3 );
@@ -61,8 +66,8 @@ public function testMinimumHeight() {
6166 * tests in order Traversal
6267 */
6368 public function testInOrder () {
64- $ bst = \ TreeUtil::getBinarySearchTree ();
65- $ array = [];
69+ $ bst = TreeUtil::getBinarySearchTree ();
70+ $ array = [];
6671 $ traversal = new InOrder ($ bst );
6772 $ traversal ->setCallable (function ($ value ) use (&$ array ) {
6873 $ array [] = $ value ;
@@ -75,8 +80,8 @@ public function testInOrder() {
7580 * tests pre order Traversal
7681 */
7782 public function testPreOrder () {
78- $ bst = \ TreeUtil::getBinarySearchTree ();
79- $ array = [];
83+ $ bst = TreeUtil::getBinarySearchTree ();
84+ $ array = [];
8085 $ traversal = new PreOrder ($ bst );
8186 $ traversal ->setCallable (function ($ value ) use (&$ array ) {
8287 $ array [] = $ value ;
@@ -89,8 +94,8 @@ public function testPreOrder() {
8994 * tests post order Traversal
9095 */
9196 public function testPostOrder () {
92- $ bst = \ TreeUtil::getBinarySearchTree ();
93- $ array = [];
97+ $ bst = TreeUtil::getBinarySearchTree ();
98+ $ array = [];
9499 $ traversal = new PostOrder ($ bst );
95100 $ traversal ->setCallable (function ($ value ) use (&$ array ) {
96101 $ array [] = $ value ;
@@ -100,7 +105,7 @@ public function testPostOrder() {
100105 }
101106
102107 public function testWithObjects () {
103- $ tree = new BinarySearchTree ();
108+ $ tree = new BinarySearchTree ();
104109 $ upper = 10 ;
105110 for ($ i = 0 ; $ i < $ upper ; $ i ++) {
106111 $ x = new TestNode ($ i );
@@ -113,9 +118,11 @@ public function testWithObjects() {
113118 $ this ->assertTrue ($ node === null );
114119
115120 }
121+
116122}
117123
118124class TestNode implements IComparable {
125+
119126 private $ id = 0 ;
120127
121128 public function __construct ($ id ) {
@@ -138,6 +145,7 @@ public function compareTo($object): int {
138145 public function getId (): int {
139146 return $ this ->id ;
140147 }
148+
141149}
142150
143151;
0 commit comments