|
@@ 35-59 (lines=25) @@
|
| 32 |
|
$size = new SizeOfTree($graph); |
| 33 |
|
} |
| 34 |
|
|
| 35 |
|
public function testICanGetDepthOfNode() |
| 36 |
|
{ |
| 37 |
|
$graph = new Graph(); |
| 38 |
|
$a = new Node('A'); |
| 39 |
|
$b = new Node('B'); |
| 40 |
|
$c = new Node('C'); |
| 41 |
|
$d = new Node('D'); |
| 42 |
|
$e = new Node('E'); |
| 43 |
|
|
| 44 |
|
$graph->insert($a)->insert($b)->insert($c)->insert($d)->insert($e); |
| 45 |
|
|
| 46 |
|
// case 1 |
| 47 |
|
$graph->addEdge($a, $b); // A -> B |
| 48 |
|
$graph->addEdge($b, $c); // B -> C |
| 49 |
|
$graph->addEdge($c, $d); // C -> D |
| 50 |
|
$graph->addEdge($a, $e); // A -> E (node with multiple childs) |
| 51 |
|
|
| 52 |
|
$size = new SizeOfTree($graph); |
| 53 |
|
|
| 54 |
|
$this->assertEquals(0, $size->getDepthOfNode($a)); |
| 55 |
|
$this->assertEquals(1, $size->getDepthOfNode($b)); |
| 56 |
|
$this->assertEquals(2, $size->getDepthOfNode($c)); |
| 57 |
|
$this->assertEquals(3, $size->getDepthOfNode($d)); |
| 58 |
|
$this->assertEquals(1, $size->getDepthOfNode($e)); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
public function testICanGetNbChildsOfNode() |
| 62 |
|
{ |
|
@@ 61-85 (lines=25) @@
|
| 58 |
|
$this->assertEquals(1, $size->getDepthOfNode($e)); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
public function testICanGetNbChildsOfNode() |
| 62 |
|
{ |
| 63 |
|
$graph = new Graph(); |
| 64 |
|
$a = new Node('A'); |
| 65 |
|
$b = new Node('B'); |
| 66 |
|
$c = new Node('C'); |
| 67 |
|
$d = new Node('D'); |
| 68 |
|
$e = new Node('E'); |
| 69 |
|
|
| 70 |
|
$graph->insert($a)->insert($b)->insert($c)->insert($d)->insert($e); |
| 71 |
|
|
| 72 |
|
// case 1 |
| 73 |
|
$graph->addEdge($a, $b); // A -> B |
| 74 |
|
$graph->addEdge($b, $c); // B -> C |
| 75 |
|
$graph->addEdge($c, $d); // C -> D |
| 76 |
|
$graph->addEdge($a, $e); // A -> E (node with multiple childs) |
| 77 |
|
|
| 78 |
|
$size = new SizeOfTree($graph); |
| 79 |
|
|
| 80 |
|
$this->assertEquals(4, $size->getNumberOfChilds($a)); |
| 81 |
|
$this->assertEquals(2, $size->getNumberOfChilds($b)); |
| 82 |
|
$this->assertEquals(1, $size->getNumberOfChilds($c)); |
| 83 |
|
$this->assertEquals(0, $size->getNumberOfChilds($d)); |
| 84 |
|
$this->assertEquals(0, $size->getNumberOfChilds($e)); |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
public function testICanGetInfoAboutAverageHeightOfTree() |
| 88 |
|
{ |