=begin testing
use Text::Tradition;
+use TryCatch;
my $cxfile = 't/data/Collatex-16.xml';
my $t = Text::Tradition->new(
ok( !$c->reading('n10'), "Reading n10 is gone" );
is( $c->reading('n9')->text, 'rood', "Reading n9 has an unchanged word" );
-# Combine n21 and n21p0
+# Try to combine n21 and n21p0. This should break.
my $remaining = $c->reading('n21');
$remaining ||= $c->reading('n22'); # one of these should still exist
-$c->merge_readings( 'n21p0', $remaining, 1 );
-ok( !$c->reading('n21'), "Reading $remaining is gone" );
-is( $c->reading('n21p0')->text, 'unto', "Reading n21p0 merged correctly" );
+try {
+ $c->merge_readings( 'n21p0', $remaining, 1 );
+ ok( 0, "Bad reading merge changed the graph" );
+} catch( Text::Tradition::Error $e ) {
+ like( $e->message, qr/neither concatenated nor collated/, "Expected exception from bad concatenation" );
+} catch {
+ ok( 0, "Unexpected error on bad reading merge: $@" );
+}
+
+try {
+ $c->calculate_ranks();
+ ok( 1, "Graph is still evidently whole" );
+} catch( Text::Tradition::Error $e ) {
+ ok( 0, "Caught a rank exception: " . $e->message );
+}
=end testing
=begin testing
+use Test::Warn;
use Text::Tradition;
use TryCatch;
-my $t = Text::Tradition->new(
- 'name' => 'inline',
- 'input' => 'Self',
- 'file' => 't/data/legendfrag.xml',
- );
+my $t;
+warnings_exist {
+ $t = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' );
+} [qr/Cannot set relationship on a meta reading/],
+ "Got expected relationship drop warning on parse";
+
my $c = $t->collation;
my %rdg_ids;
"Rank calculation on merged graph threw an error" );
}
-
-
=end testing
=cut
exists $reltypehash{$_[0]->type};
};
- my $linear = 1;
# Go through all readings looking for related ones
foreach my $r ( $self->readings ) {
next unless $self->reading( "$r" ); # might have been deleted meanwhile
} @related;
my $keep = shift @related;
foreach my $delr ( @related ) {
- $linear = undef
+ $self->linear( 0 )
unless( $self->get_relationship( $keep, $delr )->colocated );
$self->merge_readings( $keep, $delr );
}
}
}
- $self->linear( $linear );
}
=head2 compress_readings
ok( 0, "Reading duplication with all witnesses threw the wrong error" );
}
+try {
+ $sc->calculate_ranks();
+ ok( 1, "Graph is still evidently whole" );
+} catch( Text::Tradition::Error $e ) {
+ ok( 0, "Caught a rank exception: " . $e->message );
+}
+
=end testing
=cut
map { $self->set_equivalence( $_, $teq ) } @$sourcepool;
# Then merge the nodes in the equivalence graph.
foreach my $pred ( $self->equivalence_graph->predecessors( $seq ) ) {
+ next if $pred eq $teq; # don't add a self-loop on concatenation merge
$self->equivalence_graph->add_edge( $pred, $teq );
}
foreach my $succ ( $self->equivalence_graph->successors( $seq ) ) {
+ next if $succ eq $teq; # don't add a self-loop on concatenation merge
$self->equivalence_graph->add_edge( $teq, $succ );
}
$self->equivalence_graph->delete_vertex( $seq );
- # TODO enable this after collation parsing is done
throw( "Graph got disconnected making $source / $target equivalence" )
if $self->_is_disconnected && $self->collation->tradition->_initialized;
}
# =begin testing
{
use Text::Tradition;
+use TryCatch;
my $cxfile = 't/data/Collatex-16.xml';
my $t = Text::Tradition->new(
ok( !$c->reading('n10'), "Reading n10 is gone" );
is( $c->reading('n9')->text, 'rood', "Reading n9 has an unchanged word" );
-# Combine n21 and n21p0
+# Try to combine n21 and n21p0. This should break.
my $remaining = $c->reading('n21');
$remaining ||= $c->reading('n22'); # one of these should still exist
-$c->merge_readings( 'n21p0', $remaining, 1 );
-ok( !$c->reading('n21'), "Reading $remaining is gone" );
-is( $c->reading('n21p0')->text, 'unto', "Reading n21p0 merged correctly" );
+try {
+ $c->merge_readings( 'n21p0', $remaining, 1 );
+ ok( 0, "Bad reading merge changed the graph" );
+} catch( Text::Tradition::Error $e ) {
+ like( $e->message, qr/neither concatenated nor collated/, "Expected exception from bad concatenation" );
+} catch {
+ ok( 0, "Unexpected error on bad reading merge: $@" );
+}
+
+try {
+ $c->calculate_ranks();
+ ok( 1, "Graph is still evidently whole" );
+} catch( Text::Tradition::Error $e ) {
+ ok( 0, "Caught a rank exception: " . $e->message );
+}
}
# =begin testing
{
+use Test::Warn;
use Text::Tradition;
use TryCatch;
-my $t = Text::Tradition->new(
- 'name' => 'inline',
- 'input' => 'Self',
- 'file' => 't/data/legendfrag.xml',
- );
+my $t;
+warnings_exist {
+ $t = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' );
+} [qr/Cannot set relationship on a meta reading/],
+ "Got expected relationship drop warning on parse";
+
my $c = $t->collation;
my %rdg_ids;
} catch {
ok( 0, "Reading duplication with all witnesses threw the wrong error" );
}
+
+try {
+ $sc->calculate_ranks();
+ ok( 1, "Graph is still evidently whole" );
+} catch( Text::Tradition::Error $e ) {
+ ok( 0, "Caught a rank exception: " . $e->message );
+}
}