File: RangeI.t

package info (click to toggle)
bioperl 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 40,768 kB
  • ctags: 12,005
  • sloc: perl: 174,299; xml: 13,923; sh: 1,941; lisp: 1,803; asm: 109; makefile: 53
file content (67 lines) | stat: -rw-r--r-- 1,924 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*-Perl-*- Test Harness script for Bioperl
# $Id: RangeI.t 15112 2008-12-08 18:12:38Z sendu $

use strict;

BEGIN {
    use lib '.';
    use Bio::Root::Test;
    
    test_begin(-tests => 38);
	
    use_ok('Bio::SeqFeature::Generic');
}

my @funcs = qw(start end length strand overlaps contains
    equals intersection union overlap_extent disconnected_ranges
    offsetStranded subtract);

my $i = 1;
while (my $func = shift @funcs ) {
    $i++;

    # test for presence of method
    ok exists $Bio::RangeI::{$func};
    
    # union get caught in an infinite loop w/o parameters; skip invoke test.
    next if $func eq 'union';
    
    # call to strand complains without a value; skip invoke test.
    next if $func eq 'disconnected_ranges';
    
    # test invocation of method
    eval { $Bio::RangeI::{$func}->(); };
    ok($@);
}

### unit tests for subtract method ###
# contributed by Stephen Montgomery (sm8 at sanger.ac.uk), who also
# wrote the subtract method
my $feature1 =  Bio::SeqFeature::Generic->new( -start => 1, -end =>
1000, -strand => 1);
my $feature2 =  Bio::SeqFeature::Generic->new( -start => 100, -end =>
900, -strand => -1);

my $subtracted = $feature1->subtract($feature2);
ok(defined($subtracted));
is(scalar(@$subtracted), 2);
foreach my $range (@$subtracted) {
    ok($range->start == 1 || $range->start == 901);
    ok($range->end == 99 || $range->end == 1000);
}

$subtracted = $feature2->subtract($feature1);
ok(!defined($subtracted));
$subtracted = $feature1->subtract($feature2, 'weak');
ok(!defined($subtracted));
$subtracted = $feature1->subtract($feature2, 'strong');
ok(!defined($subtracted));

my $feature3 =  Bio::SeqFeature::Generic->new( -start => 500, -end =>
1500, -strand => 1);
$subtracted = $feature1->subtract($feature3);
ok(defined($subtracted));
is scalar(@$subtracted), 1;
my $subtracted_i = @$subtracted[0];
is($subtracted_i->start, 1);
is($subtracted_i->end, 499);