# Make an undirected version of this graph.
$graph = $self->graph->undirected_copy();
}
+ # First, ensure that the requested root is actually a vertex in the graph.
+ unless( $graph->has_vertex( $rootvertex ) ) {
+ throw( "Cannot orient graph $graph on nonexistent vertex $rootvertex" );
+ }
+
+ # Now make a directed version of the graph.
my $rooted = Graph->new();
$rooted->add_vertex( $rootvertex );
my @next = ( $rootvertex );
}
# Set the vertex classes
map { $rooted->set_vertex_attribute( $_, 'class', 'hypothetical' ) }
- $self->graph->hypotheticals;
- map { $rooted->set_vertex_class( $_, 'class', 'extant' ) }
- $self->graph->witnesses;
- return $rooted;
+ $self->hypotheticals;
+ map { $rooted->set_vertex_attribute( $_, 'class', 'extant' ) }
+ $self->witnesses;
+ $self->graph( $rooted );
}
my $editable = $stemma->editable();
ok( $editable =~ /digraph/, "Got a dot edit graph" );
ok( $editable =~ /hypothetical/, "Graph contains an edit class" );
+
+# Test re-rooting of our graph
+try {
+ $stemma->root_graph('D');
+ ok( 0, "Made attempt to root stemma graph on nonexistent vertex" );
+} catch( Text::Tradition::Error $e ) {
+ like( $e->message, qr/Cannot orient graph(.*)on nonexistent vertex/,
+ "Exception raised for attempt to root graph on nonexistent vertex" );
+}
+$stemma->root_graph( 'B' );
+is( $stemma->graph, '1-A,2-1,2-C,B-2',
+ "Stemma graph successfully re-rooted on vertex B" );
+
done_testing();