Fix bug 253 testing for defined
[bioperl-live.git] / t / Phenotype / Phenotype.t
blob2c0d1c0ab0392cd81e529d9ee36a9926d0e1d44e
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7     use lib '.';
8     use Bio::Root::Test;
9     
10     test_begin(-tests => 116);
11         
12     use_ok('Bio::Phenotype::Phenotype');
13     use_ok('Bio::Species');
14     use_ok('Bio::Annotation::Reference');
15     use_ok('Bio::Map::CytoPosition');
16     use_ok('Bio::Phenotype::Correlate');
17     use_ok('Bio::Phenotype::Measure');
18     use_ok('Bio::Annotation::DBLink');
21 my $obj = Bio::Phenotype::Phenotype->new();
23 isa_ok( $obj, "Bio::Phenotype::PhenotypeI" );
24 isa_ok( $obj, "Bio::Phenotype::Phenotype" );
26 ok( $obj->name( "r1" ) );
27 is( $obj->name(), "r1" );
29 ok( $obj->description( "This is ..." ) );
30 is( $obj->description(), "This is ..." );
32 my $mouse = Bio::Species->new();
33 $mouse->classification( qw( musculus Mus ) );
34 ok( $obj->species( $mouse ) );
35 is( $obj->species()->binomial(), "Mus musculus" );
37 ok( $obj->comment( "putative" ) );
38 is( $obj->comment(), "putative" );
42 is( $obj->each_gene_symbol(), 0 );
44 ok( $obj->add_gene_symbols( ( "A", "B" ) ) );
45 is( $obj->each_gene_symbol(), 2 );
46 my @gs = $obj->each_gene_symbol();
47 is( $gs[ 0 ], "A" );
48 is( $gs[ 1 ], "B" );
49 is( $obj->each_gene_symbol(), 2 );
51 my @gs2 = $obj->remove_gene_symbols();
52 is( $gs2[ 0 ], "A" );
53 is( $gs2[ 1 ], "B" );
55 is( $obj->each_gene_symbol(), 0 );
56 is( $obj->remove_gene_symbols(), 0 );
60 my $v1 = Bio::Variation::VariantI->new();
61 my $v2 = Bio::Variation::VariantI->new();
63 $v1->length( "123" );
65 is( $obj->each_Variant(), 0 );
67 ok( $obj->add_Variants( ( $v1, $v2 ) ) );
68 is( $obj->each_Variant(), 2 );
69 my @vs = $obj->each_Variant();
70 is( $vs[ 0 ], $v1 );
71 is( $vs[ 1 ], $v2 );
72 is( $vs[ 0 ]->length(), "123" );
73 is( $obj->each_Variant(), 2 );
75 my @vs2 = $obj->remove_Variants();
76 is( $vs2[ 0 ], $v1 );
77 is( $vs2[ 1 ], $v2 );
79 is( $obj->each_Variant(), 0 );
80 is( $obj->remove_Variants(), 0 );
85 my $r1 = Bio::Annotation::Reference->new();
86 my $r2 = Bio::Annotation::Reference->new();
88 $r1->title( "title" );
90 is( $obj->each_Reference(), 0 );
92 ok( $obj->add_References( ( $r1, $r2 ) ) );
93 is( $obj->each_Reference(), 2 );
94 my @rs = $obj->each_Reference();
95 is( $rs[ 0 ]->display_text, $r1->display_text,'operator overloading in AnnotationI is deprecated');
96 is( $rs[ 1 ]->display_text, $r2->display_text,'operator overloading in AnnotationI is deprecated');
97 is( $rs[ 0 ]->title(), "title" );
98 is( $obj->each_Reference(), 2 );
100 my @rs2 = $obj->remove_References();
101 is( $rs2[ 0 ]->display_text, $r1->display_text,'operator overloading in AnnotationI is deprecated');
102 is( $rs2[ 1 ]->display_text, $r2->display_text,'operator overloading in AnnotationI is deprecated');
104 is( $obj->each_Reference(), 0 );
105 is( $obj->remove_References(), 0 );
110 my $c1 = Bio::Map::CytoPosition->new();
111 my $c2 = Bio::Map::CytoPosition->new();
113 $c1->chr( "12" );
115 is( $obj->each_CytoPosition(), 0 );
117 ok( $obj->add_CytoPositions( ( $c1, $c2 ) ) );
118 is( $obj->each_CytoPosition(), 2 );
119 my @cs = $obj->each_CytoPosition();
120 is( $cs[ 0 ], $c1 );
121 is( $cs[ 1 ], $c2 );
122 is( $cs[ 0 ]->chr(), 12 );
123 is( $obj->each_CytoPosition(), 2 );
125 my @cs2 = $obj->remove_CytoPositions();
126 is( $cs2[ 0 ], $c1 );
127 is( $cs2[ 1 ], $c2 );
129 is( $obj->each_CytoPosition(), 0 );
130 is( $obj->remove_CytoPositions(), 0 );
135 my $co1 = Bio::Phenotype::Correlate->new();
136 my $co2 = Bio::Phenotype::Correlate->new();
138 ok( $co1->name( "name" ) );
140 is( $obj->each_Correlate(), 0 );
142 ok( $obj->add_Correlates( ( $co1, $co2 ) ) );
143 is( $obj->each_Correlate(), 2 );
144 my @cos = $obj->each_Correlate();
145 is( $cos[ 0 ], $co1 );
146 is( $cos[ 1 ], $co2 );
147 is( $cos[ 0 ]->name, "name" );
148 is( $obj->each_Correlate(), 2 );
150 my @cos2 = $obj->remove_Correlates();
151 is( $cos2[ 0 ], $co1 );
152 is( $cos2[ 1 ], $co2 );
154 is( $obj->each_Correlate(), 0 );
155 is( $obj->remove_Correlates(), 0 );
160 my $m1 = Bio::Phenotype::Measure->new();
161 my $m2 = Bio::Phenotype::Measure->new();
163 ok( $m1->description( "desc" ) );
165 is( $obj->each_Measure(), 0 );
167 ok( $obj->add_Measures( ( $m1, $m2 ) ) );
168 is( $obj->each_Measure(), 2 );
169 my @ms = $obj->each_Measure();
170 is( $ms[ 0 ], $m1 );
171 is( $ms[ 1 ], $m2 );
172 is( $ms[ 0 ]->description, "desc" );
173 is( $obj->each_Measure(), 2 );
175 my @ms2 = $obj->remove_Measures();
176 is( $ms2[ 0 ], $m1 );
177 is( $ms2[ 1 ], $m2 );
179 is( $obj->each_Measure(), 0 );
180 is( $obj->remove_Measures(), 0 );
184 is( $obj->each_keyword(), 0 );
186 ok( $obj->add_keywords( ( "A", "B" ) ) );
187 is( $obj->each_keyword(), 2 );
188 my @ks = $obj->each_keyword();
189 is( $ks[ 0 ], "A" );
190 is( $ks[ 1 ], "B" );
191 is( $obj->each_keyword(), 2 );
193 my @ks2 = $obj->remove_keywords();
194 is( $ks2[ 0 ], "A" );
195 is( $ks2[ 1 ], "B" );
197 is( $obj->each_keyword(), 0 );
198 is( $obj->remove_keywords(), 0 );
202 my $l1 = Bio::Annotation::DBLink->new();
203 my $l2 = Bio::Annotation::DBLink->new();
205 ok( $l1->comment( "comment" ) );
207 is( $obj->each_DBLink(), 0 );
209 ok( $obj->add_DBLinks( ( $l1, $l2 ) ) );
210 is( $obj->each_DBLink(), 2 );
211 my @ls = $obj->each_DBLink();
212 is( $ls[ 0 ]->display_text, $l1->display_text,'operator overloading in AnnotationI is deprecated');
213 is( $ls[ 1 ]->display_text, $l2->display_text,'operator overloading in AnnotationI is deprecated');
214 is( $ls[ 0 ]->comment(), "comment" );
215 is( $obj->each_DBLink(), 2 );
217 my @ls2 = $obj->remove_DBLinks();
218 is( $ls2[ 0 ]->display_text, $l1->display_text,'operator overloading in AnnotationI is deprecated');
219 is( $ls2[ 1 ]->display_text, $l2->display_text,'operator overloading in AnnotationI is deprecated');
221 is( $obj->each_DBLink(), 0 );
222 is( $obj->remove_DBLinks(), 0 );
226 is( $obj->each_Genotype(), 0 );
228 ok( $obj->add_Genotypes( ( "A", "B" ) ) );
229 is( $obj->each_Genotype(), 2 );
230 my @gts = $obj->each_Genotype();
231 is( $gts[ 0 ], "A" );
232 is( $gts[ 1 ], "B" );
233 is( $obj->each_Genotype(), 2 );
235 my @gts2 = $obj->remove_Genotypes();
236 is( $gts2[ 0 ], "A" );
237 is( $gts2[ 1 ], "B" );
239 is( $obj->each_Genotype(), 0 );
240 is( $obj->remove_Genotypes(), 0 );