X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstemma.t;h=67ded66a85cd2b2afcc0916a6ac94ee1212305b1;hb=5f52ddcad7ea7dd5f8f07dbfd664b2f2faee7221;hp=276e7366fa443dae5239ed5d15bd5a6a45ca5fe0;hpb=7035e3a6ff8829ec8390fdfde75f23def2ed9313;p=scpubgit%2Fstemmatology.git diff --git a/t/stemma.t b/t/stemma.t index 276e736..67ded66 100644 --- a/t/stemma.t +++ b/t/stemma.t @@ -1,10 +1,10 @@ #!/usr/bin/perl use strict; use warnings; +use File::Which; use Test::More; use lib 'lib'; use Text::Tradition; -use Text::Tradition::Stemma; use XML::LibXML; use XML::LibXML::XPathContext; @@ -15,23 +15,60 @@ my $tradition = Text::Tradition->new( 'input' => 'CollateX', 'file' => $datafile, ); -my $stemma = Text::Tradition::Stemma->new( 'collation' => $tradition->collation ); +# Set up some relationships +my $c = $tradition->collation; +$c->add_relationship( 'n25', 'n26', { 'type' => 'spelling' } ); +$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' ); # 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 -$stemma->make_character_matrix(); +my $m = $stemma->make_character_matrix(); ## check number of rows +is( scalar @$m, 3, "Found three witnesses in char matrix" ); ## check number of columns +is( scalar( @{$m->[0]} ), 19, "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" ); +} # Test that pars runs -my( $status, $tree ) = $stemma->run_phylip_pars(); -ok( $status, "pars ran successfully" ); -print STDERR "Error was $tree\n" unless $status; - -# Test that we get a tree +SKIP: { + skip "pars not in path", 3 unless File::Which::which('pars'); + my( $status, $tree ) = $stemma->run_phylip_pars(); + ok( $status, "pars ran successfully" ); + print STDERR "Error was $tree\n" unless $status; + + # 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" ); +} -# Test that the tree has all our witnesses +# Test our dot output +my $display = $stemma->as_dot(); +ok( $display =~ /digraph/, "Got a dot display graph" ); +ok( $display !~ /hypothetical/, "Graph is display rather than edit" ); +# Test our editable output +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();