don't run SVG tests unless dot is installed
[scpubgit/stemmatology.git] / t / text_tradition_collation.t
CommitLineData
0e47f4f6 1#!/usr/bin/perl -w
2
3use strict;
4use Test::More 'no_plan';
5$| = 1;
6
7
8
9# =begin testing
10{
11use Text::Tradition;
12
56eefa04 13my $READINGS = 311;
14my $PATHS = 361;
15
16my $datafile = 't/data/florilegium_tei_ps.xml';
17my $tradition = Text::Tradition->new( 'input' => 'TEI',
18 'name' => 'test0',
19 'file' => $datafile,
20 'linear' => 1 );
21
22ok( $tradition, "Got a tradition object" );
23is( scalar $tradition->witnesses, 13, "Found all witnesses" );
24ok( $tradition->collation, "Tradition has a collation" );
25
26my $c = $tradition->collation;
27is( scalar $c->readings, $READINGS, "Collation has all readings" );
28is( scalar $c->paths, $PATHS, "Collation has all paths" );
29is( scalar $c->relationships, 0, "Collation has all relationships" );
30
31# Add a few relationships
32$c->add_relationship( 'w123', 'w125', { 'type' => 'collated' } );
33$c->add_relationship( 'w193', 'w196', { 'type' => 'collated' } );
34$c->add_relationship( 'w257', 'w262', { 'type' => 'transposition' } );
35
36# Now write it to GraphML and parse it again.
37
38my $graphml = $c->as_graphml;
39my $st = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml );
40is( scalar $st->collation->readings, $READINGS, "Reparsed collation has all readings" );
41is( scalar $st->collation->paths, $PATHS, "Reparsed collation has all paths" );
42is( scalar $st->collation->relationships, 3, "Reparsed collation has new relationships" );
43}
44
45
46
47# =begin testing
48{
49use Text::Tradition;
50
0e47f4f6 51my $cxfile = 't/data/Collatex-16.xml';
52my $t = Text::Tradition->new(
53 'name' => 'inline',
54 'input' => 'CollateX',
55 'file' => $cxfile,
56 );
57my $c = $t->collation;
4633f9e4 58
b365fbae 59# Make an svg
bfcbcecb 60my $table = $c->alignment_table;
61ok( $c->has_cached_table, "Alignment table was cached" );
62is( $c->alignment_table, $table, "Cached table returned upon second call" );
b365fbae 63$c->calculate_ranks;
bfcbcecb 64is( $c->alignment_table, $table, "Cached table retained with no rank change" );
b365fbae 65$c->add_relationship( 'n9', 'n23', { 'type' => 'spelling' } );
bfcbcecb 66isnt( $c->alignment_table, $table, "Alignment table changed after relationship add" );
b365fbae 67}
68
69
70
71# =begin testing
72{
73use Text::Tradition;
74
75my $cxfile = 't/data/Collatex-16.xml';
76my $t = Text::Tradition->new(
77 'name' => 'inline',
78 'input' => 'CollateX',
79 'file' => $cxfile,
80 );
81my $c = $t->collation;
82
4633f9e4 83isnt( $c->reading('n23')->rank, $c->reading('n9')->rank, "Rank skew exists" );
84$c->add_relationship( 'n23', 'n9', { 'type' => 'collated', 'scope' => 'local' } );
85is( scalar $c->relationships, 4, "Found all expected relationships" );
86$c->remove_collations;
87is( scalar $c->relationships, 3, "Collated relationships now gone" );
88is( $c->reading('n23')->rank, $c->reading('n9')->rank, "Aligned ranks were preserved" );
89}
90
91
92
93# =begin testing
94{
95use Text::Tradition;
96
97my $cxfile = 't/data/Collatex-16.xml';
98my $t = Text::Tradition->new(
99 'name' => 'inline',
100 'input' => 'CollateX',
101 'file' => $cxfile,
102 );
103my $c = $t->collation;
0e47f4f6 104
d4b75f44 105my @common = $c->calculate_common_readings();
106is( scalar @common, 8, "Found correct number of common readings" );
107my @marked = sort $c->common_readings();
108is( scalar @common, 8, "All common readings got marked as such" );
109my @expected = qw/ n1 n12 n16 n19 n20 n5 n6 n7 /;
110is_deeply( \@marked, \@expected, "Found correct list of common readings" );
111}
112
113
114
115# =begin testing
116{
117use Text::Tradition;
118
119my $cxfile = 't/data/Collatex-16.xml';
120my $t = Text::Tradition->new(
121 'name' => 'inline',
122 'input' => 'CollateX',
123 'file' => $cxfile,
124 );
125my $c = $t->collation;
126
4e5a7b2c 127is( $c->common_predecessor( 'n9', 'n23' )->id,
0e47f4f6 128 'n20', "Found correct common predecessor" );
4e5a7b2c 129is( $c->common_successor( 'n9', 'n23' )->id,
0e47f4f6 130 '#END#', "Found correct common successor" );
131
4e5a7b2c 132is( $c->common_predecessor( 'n19', 'n17' )->id,
0e47f4f6 133 'n16', "Found correct common predecessor for readings on same path" );
4e5a7b2c 134is( $c->common_successor( 'n21', 'n26' )->id,
0e47f4f6 135 '#END#', "Found correct common successor for readings on same path" );
136}
137
138
139
140
1411;