load XML::LibXML only when required; handle global relationships more correctly;...
[scpubgit/stemmatology.git] / t / analysis.t
index 19a6c50..b9e9d83 100755 (executable)
@@ -114,7 +114,12 @@ foreach my $row ( @{$results->{'variants'}} ) {
                }
        } else {
                # If not displaying, we're testing.
-               is( $row->{'genealogical'}, $expected{$row->{'id'}}, 
+               # HACK to cope with formerly unuseful rows
+               unless( exists $expected{$row->{'id'}} ) {
+                       $expected{$row->{'id'}} = 1;
+               }
+               my $gen_bool = $row->{'genealogical'} ? 1 : '';
+               is( $gen_bool, $expected{$row->{'id'}}, 
                        "Got expected genealogical result for rank " . $row->{'id'} );
                # If the row is genealogical, there should be one reading with no parents,
                # every reading should independently occur exactly once, and the total
@@ -125,15 +130,15 @@ foreach my $row ( @{$results->{'variants'}} ) {
                        my %is_parent;
                        my @has_no_parent;
                        foreach my $rdg ( @{$row->{'readings'}} ) {
-                               my $parents = $rdg->{'reading_parents'} || [];
-                               foreach my $p ( @$parents ) {
+                               my $parents = $rdg->{'reading_parents'} || {};
+                               foreach my $p ( keys %$parents ) {
                                        push( @{$is_parent{$p}}, $rdg->{'readingid'} );
                                }
-                               push( @has_no_parent, $rdg->{'readingid'} ) unless @$parents;
+                               push( @has_no_parent, $rdg->{'readingid'} ) unless keys %$parents;
                        }
                        # Test some stuff
                        foreach my $rdg ( @{$row->{'readings'}} ) {
-                               is( $rdg->{'independent_occurrence'}, 1, 
+                               is( @{$rdg->{'independent_occurrence'}}, 1, 
                                        "Genealogical reading originates exactly once" );
                        }
                        is( @has_no_parent, 1, "Only one genealogical reading lacks a parent" );