Const/t/20basemethods.t

filter: Statementstmt 100% 53 / 53 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 58 / 58 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Const/t/10iomethods.t ↑ Summary Const/t/30querymethods.t »
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl 1.t'
3  
4 #########################
5  
6 # change 'tests => 1' to 'tests => last_test_to_print';
7  
8 1 ▶use Test::More tests => 34;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 #01
12 1 ▶ use_ok('Lingua::Treebank::Const')
Subroutine BEGIN: called CC=1 SCAR=0.0
13 };
14  
15 #########################
16  
17 # Insert your test code below, the Test::More module is use()ed here so read
18 # its man page ( perldoc Test::More ) for help writing this test script.
19 1 ▶use constant PACK => 'Lingua::Treebank::Const';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 can_ok(PACK,
22 qw( is_root is_terminal ),
23 qw( insert_at append prepend ),
24 qw( prev_sib next_sib ),
25 qw( left_leaf right_leaf ),
26 qw( prev_leaf next_leaf ),
27 );
28  
29 1 my $d = PACK->new();
30  
31 1 ok( defined $d, "new() returned something" );
32  
33 1 isa_ok($d, PACK, 'root node');
34  
35 1 my $ex1 = <<EOEX1;
36 (S
37 (NP
38 (NNP Joe)
39 )
40 (VP
41 (VB likes)
42 (NP
43 (NNP Bach)
44 )
45 )
46 (. .)
47 )
48 EOEX1
49  
50 1 $d->from_penn_string($ex1);
51  
52 #05
53 1 ok(1, "passed from_penn_string");
54  
55 1 is( $d->tag(), 'S', 'top tag is "S"' );
56  
57 1 ok( ( $d->is_root() ) , 'top is root' );
58  
59 1 ok( not $d->is_terminal() );
60  
61 1 ok( (not defined $d->prev_sib() ), 'root node has no prev_sib');
62 #10
63 1 ok( (not defined $d->next_sib() ), 'root node has no next_sib');
64  
65  
66 1 my PACK $joe = $d->left_leaf();
67 1 isa_ok($joe, PACK, '"Joe" node');
68  
69 1 ok( $joe->is_terminal() , ' left leaf is terminal');
70  
71 1 is( $joe->tag(), 'NNP', ' leftmost tag is "NNP"');
72  
73 1 is( $joe->word(), 'Joe', ' leftmost word is "Joe"');
74  
75 #15
76 1 ok( (not $joe->is_root()) , ' leftmost not a root');
77  
78 1 ok( (not defined $joe->prev_leaf()), " leftmost's prev_leaf not defined");
79  
80 1 ok( ( not defined $joe->prev_sib() ), " leftmost has no immediate sib (l)");
81 1 ok( ( not defined $joe->next_sib() ), " leftmost has no immediate sib (r)");
82  
83 1 is ($joe->right_leaf(), $joe, ' right leaf of terminal is self');
84  
85 #20
86 1 is($joe->left_leaf(), $joe, ' left leaf of terminal is self');
87  
88 1 my $likes = $joe->next_leaf();
89  
90 1 isa_ok($likes, PACK, '"likes" node');
91  
92 1 is($likes->prev_leaf, $joe, ' next-previous is original');
93  
94 1 is($likes->word(), 'likes', ' "likes" node has right word');
95  
96  
97 1 is($likes->tag(), 'VB', '"likes" node has right tag');
98  
99 #25
100 1 isnt($likes->parent(), $joe->parent(),
101 '"Joe" and "likes" do not share a parent');
102  
103 1 is ($likes->parent()->parent(), $d, ' root is grandparent of "likes"');
104  
105 1 is ($joe->parent()->parent(), $d, ' root is grandparent of "joe"');
106  
107 1 my $rl = $d->right_leaf();
108  
109 1 isa_ok($rl, PACK, 'rightmost leaf');
110  
111 1 is($rl->word(), '.', "rightmost leaf is '.'");
112  
113 #30
114 1 is($rl->tag(), '.', "rightmost tag is '.'");
115  
116 1 ok( ( not defined $rl->next_sib() ),
117 "right-leaf has no next_sib" );
118  
119 1 is($rl->parent, $d, "rl parent is the root");
120  
121 1 is($rl->prev_sib(), $likes->parent(),
122 "rl's prev sib is the parent of likes");
123  
124 1 is($likes->parent->next_sib(), $rl,
125 'next sib of "likes"->parent is rl');
126  
127  
128  
129  
130  
« Const/t/10iomethods.t ↑ Summary Const/t/30querymethods.t »