Commit | Line | Data |
b0b4421a |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use Test::More 'no_plan'; |
5 | $| = 1; |
6 | |
7 | |
8 | |
9 | # =begin testing |
10 | { |
11 | use Text::Tradition; |
ee801e17 |
12 | use TryCatch; |
b0b4421a |
13 | |
14 | use_ok( 'Text::Tradition::Collation::RelationshipStore' ); |
ee801e17 |
15 | |
16 | # Add some relationships, and delete them |
17 | |
18 | my $cxfile = 't/data/Collatex-16.xml'; |
19 | my $t = Text::Tradition->new( |
20 | 'name' => 'inline', |
21 | 'input' => 'CollateX', |
22 | 'file' => $cxfile, |
23 | ); |
24 | my $c = $t->collation; |
25 | |
f8331a4d |
26 | my @v1 = $c->add_relationship( 'n21', 'n22', { 'type' => 'lexical' } ); |
ee801e17 |
27 | is( scalar @v1, 1, "Added a single relationship" ); |
28 | is( $v1[0]->[0], 'n21', "Got correct node 1" ); |
29 | is( $v1[0]->[1], 'n22', "Got correct node 2" ); |
679f17e1 |
30 | my @v2 = $c->add_relationship( 'n24', 'n23', |
ee801e17 |
31 | { 'type' => 'spelling', 'scope' => 'global' } ); |
32 | is( scalar @v2, 2, "Added a global relationship with two instances" ); |
33 | @v1 = $c->del_relationship( 'n22', 'n21' ); |
34 | is( scalar @v1, 1, "Deleted first relationship" ); |
679f17e1 |
35 | @v2 = $c->del_relationship( 'n12', 'n13' ); |
ee801e17 |
36 | is( scalar @v2, 2, "Deleted second global relationship" ); |
681893aa |
37 | my @v3 = $c->del_relationship( 'n1', 'n2' ); |
38 | is( scalar @v3, 0, "Nothing deleted on non-existent relationship" ); |
b0b4421a |
39 | } |
40 | |
41 | |
42 | |
6d381462 |
43 | # =begin testing |
44 | { |
45 | use Text::Tradition; |
46 | use TryCatch; |
47 | |
48 | my $t1 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' ); |
49 | # Test 1: try to equate nodes that are prevented with an intermediate collation |
50 | ok( $t1, "Parsed test fragment file" ); |
51 | my $c1 = $t1->collation; |
414cc046 |
52 | ## HACK |
53 | $c1->calculate_ranks(); |
6d381462 |
54 | my $trel = $c1->get_relationship( '9,2', '9,3' ); |
55 | is( ref( $trel ), 'Text::Tradition::Collation::Relationship', |
56 | "Troublesome relationship exists" ); |
57 | is( $trel->type, 'collated', "Troublesome relationship is a collation" ); |
58 | |
59 | # Try to make the link we want |
60 | try { |
61 | $c1->add_relationship( '8,6', '10,3', { 'type' => 'orthographic' } ); |
62 | ok( 1, "Added cross-collation relationship as expected" ); |
63 | } catch { |
64 | ok( 0, "Existing collation blocked equivalence relationship" ); |
65 | } |
66 | |
67 | try { |
68 | $c1->calculate_ranks(); |
69 | ok( 1, "Successfully calculated ranks" ); |
70 | } catch { |
71 | ok( 0, "Collation now has a cycle" ); |
72 | } |
73 | |
74 | # Test 2: try to equate nodes that are prevented with a real intermediate |
75 | # equivalence |
76 | |
77 | my $t2 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' ); |
78 | # Test 1: try to equate nodes that are prevented with an intermediate collation |
79 | my $c2 = $t2->collation; |
414cc046 |
80 | ## HACK |
81 | $c2->calculate_ranks(); |
6d381462 |
82 | $c2->add_relationship( '9,2', '9,3', { 'type' => 'lexical' } ); |
83 | my $trel2 = $c2->get_relationship( '9,2', '9,3' ); |
84 | is( ref( $trel2 ), 'Text::Tradition::Collation::Relationship', |
85 | "Created blocking relationship" ); |
86 | is( $trel2->type, 'lexical', "Blocking relationship is not a collation" ); |
87 | # This time the link ought to fail |
88 | try { |
89 | $c2->add_relationship( '8,6', '10,3', { 'type' => 'orthographic' } ); |
90 | ok( 0, "Existing equivalence blocked crossing relationship" ); |
91 | } catch { |
92 | ok( 1, "Added cross-equivalent bad relationship" ); |
93 | } |
94 | |
95 | try { |
96 | $c2->calculate_ranks(); |
97 | ok( 1, "Successfully calculated ranks" ); |
98 | } catch { |
99 | ok( 0, "Collation now has a cycle" ); |
100 | } |
101 | } |
102 | |
103 | |
104 | |
b0b4421a |
105 | |
106 | 1; |