From: Tara L Andrews Date: Thu, 19 Apr 2012 14:01:01 +0000 (+0200) Subject: add failing tests for relationship logic, next we fix them X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6d381462ed381ad399f23f7e7967e07416b08ee4;p=scpubgit%2Fstemmatology.git add failing tests for relationship logic, next we fix them --- diff --git a/lib/Text/Tradition/Collation/RelationshipStore.pm b/lib/Text/Tradition/Collation/RelationshipStore.pm index dade4b4..d894568 100644 --- a/lib/Text/Tradition/Collation/RelationshipStore.pm +++ b/lib/Text/Tradition/Collation/RelationshipStore.pm @@ -202,6 +202,63 @@ scoped non-locally. Returns a status boolean and a list of all reading pairs connected by the call to add_relationship. +=begin testing + +use Text::Tradition; +use TryCatch; + +my $t1 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' ); +# Test 1: try to equate nodes that are prevented with an intermediate collation +ok( $t1, "Parsed test fragment file" ); +my $c1 = $t1->collation; +my $trel = $c1->get_relationship( '9,2', '9,3' ); +is( ref( $trel ), 'Text::Tradition::Collation::Relationship', + "Troublesome relationship exists" ); +is( $trel->type, 'collated', "Troublesome relationship is a collation" ); + +# Try to make the link we want +try { + $c1->add_relationship( '8,6', '10,3', { 'type' => 'orthographic' } ); + ok( 1, "Added cross-collation relationship as expected" ); +} catch { + ok( 0, "Existing collation blocked equivalence relationship" ); +} + +try { + $c1->calculate_ranks(); + ok( 1, "Successfully calculated ranks" ); +} catch { + ok( 0, "Collation now has a cycle" ); +} + +# Test 2: try to equate nodes that are prevented with a real intermediate +# equivalence + +my $t2 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' ); +# Test 1: try to equate nodes that are prevented with an intermediate collation +my $c2 = $t2->collation; +$c2->add_relationship( '9,2', '9,3', { 'type' => 'lexical' } ); +my $trel2 = $c2->get_relationship( '9,2', '9,3' ); +is( ref( $trel2 ), 'Text::Tradition::Collation::Relationship', + "Created blocking relationship" ); +is( $trel2->type, 'lexical', "Blocking relationship is not a collation" ); +# This time the link ought to fail +try { + $c2->add_relationship( '8,6', '10,3', { 'type' => 'orthographic' } ); + ok( 0, "Existing equivalence blocked crossing relationship" ); +} catch { + ok( 1, "Added cross-equivalent bad relationship" ); +} + +try { + $c2->calculate_ranks(); + ok( 1, "Successfully calculated ranks" ); +} catch { + ok( 0, "Collation now has a cycle" ); +} + +=end testing + =cut sub add_relationship { diff --git a/t/data/legendfrag.xml b/t/data/legendfrag.xml new file mode 100644 index 0000000..004a7ca --- /dev/null +++ b/t/data/legendfrag.xml @@ -0,0 +1,1822 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (a.c.) + base text + Latin + 1 + 3.1 + , + Legend of Bishop Henry + + + Default + #END# + 1 + #END# + 1137 + + + Default + #START# + 1 + #START# + 0 + + + Default + beatus + 10,2 + 10 + 0 + + + Default + venerabilis + 10,3 + 10 + 0 + + + Default + sanctus + 10,4 + 10 + 0 + + + Default + henricus + 11,2 + 11 + 0 + + + Default + heinricus + 11,3 + 11 + 0 + + + Default + Henricus + 11,4 + 11 + 0 + + + Default + pontifex + 11,5 + 11 + 0 + + + Default + de + 12,2 + 12 + 0 + + + Default + in + 12,3 + 12 + 0 + + + Default + ex + 12,4 + 12 + 0 + + + Default + anglia + 13,2 + 13 + 0 + + + Default + Anglia + 13,3 + 13 + 0 + + + Default + oriundus + 14,2 + 14 + 0 + + + Default + in + 6,2 + 6 + 0 + + + Default + svecia + 7,1 + 7 + 0 + + + Default + suetia + 7,3 + 7 + 0 + + + Default + swetia + 7,4 + 7 + 0 + + + Default + swecia + 7,5 + 7 + 0 + + + Default + suecia + 7,6 + 7 + 0 + + + Default + Swecia + 7,7 + 7 + 0 + + + Default + #LACUNA# + 8,1 + 8 + 0 + 1 + + + Default + Venerabilis + 8,2 + 8 + 0 + + + Default + beatus + 8,3 + 8 + 0 + + + Default + sanctus + 8,4 + 8 + 0 + + + Default + uenerabilis + 8,5 + 8 + 0 + + + Default + venerabilis + 8,6 + 8 + 0 + + + Default + henricus + 9,2 + 9 + 0 + + + Default + pontifex + 9,3 + 9 + 0 + + + K + + + A + + + Ab + + + B + + + BA + + + BL + + + BLu + + + BS + + + H + + + Ho + + + JG + + + L + + + Q + + + St + + + U + + + Y + + + O + + + Sk + + + AJ + + + CP + + + Cd + + + D + + + De + + + E + + + Fg + + + I + + + JB + + + LT + + + Lu + + + NR + + + NR2 + + + R + + + Va + + + Z + + + BSt + + + BU + + + Bc + + + C + + + Dr + + + Ef + + + F + + + G + + + Gh + + + Li + + + M + + + MN + + + N + + + P + + + S + + + T + + + V + + + Vg + + + X + + + T + + + Sk + + + A + + + B + + + BSt + + + BU + + + Bc + + + C + + + Dr + + + Ef + + + F + + + Gh + + + H + + + Ho + + + JG + + + K + + + M + + + MN + + + O + + + P + + + S + + + St + + + U + + + V + + + Vg + + + X + + + Y + + + BA + + + N + + + BL + + + BLu + + + BS + + + Q + + + G + + + N + + + H + + + De + + + CP + + + A + + + BL + + + BS + + + BSt + + + BU + + + Bc + + + C + + + Dr + + + Ho + + + K + + + Li + + + M + + + S + + + St + + + V + + + Vg + + + X + + + BLu + + + B + + + Ef + + + F + + + Gh + + + H + + + JG + + + MN + + + O + + + P + + + Q + + + U + + + Y + + + BA + + + G + + + L + + + T + + + N + + + Ab + + + BL + + + NR + + + B + + + C + + + Dr + + + E + + + Ef + + + Fg + + + I + + + JG + + + K + + + MN + + + S + + + T + + + Y + + + P + + + N + + + Y + + + B + + + BA + + + Ef + + + F + + + Gh + + + H + + + JG + + + MN + + + O + + + P + + + Q + + + Sk + + + U + + + A + + + BL + + + BS + + + BSt + + + BU + + + Bc + + + C + + + Dr + + + G + + + Ho + + + K + + + L + + + M + + + S + + + St + + + T + + + V + + + Vg + + + X + + + Li + + + BLu + + + A + + + B + + + BA + + + BL + + + BLu + + + BS + + + BSt + + + BU + + + Bc + + + C + + + Dr + + + Ef + + + F + + + G + + + Gh + + + H + + + Ho + + + JG + + + K + + + L + + + M + + + MN + + + O + + + P + + + Q + + + S + + + Sk + + + St + + + T + + + U + + + V + + + Vg + + + X + + + Li + + + N + + + Y + + + Q + + + BS + + + JG + + + A + + + B + + + BA + + + BL + + + BLu + + + BSt + + + BU + + + Bc + + + C + + + Dr + + + Ef + + + F + + + G + + + Gh + + + H + + + Ho + + + K + + + L + + + Li + + + M + + + MN + + + N + + + O + + + P + + + S + + + Sk + + + St + + + T + + + U + + + V + + + Vg + + + X + + + Y + + + Gh + + + Sk + + + Vg + + + Z + + + L + + + U + + + Cd + + + BA + + + BLu + + + BS + + + BSt + + + O + + + X + + + Dr + + + P + + + A + + + Ab + + + B + + + BA + + + BL + + + BLu + + + BS + + + BSt + + + BU + + + Bc + + + C + + + Ef + + + F + + + G + + + Gh + + + H + + + Ho + + + JG + + + K + + + L + + + Li + + + M + + + MN + + + N + + + O + + + Q + + + S + + + Sk + + + St + + + T + + + U + + + V + + + Vg + + + X + + + Y + + + M + + + AJ + + + Li + + + BA + + + P + + + T + + + BLu + + + Gh + + + JG + + + S + + + A + + + B + + + BU + + + C + + + Ho + + + K + + + M + + + MN + + + O + + + Sk + + + St + + + Vg + + + Ab + + + BL + + + BS + + + BSt + + + Bc + + + Dr + + + Ef + + + F + + + G + + + H + + + L + + + Li + + + N + + + Q + + + U + + + X + + + Y + + + V + + + Lu + + + Bc + + + St + + + V + + + JB + + + NR2 + + + V + + + Gh + + + S + + + JG + + + BLu + + + BA + + + P + + + Vg + + + BU + + + A + + + B + + + C + + + Ho + + + K + + + M + + + MN + + + O + + + Sk + + + St + + + Ab + + + N + + + Ef + + + H + + + BS + + + BSt + + + Bc + + + Dr + + + F + + + G + + + L + + + Q + + + U + + + X + + + Y + + + BL + + + Li + + + T + + + BU + + + D + + + A + + + Va + + + Ab + + + BU + + + T + + + N + + + Li + + + Ef + + + Gh + + + H + + + S + + + Vg + + + A + + + B + + + BA + + + BS + + + BSt + + + Bc + + + C + + + Dr + + + F + + + G + + + Ho + + + JG + + + K + + + L + + + M + + + MN + + + O + + + P + + + Q + + + Sk + + + St + + + U + + + V + + + X + + + Y + + + G + + + Ho + + + F + + + Q + + + N + + + A + + + B + + + BA + + + BSt + + + BU + + + Bc + + + C + + + Dr + + + Ef + + + F + + + Gh + + + H + + + Ho + + + JG + + + K + + + M + + + MN + + + O + + + P + + + S + + + Sk + + + St + + + T + + + U + + + V + + + Vg + + + X + + + Y + + + Li + + + BS + + + G + + + Q + + + L + + + R + + + LT + + + + + #END# + + + #START# + + + 10,2 + + + 10,3 + + + 10,4 + + + 11,2 + + + 11,3 + + + 11,4 + + + 11,5 + + + 12,2 + + + 12,3 + + + 12,4 + + + 13,2 + + + 13,3 + + + 14,2 + + + 6,2 + + + 7,1 + + + 7,3 + + + 7,4 + + + 7,5 + + + 7,6 + + + 7,7 + + + 8,1 + + + 8,2 + + + 8,3 + + + 8,4 + + + 8,5 + + + 8,6 + + + 9,2 + + + 9,3 + + + henricus + heinricus + spelling + Same word. One reading has a capital H, the other hasn't. + local + + + henricus + Henricus + orthographic + Same word. One reading has a capital H, the other hasn't. + local + + + in + ex + collated + Parsed together for rank 12 + local + + + anglia + Anglia + orthographic + local + + + svecia + suetia + orthographic + Same word. + local + + + svecia + swetia + orthographic + Same word. + local + + + swetia + swecia + orthographic + Same word. + local + + + swecia + Swecia + orthographic + Same word. + local + + + suecia + Swecia + orthographic + local + + + Venerabilis + uenerabilis + orthographic + local + + + Venerabilis + venerabilis + orthographic + global + + + uenerabilis + venerabilis + orthographic + local + + + henricus + pontifex + collated + local + Parsed together for rank 9 + + + diff --git a/t/text_tradition_collation_relationshipstore.t b/t/text_tradition_collation_relationshipstore.t index 01c888d..320832e 100644 --- a/t/text_tradition_collation_relationshipstore.t +++ b/t/text_tradition_collation_relationshipstore.t @@ -40,5 +40,63 @@ is( scalar @v3, 0, "Nothing deleted on non-existent relationship" ); +# =begin testing +{ +use Text::Tradition; +use TryCatch; + +my $t1 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' ); +# Test 1: try to equate nodes that are prevented with an intermediate collation +ok( $t1, "Parsed test fragment file" ); +my $c1 = $t1->collation; +my $trel = $c1->get_relationship( '9,2', '9,3' ); +is( ref( $trel ), 'Text::Tradition::Collation::Relationship', + "Troublesome relationship exists" ); +is( $trel->type, 'collated', "Troublesome relationship is a collation" ); + +# Try to make the link we want +try { + $c1->add_relationship( '8,6', '10,3', { 'type' => 'orthographic' } ); + ok( 1, "Added cross-collation relationship as expected" ); +} catch { + ok( 0, "Existing collation blocked equivalence relationship" ); +} + +try { + $c1->calculate_ranks(); + ok( 1, "Successfully calculated ranks" ); +} catch { + ok( 0, "Collation now has a cycle" ); +} + +# Test 2: try to equate nodes that are prevented with a real intermediate +# equivalence + +my $t2 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' ); +# Test 1: try to equate nodes that are prevented with an intermediate collation +my $c2 = $t2->collation; +$c2->add_relationship( '9,2', '9,3', { 'type' => 'lexical' } ); +my $trel2 = $c2->get_relationship( '9,2', '9,3' ); +is( ref( $trel2 ), 'Text::Tradition::Collation::Relationship', + "Created blocking relationship" ); +is( $trel2->type, 'lexical', "Blocking relationship is not a collation" ); +# This time the link ought to fail +try { + $c2->add_relationship( '8,6', '10,3', { 'type' => 'orthographic' } ); + ok( 0, "Existing equivalence blocked crossing relationship" ); +} catch { + ok( 1, "Added cross-equivalent bad relationship" ); +} + +try { + $c2->calculate_ranks(); + ok( 1, "Successfully calculated ranks" ); +} catch { + ok( 0, "Collation now has a cycle" ); +} +} + + + 1;