t/*: remove "use lib '.'" and t/lib/Error.pm
[bioperl-live.git] / t / SeqFeature / RangeI.t
blob5bff03d1f968d4a57043888162dd2bfaecf72d84
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7     use Bio::Root::Test;
8     
9     test_begin(-tests => 45);
10         
11     use_ok('Bio::SeqFeature::Generic');
14 my @funcs = qw(start end length strand overlaps contains
15     equals intersection union overlap_extent disconnected_ranges
16     offsetStranded subtract);
18 my $i = 1;
19 while (my $func = shift @funcs ) {
20     $i++;
22     # test for presence of method
23     ok exists $Bio::RangeI::{$func};
24     
25     # union get caught in an infinite loop w/o parameters; skip invoke test.
26     next if $func eq 'union';
27     
28     # call to strand complains without a value; skip invoke test.
29     next if $func eq 'disconnected_ranges';
30     
31     # test invocation of method
32     eval { $Bio::RangeI::{$func}->(); };
33     ok($@);
36 ### unit tests for subtract method ###
37 # contributed by Stephen Montgomery (sm8 at sanger.ac.uk), who also
38 # wrote the subtract method
39 my $feature1 =  Bio::SeqFeature::Generic->new( -start => 1, -end =>
40 1000, -strand => 1);
41 my $feature2 =  Bio::SeqFeature::Generic->new( -start => 100, -end =>
42 900, -strand => -1);
44 my $subtracted = $feature1->subtract($feature2);
45 ok(defined($subtracted));
46 is(scalar(@$subtracted), 2);
47 foreach my $range (@$subtracted) {
48     ok($range->start == 1 || $range->start == 901);
49     ok($range->end == 99 || $range->end == 1000);
52 $subtracted = $feature2->subtract($feature1);
53 ok(!defined($subtracted));
54 $subtracted = $feature1->subtract($feature2, 'weak');
55 ok(!defined($subtracted));
56 $subtracted = $feature1->subtract($feature2, 'strong');
57 ok(!defined($subtracted));
59 my $feature3 =  Bio::SeqFeature::Generic->new( -start => 500, -end =>
60 1500, -strand => 1);
61 $subtracted = $feature1->subtract($feature3);
62 ok(defined($subtracted));
63 is scalar(@$subtracted), 1;
64 my $subtracted_i = @$subtracted[0];
65 is($subtracted_i->start, 1);
66 is($subtracted_i->end, 499);
69 # ---------------
70 # Added Bio::Location::SplitLocationI support to subtract().  --jhannah 20091018
71 $feature1 =  Bio::SeqFeature::Generic->new();
72 $feature2 =  Bio::SeqFeature::Generic->new();
73 my $loc = Bio::Location::Split->new();
74 $loc->add_sub_Location(Bio::Location::Simple->new(-start=>100, -end=>200, -strand=>1));
75 $loc->add_sub_Location(Bio::Location::Simple->new(-start=>300, -end=>400, -strand=>1));
76 $loc->add_sub_Location(Bio::Location::Simple->new(-start=>500, -end=>600, -strand=>1));
77 $feature1->location($loc);
78 $loc = Bio::Location::Split->new();
79 $loc->add_sub_Location(Bio::Location::Simple->new(-start=>350, -end=>400, -strand=>1));
80 $loc->add_sub_Location(Bio::Location::Simple->new(-start=>500, -end=>510, -strand=>1));
81 $feature2->location($loc);
82 $subtracted = $feature1->subtract($feature2);
83 is(@$subtracted, 3,                              "subtract() of split features");
84 is($subtracted->[0]->start, 100,                 "   0 start");
85 is($subtracted->[0]->end,   200,                 "   0 end");
86 is($subtracted->[1]->start, 300,                 "   1 start");
87 is($subtracted->[1]->end,   349,                 "   1 end");
88 is($subtracted->[2]->start, 511,                 "   2 start");
89 is($subtracted->[2]->end,   600,                 "   2 end");
90 # ---------------