X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Ftext_tradition_collation.t;h=f9d07fb747f8c14debe05c64522fdf8525f4f7d9;hb=e3b14278ce0995051308e72fcf3e6db13f578285;hp=bb283fab0e6d5f1ea789f12a6c6952bfe2b5b72f;hpb=0e47f4f67650eaa804f9e23b3241718d8eb94433;p=scpubgit%2Fstemmatology.git diff --git a/t/text_tradition_collation.t b/t/text_tradition_collation.t index bb283fa..f9d07fb 100644 --- a/t/text_tradition_collation.t +++ b/t/text_tradition_collation.t @@ -10,6 +10,113 @@ $| = 1; { use Text::Tradition; +my $READINGS = 311; +my $PATHS = 361; + +my $datafile = 't/data/florilegium_tei_ps.xml'; +my $tradition = Text::Tradition->new( 'input' => 'TEI', + 'name' => 'test0', + 'file' => $datafile, + 'linear' => 1 ); + +ok( $tradition, "Got a tradition object" ); +is( scalar $tradition->witnesses, 13, "Found all witnesses" ); +ok( $tradition->collation, "Tradition has a collation" ); + +my $c = $tradition->collation; +is( scalar $c->readings, $READINGS, "Collation has all readings" ); +is( scalar $c->paths, $PATHS, "Collation has all paths" ); +is( scalar $c->relationships, 0, "Collation has all relationships" ); + +# Add a few relationships +$c->add_relationship( 'w123', 'w125', { 'type' => 'collated' } ); +$c->add_relationship( 'w193', 'w196', { 'type' => 'collated' } ); +$c->add_relationship( 'w257', 'w262', { 'type' => 'transposition' } ); + +# Now write it to GraphML and parse it again. + +my $graphml = $c->as_graphml; +my $st = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml ); +is( scalar $st->collation->readings, $READINGS, "Reparsed collation has all readings" ); +is( scalar $st->collation->paths, $PATHS, "Reparsed collation has all paths" ); +is( scalar $st->collation->relationships, 3, "Reparsed collation has new relationships" ); +} + + + +# =begin testing +{ +use Text::Tradition; + +my $cxfile = 't/data/Collatex-16.xml'; +my $t = Text::Tradition->new( + 'name' => 'inline', + 'input' => 'CollateX', + 'file' => $cxfile, + ); +my $c = $t->collation; + +# Make an svg +my $svg = $c->as_svg; +is( substr( $svg, 0, 5 ), 'has_cached_svg, "SVG was cached" ); +is( $c->as_svg, $svg, "Cached SVG returned upon second call" ); +$c->calculate_ranks; +is( $c->as_svg, $svg, "Cached SVG retained with no rank change" ); +$c->add_relationship( 'n9', 'n23', { 'type' => 'spelling' } ); +isnt( $c->as_svg, $svg, "SVG changed after relationship add" ); +} + + + +# =begin testing +{ +use Text::Tradition; + +my $cxfile = 't/data/Collatex-16.xml'; +my $t = Text::Tradition->new( + 'name' => 'inline', + 'input' => 'CollateX', + 'file' => $cxfile, + ); +my $c = $t->collation; + +isnt( $c->reading('n23')->rank, $c->reading('n9')->rank, "Rank skew exists" ); +$c->add_relationship( 'n23', 'n9', { 'type' => 'collated', 'scope' => 'local' } ); +is( scalar $c->relationships, 4, "Found all expected relationships" ); +$c->remove_collations; +is( scalar $c->relationships, 3, "Collated relationships now gone" ); +is( $c->reading('n23')->rank, $c->reading('n9')->rank, "Aligned ranks were preserved" ); +} + + + +# =begin testing +{ +use Text::Tradition; + +my $cxfile = 't/data/Collatex-16.xml'; +my $t = Text::Tradition->new( + 'name' => 'inline', + 'input' => 'CollateX', + 'file' => $cxfile, + ); +my $c = $t->collation; + +my @common = $c->calculate_common_readings(); +is( scalar @common, 8, "Found correct number of common readings" ); +my @marked = sort $c->common_readings(); +is( scalar @common, 8, "All common readings got marked as such" ); +my @expected = qw/ n1 n12 n16 n19 n20 n5 n6 n7 /; +is_deeply( \@marked, \@expected, "Found correct list of common readings" ); +} + + + +# =begin testing +{ +use Text::Tradition; + my $cxfile = 't/data/Collatex-16.xml'; my $t = Text::Tradition->new( 'name' => 'inline', @@ -18,14 +125,14 @@ my $t = Text::Tradition->new( ); my $c = $t->collation; -is( $c->common_predecessor( $c->reading('n9'), $c->reading('n23') )->id, +is( $c->common_predecessor( 'n9', 'n23' )->id, 'n20', "Found correct common predecessor" ); -is( $c->common_successor( $c->reading('n9'), $c->reading('n23') )->id, +is( $c->common_successor( 'n9', 'n23' )->id, '#END#', "Found correct common successor" ); -is( $c->common_predecessor( $c->reading('n19'), $c->reading('n17') )->id, +is( $c->common_predecessor( 'n19', 'n17' )->id, 'n16', "Found correct common predecessor for readings on same path" ); -is( $c->common_successor( $c->reading('n21'), $c->reading('n26') )->id, +is( $c->common_successor( 'n21', 'n26' )->id, '#END#', "Found correct common successor for readings on same path" ); }