Sync'ed RichSeqI with the implementation. RichSeq provides backward
[bioperl-live.git] / t / Map.t
bloba82a227d3397fa5fe285a4d2f736fab4fa30fef2
1 # -*-Perl-*-
2 ## Bioperl Test Harness Script for Modules
3 ## $Id$
6 use strict;
8 BEGIN {
9     use vars qw($DEBUG);
10     $DEBUG = $ENV{'BIOPERLDEBUG'};
11     # to handle systems with no installed Test module
12     # we include the t dir (where a copy of Test.pm is located)
13     # as a fallback
14     eval { require Test; };
15     if( $@ ) {
16         use lib 't';
17     }
18     use Test;
19     plan tests => 48;
22 END {
26 # Let's test first the map class : Bio::Map::SimpleMap
28 use Data::Dumper;
29 use Bio::Map::SimpleMap;
30 ok 1;
32 ok my $map = new Bio::Map::SimpleMap(-name  => 'my');
33 ok $map->type('cyto'); 
34 ok $map->type, 'cyto'; 
35 ok $map->units, ''; 
36 ok $map->length, 0, "Length is ". $map->length;
37 ok $map->name, 'my';
38 ok $map->species('human'), 'human';
39 ok $map->species, 'human';
40 ok $map->unique_id, '1';
44 # Secondly, create Markers for the Map
47 use Bio::Map::Marker;
48 ok 1;
51 # Four ways of adding a position:
53 # 1. position gets a map object and a value as arguments
55 ok my $marker1 = new Bio::Map::Marker();
56 ok $marker1->name('gene1'), 'Unnamed marker' ;
57 ok $marker1->name(), 'gene1';
59 ok $marker1->position($map, 100);
60 ok $marker1->position->value, 100;
61 ok $marker1->map, $map;
65 # Now that we have a Marker, let's 
66 #    make sure the basic Position class works
69 use Bio::Map::Position;
70 ok 1;
71 ok my $pos = new Bio::Map::Position();
72 ok $pos->map($map);
73 ok $pos->map(), $map;
74 ok $pos->marker($marker1);
75 ok $pos->marker(), $marker1;
77 ok $pos->value('999');
78 ok $pos->value(), '999';
79 ok $pos->numeric, 999;
81 # ... and then continue testing the Marker
83 # 2. position is set in the constructor
84 ok my $marker2 = new Bio::Map::Marker(-name => 'gene2',
85                                       -position => [$map, 200]
86                                       );
87 ok ( $marker2->map, $map);
88 ok ($marker2->position->value, 200);
90 # 3. marker is first added into map, 
91 #    then marker knows the the position belongs to
92 ok my $marker3 = new Bio::Map::Marker(-name => 'gene3');
93 ok $map->add_element($marker3);
94 ok $marker3->map, $map;
95 ok $marker3->position(300);
96 ok $marker3->position->value, 300;
97 ok my $position = $marker3->position($map);
99 # 4. A Position is explicitely created
100 ok my $cpos = new Bio::Map::Position(-map => $map,
101                                      -value => 500);
102 ok $marker3->position($cpos);
103 my $cpos2 = $marker3->position($cpos);
104 ok $cpos2 eq $cpos;
105 ok $marker3->position->value, 500;
109 # Next, what do markers know about Maps?
112 ok (scalar ($marker3->known_maps), 1); 
113 ok $marker3->in_map(1);
114 ok ! $marker3->in_map(2);
119 # Lastly, let's test the comparison methods
122 ok $marker1->equals($marker1);
123 ok ! $marker1->equals($marker3);
124 ok $marker1->less_than($marker3);
125 ok ! $marker1->greater_than($marker3);
126 ok ! $marker3->less_than($marker1);
127 ok $marker3->greater_than($marker1);