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