1 # -*-Perl-*- Test Harness script for Bioperl
9 test_begin(-tests => 49);
14 my $range = Bio::Range->new(-start=>10,
18 isa_ok($range,'Bio::Range', 'BioRange object');
19 is($range->strand, 1);
21 my $range2 = Bio::Range->new(-start=>15,
25 isa_ok($range2,'Bio::Range', 'BioRange object');
26 is($range2->strand, 1);
28 my $r = Bio::Range->new();
29 is ( $r->strand(0), 0 ) ;
30 is ( $r->start(27), 27 );
31 is ( $r->end(28), 28 ) ;
33 ok(! defined $r->intersection($range2));
35 $r = $range->union($range2);
39 $r = $range->intersection($range2);
40 is ( $r->start, 15 ) ;
44 # intersection and union can also take lists
45 my $range3 = Bio::Range->new(-start=>18,-end=>30);
46 isa_ok($range3,'Bio::Range', 'BioRange object');
48 $r = $range->intersection([$range2, $range3]);
49 ok( ( $r->start == 18 ) && ( $r->end == 20 ));
50 $r = Bio::Range->intersection([$range, $range2, $range3]);
51 ok($r->start == 18 && $r->end == 20);
52 $r = $range->union($range2, $range3);
53 ok( ( $r->start == 10 ) && ( $r->end == 30 ) );
54 $r = Bio::Range->union($range, $range2, $range3);
55 ok( ( $r->start == 10 ) && ( $r->end == 30 ) );
57 ok (! $range->intersection([$range2, $range3]));
59 ok (! $range->contains($range2));
60 ok (! $range2->contains($range));
61 ok ($range->overlaps($range2));
62 ok ($range2->overlaps($range));
65 $range3 = Bio::Range->new(-start => 15,
69 my $range4 = Bio::Range->new(-start => 15,
73 isa_ok($range4,'Bio::Range', 'BioRange object');
75 my $range5 = Bio::Range->new(-start => 15,
79 isa_ok($range5,'Bio::Range', 'BioRange object');
81 my $range6 = Bio::Range->new(-start => 20,
85 isa_ok($range6,'Bio::Range', 'BioRange object');
87 ok $range3->_ignore($range4), ' 1 & -1' ;
88 ok $range3->_weak($range3),' 1 & 1 true' ;
89 ok $range3->_weak($range5), ' 1 & 0 true' ;
90 ok (! $range3->_weak($range4), ' 1 & -1 false' );
91 ok $range3->_strong($range3), ' 1 & 1 true' ;
92 ok (! $range3->_strong($range5), ' 1 & 0 false' );
93 ok (! $range3->_strong($range4), ' 1 & -1 false' );
95 ok ! ( $range3->overlaps($range4,'weak'));
96 ok ! ( $range4->overlaps($range3,'weak'));
97 ok ! ( $range3->overlaps($range4,'strong'));
98 ok ! ( $range4->overlaps($range3,'strong'));
102 ok ( $range3->overlaps($range4,'weak'));
103 ok ( $range4->overlaps($range3,'weak'));
104 ok ! ( $range3->overlaps($range4,'strong'));
105 ok ! ( $range4->overlaps($range3,'strong'));
107 # if strands are different then intersection() should return 0...
108 $r = $range3->intersection($range4);
109 is ( $r->strand, 0 );
111 # or if both strands are -1 then -1 should be returned
112 $r = $range6->intersection($range4);
113 is ( $r->strand, -1 );
115 # test implemention of offsetStranded:
116 $r = Bio::Range->new(-start => 30, -end => 40, -strand => -1);
117 isa_ok($r, 'Bio::Range', 'Bio::Range object') ;
118 is ($r->offsetStranded(-5,10)->toString, '(20, 45) strand=-1');
119 is ($r->offsetStranded(+5,-10)->toString, '(30, 40) strand=-1');
121 is ($r->offsetStranded(-5,10)->toString, '(25, 50) strand=1');
122 is ($r->offsetStranded(+5,-10)->toString, '(30, 40) strand=1');