X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstemma.t;h=697d0d2c46b1070c0caf1c74fd9cb7afdddcde38;hb=7f52eac8cd00b160ea9e828790cbd093dc444feb;hp=95b25e3273bd1f90e083452c6ca3541d1169a9c5;hpb=7a7c249ce334ba9d74af27aba82d8f29792250d7;p=scpubgit%2Fstemmatology.git diff --git a/t/stemma.t b/t/stemma.t index 95b25e3..697d0d2 100644 --- a/t/stemma.t +++ b/t/stemma.t @@ -1,9 +1,11 @@ #!/usr/bin/perl use strict; use warnings; +use File::Which; use Test::More; use lib 'lib'; use Text::Tradition; +use Text::Tradition::StemmaUtil qw/ character_input phylip_pars parse_newick /; use XML::LibXML; use XML::LibXML::XPathContext; @@ -21,42 +23,46 @@ $c->add_relationship( 'n9', 'n23', { 'type' => 'spelling' } ); $c->add_relationship( 'n8', 'n13', { 'type' => 'spelling' } ); $c->calculate_ranks(); -my $stemma = $tradition->add_stemma( 't/data/simple.dot' ); +my $stemma = $tradition->add_stemma( dotfile => 't/data/simple.dot' ); # Test for object creation ok( $stemma->isa( 'Text::Tradition::Stemma' ), 'Got the right sort of object' ); is( $stemma->graph, '1-2,1-A,2-B,2-C', "Got the correct graph" ); # Test for character matrix creation -my $m = $stemma->make_character_matrix(); +my $mstr = character_input( $c->alignment_table() ); ## check number of rows -is( scalar @$m, 3, "Found three witnesses in char matrix" ); +my @mlines = split( "\n", $mstr ); +my $msig = shift @mlines; +my( $rows, $chars ) = $msig =~ /(\d+)\s+(\d+)/; +is( $rows, 3, "Found three witnesses in char matrix" ); ## check number of columns -is( scalar( @{$m->[0]} ), 19, "Found 18 rows plus sigla in char matrix" ); +is( $chars, 18, "Found 18 rows plus sigla in char matrix" ); ## check matrix my %expected = ( 'A' => 'AAAAAAAXAAAAAAAAAA', 'B' => 'AXXXAAAAAABABAABAA', 'C' => 'AXXXAAAAABAAAAAXBB', ); -my @wits = map { shift @$_; } @$m; -map { s/\s+//g } @wits; -foreach my $i ( 0 .. $#wits ) { - my $w = $wits[$i]; - is( join( '', @{$m->[$i]} ), $expected{$w}, "Row for witness $w is correct" ); +foreach my $ml ( @mlines ) { + my( $wit, $chars ) = split( /\s+/, $ml ); + is( $chars, $expected{$wit}, "Row for witness $wit is correct" ); } # Test that pars runs -my( $status, $tree ) = $stemma->run_phylip_pars(); -ok( $status, "pars ran successfully" ); -print STDERR "Error was $tree\n" unless $status; +SKIP: { + skip "pars not in path", 3 unless File::Which::which('pars'); + my $newick = phylip_pars( $mstr ); + ok( $newick, "pars ran successfully" ); -# Test that we get a tree -is( scalar @{$stemma->distance_trees}, 1, "Got a single tree" ); -# Test that the tree has all our witnesses -$tree = $stemma->distance_trees->[0]; -my @leaves = grep { $tree->degree( $_ ) == 1 } $tree->vertices; -is( scalar @leaves, 3, "All witnesses in the tree" ); + my $trees = parse_newick( $newick ); + # Test that we get a tree + is( scalar @$trees, 1, "Got a single tree" ); + # Test that the tree has all our witnesses + my $tree = $trees->[0]; + my @leaves = grep { $tree->degree( $_ ) == 1 } $tree->vertices; + is( scalar @leaves, 3, "All witnesses in the tree" ); +} # Test our dot output my $display = $stemma->as_dot(); @@ -67,4 +73,4 @@ my $editable = $stemma->editable(); ok( $editable =~ /digraph/, "Got a dot edit graph" ); ok( $editable =~ /hypothetical/, "Graph contains an edit class" ); -done_testing(); \ No newline at end of file +done_testing();