File tree 3 files changed +24
-6
lines changed
3 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ public function it_can_generate_a_graph()
34
34
35
35
$ tree = new ValueNode ('root ' , 2 );
36
36
37
- $ nodes = [];
37
+ $ nodes = [0 => new ValueNode () ];
38
38
foreach (\range ('A ' , 'F ' ) as $ letter ) {
39
39
$ nodes [] = new ValueNode ($ letter , 2 );
40
40
}
@@ -78,4 +78,26 @@ public function it_can_create_a_graph()
78
78
->render ($ tree )
79
79
->shouldReturn ($ result . PHP_EOL );
80
80
}
81
+
82
+ public function it_can_display ()
83
+ {
84
+ $ visitor = new BreadthFirstVisitor ();
85
+ $ graph = new Graph ();
86
+ $ graphviz = new GraphViz ();
87
+
88
+ $ this ->beConstructedWith ($ visitor , $ graph , $ graphviz );
89
+
90
+ $ tree = new ValueNode ('root ' , 2 );
91
+
92
+ $ nodes = [];
93
+ foreach (\range ('A ' , 'F ' ) as $ letter ) {
94
+ $ nodes [] = new ValueNode ($ letter , 2 );
95
+ }
96
+
97
+ $ tree ->add (...$ nodes );
98
+
99
+ $ this
100
+ ->display ($ tree )
101
+ ->shouldReturn ($ this );
102
+ }
81
103
}
Original file line number Diff line number Diff line change @@ -17,6 +17,6 @@ class TestGraphViz extends GraphViz
17
17
*/
18
18
protected function hash (NodeInterface $ node )
19
19
{
20
- return $ node ->getValue ();
20
+ return $ node ->getValue () ?? parent :: hash ( $ node ) ;
21
21
}
22
22
}
Original file line number Diff line number Diff line change @@ -73,10 +73,6 @@ public function getGraph(NodeInterface $node): Graph
73
73
/** @var int $hash_parent */
74
74
$ hash_parent = $ this ->hash ($ parent );
75
75
76
- if (false === $ this ->graph ->hasVertex ($ hash_parent )) {
77
- $ this ->graph ->createVertex ($ hash_parent );
78
- }
79
-
80
76
$ this ->graph ->getVertex ($ hash_parent )->createEdgeTo ($ this ->graph ->getVertex ($ hash ));
81
77
}
82
78
You can’t perform that action at this time.
0 commit comments