3 use strict; use warnings;
8 use Text::Tradition::StemmaUtil qw/ make_character_matrix /;
10 use XML::LibXML::XPathContext;
12 my $datafile = 't/data/Collatex-16.xml'; #TODO need other test data
14 my $tradition = Text::Tradition->new(
16 'input' => 'CollateX',
19 # Set up some relationships
20 my $c = $tradition->collation;
21 $c->add_relationship( 'n25', 'n26', { 'type' => 'spelling' } );
22 $c->add_relationship( 'n9', 'n23', { 'type' => 'spelling' } );
23 $c->add_relationship( 'n8', 'n13', { 'type' => 'spelling' } );
24 $c->calculate_ranks();
26 my $stemma = $tradition->add_stemma( 't/data/simple.dot' );
28 # Test for object creation
29 ok( $stemma->isa( 'Text::Tradition::Stemma' ), 'Got the right sort of object' );
30 is( $stemma->graph, '1-2,1-A,2-B,2-C', "Got the correct graph" );
32 # Test for character matrix creation
33 my $m = make_character_matrix( $c->make_alignment_table() );
34 ## check number of rows
35 is( scalar @$m, 3, "Found three witnesses in char matrix" );
36 ## check number of columns
37 is( scalar( @{$m->[0]} ), 19, "Found 18 rows plus sigla in char matrix" );
40 'A' => 'AAAAAAAXAAAAAAAAAA',
41 'B' => 'AXXXAAAAAABABAABAA',
42 'C' => 'AXXXAAAAABAAAAAXBB',
44 my @wits = map { shift @$_; } @$m;
45 map { s/\s+//g } @wits;
46 foreach my $i ( 0 .. $#wits ) {
48 is( join( '', @{$m->[$i]} ), $expected{$w}, "Row for witness $w is correct" );
53 skip "pars not in path", 3 unless File::Which::which('pars');
54 my( $status, $tree ) = $stemma->run_phylip_pars();
55 ok( $status, "pars ran successfully" );
56 print STDERR "Error was $tree\n" unless $status;
58 # Test that we get a tree
59 is( scalar @{$stemma->distance_trees}, 1, "Got a single tree" );
60 # Test that the tree has all our witnesses
61 $tree = $stemma->distance_trees->[0];
62 my @leaves = grep { $tree->degree( $_ ) == 1 } $tree->vertices;
63 is( scalar @leaves, 3, "All witnesses in the tree" );
67 my $display = $stemma->as_dot();
68 ok( $display =~ /digraph/, "Got a dot display graph" );
69 ok( $display !~ /hypothetical/, "Graph is display rather than edit" );
70 # Test our editable output
71 my $editable = $stemma->editable();
72 ok( $editable =~ /digraph/, "Got a dot edit graph" );
73 ok( $editable =~ /hypothetical/, "Graph contains an edit class" );