tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / t / Ontology / Term.t
blob0892f113e896a9b388115fc99611a934acffbe4c
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 => 54,
11                            -requires_module => 'Graph::Directed');
12         
13         use_ok('Bio::Ontology::Term');
14         use_ok('Bio::Ontology::TermFactory');
15         use_ok('Bio::Annotation::DBLink');
18 my $obj = Bio::Ontology::Term->new();
20 isa_ok $obj, "Bio::Ontology::TermI";
22 is( $obj->identifier( "0003947" ), "0003947" );
23 is( $obj->identifier(), "0003947" );
25 is( $obj->name( "N-acetylgalactosaminyltransferase" ), "N-acetylgalactosaminyltransferase" );
26 is( $obj->name(), "N-acetylgalactosaminyltransferase" );
28 is( $obj->definition( "Catalysis of ..." ), "Catalysis of ..." );
29 is( $obj->definition(), "Catalysis of ..." );
31 is( $obj->version( "666" ), "666" );
32 is( $obj->version(), "666" );
34 ok( $obj->ontology( "category 1 name" ) );
35 is( $obj->ontology()->name(), "category 1 name" );
37 my $ont = Bio::Ontology::Ontology->new();
38 ok( $ont->name( "category 2 name" ) );
40 ok( $obj->ontology( $ont ) );
41 is( $obj->ontology()->name(), "category 2 name" );
43 is( $obj->is_obsolete( 1 ), 1 );
44 is( $obj->is_obsolete(), 1 );
46 is( $obj->comment( "Consider the term ..." ), "Consider the term ..." );
47 is( $obj->comment(), "Consider the term ..." );
49 is( $obj->get_synonyms(), 0 );
51 $obj->add_synonym( ( "AA", "AB" ) );
52 my @al1 = $obj->get_synonyms();
53 is( scalar(@al1), 2 );
54 is( $al1[ 0 ], "AA" );
55 is( $al1[ 1 ], "AB" );
57 my @al2 = $obj->remove_synonyms();
58 is( $al2[ 0 ], "AA" );
59 is( $al2[ 1 ], "AB" );
61 is( $obj->get_synonyms(), 0 );
62 is( $obj->remove_synonyms(), 0 );
64 $obj->add_synonyms( ( "AA", "AB" ) );
66 is( $obj->identifier(undef), undef );
67 is( $obj->name(undef), undef );
68 is( $obj->definition(undef), undef );
69 is( $obj->is_obsolete(0), 0 );
70 is( $obj->comment(undef), undef );
73 $obj = Bio::Ontology::Term->new( 
74     -identifier  => "0016847",
75     -name        => "1-aminocyclopropane-1-carboxylate synthase",
76     -definition  => "Catalysis of ...",
77     -is_obsolete => 0,
78     -version     => "6.6.6",
79     -ontology    => "cat",
80     -comment     => "X",
81     -dbxrefs    => [
82         Bio::Annotation::DBLink->new(-database => 'db1'),
83         Bio::Annotation::DBLink->new(-database => 'db2')
84     ],
85     -references => []
86 );  
88 is( $obj->identifier(), "0016847" );
89 is( $obj->name(), "1-aminocyclopropane-1-carboxylate synthase" );
90 is( $obj->definition(), "Catalysis of ..." );
91 is( $obj->is_obsolete(), 0);
92 is( $obj->comment(), "X" );
93 is( $obj->version(), "6.6.6" );
94 is( $obj->ontology()->name(), "cat" );
95 is( scalar($obj->get_dbxrefs), 2);
96 is( scalar($obj->get_references), 0);
98 # test object factory for terms
99 my $fact = Bio::Ontology::TermFactory->new();
100 $obj = $fact->create_object(-name => "some ontology term");
101 isa_ok $obj, "Bio::Ontology::TermI";
102 is ($obj->name, "some ontology term");
104 $fact->type("Bio::Ontology::GOterm");
105 $obj = $fact->create_object(-name => "some ontology term",
106                             -identifier => "GO:987654");
107 isa_ok $obj, "Bio::Ontology::TermI";
108 isa_ok $obj, "Bio::Ontology::GOterm";
109 is ($obj->name, "some ontology term");
110 is ($obj->identifier, "GO:987654");
112 $fact->type("Bio::Annotation::OntologyTerm");
113 $obj = $fact->create_object(-name => "some ontology term",
114                             -identifier => "GO:987654",
115                             -ontology => "nonsense");
116 isa_ok $obj, "Bio::Ontology::TermI";
117 isa_ok $obj, "Bio::AnnotationI";
118 is ($obj->name, "some ontology term");
119 is ($obj->identifier, "GO:987654");
120 is ($obj->tagname, "nonsense");