1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 49);
15 my $range = Bio::Range->new(-start=>10,
19 isa_ok($range,'Bio::Range', 'BioRange object');
20 is($range->strand, 1);
22 my $range2 = Bio::Range->new(-start=>15,
26 isa_ok($range2,'Bio::Range', 'BioRange object');
27 is($range2->strand, 1);
29 my $r = Bio::Range->new();
30 is ( $r->strand(0), 0 ) ;
31 is ( $r->start(27), 27 );
32 is ( $r->end(28), 28 ) ;
34 ok(! defined $r->intersection($range2));
36 $r = $range->union($range2);
40 $r = $range->intersection($range2);
41 is ( $r->start, 15 ) ;
45 # intersection and union can also take lists
46 my $range3 = Bio::Range->new(-start=>18,-end=>30);
47 isa_ok($range3,'Bio::Range', 'BioRange object');
49 $r = $range->intersection([$range2, $range3]);
50 ok( ( $r->start == 18 ) && ( $r->end == 20 ));
51 $r = Bio::Range->intersection([$range, $range2, $range3]);
52 ok($r->start == 18 && $r->end == 20);
53 $r = $range->union($range2, $range3);
54 ok( ( $r->start == 10 ) && ( $r->end == 30 ) );
55 $r = Bio::Range->union($range, $range2, $range3);
56 ok( ( $r->start == 10 ) && ( $r->end == 30 ) );
58 ok (! $range->intersection([$range2, $range3]));
60 ok (! $range->contains($range2));
61 ok (! $range2->contains($range));
62 ok ($range->overlaps($range2));
63 ok ($range2->overlaps($range));
66 $range3 = Bio::Range->new(-start => 15,
70 my $range4 = Bio::Range->new(-start => 15,
74 isa_ok($range4,'Bio::Range', 'BioRange object');
76 my $range5 = Bio::Range->new(-start => 15,
80 isa_ok($range5,'Bio::Range', 'BioRange object');
82 my $range6 = Bio::Range->new(-start => 20,
86 isa_ok($range6,'Bio::Range', 'BioRange object');
88 ok $range3->_ignore($range4), ' 1 & -1' ;
89 ok $range3->_weak($range3),' 1 & 1 true' ;
90 ok $range3->_weak($range5), ' 1 & 0 true' ;
91 ok (! $range3->_weak($range4), ' 1 & -1 false' );
92 ok $range3->_strong($range3), ' 1 & 1 true' ;
93 ok (! $range3->_strong($range5), ' 1 & 0 false' );
94 ok (! $range3->_strong($range4), ' 1 & -1 false' );
96 ok ! ( $range3->overlaps($range4,'weak'));
97 ok ! ( $range4->overlaps($range3,'weak'));
98 ok ! ( $range3->overlaps($range4,'strong'));
99 ok ! ( $range4->overlaps($range3,'strong'));
103 ok ( $range3->overlaps($range4,'weak'));
104 ok ( $range4->overlaps($range3,'weak'));
105 ok ! ( $range3->overlaps($range4,'strong'));
106 ok ! ( $range4->overlaps($range3,'strong'));
108 # if strands are different then intersection() should return 0...
109 $r = $range3->intersection($range4);
110 is ( $r->strand, 0 );
112 # or if both strands are -1 then -1 should be returned
113 $r = $range6->intersection($range4);
114 is ( $r->strand, -1 );
116 # test implemention of offsetStranded:
117 $r = Bio::Range->new(-start => 30, -end => 40, -strand => -1);
118 isa_ok($r, 'Bio::Range', 'Bio::Range object') ;
119 is ($r->offsetStranded(-5,10)->toString, '(20, 45) strand=-1');
120 is ($r->offsetStranded(+5,-10)->toString, '(30, 40) strand=-1');
122 is ($r->offsetStranded(-5,10)->toString, '(25, 50) strand=1');
123 is ($r->offsetStranded(+5,-10)->toString, '(30, 40) strand=1');