Skip to content

Commit

Permalink
added tests for creating objects and lines, adding lines, testing for…
Browse files Browse the repository at this point in the history
…matted switch point files. Re #26
  • Loading branch information
suryasaha committed May 13, 2015
1 parent f6cb53a commit 88fed66
Showing 1 changed file with 47 additions and 12 deletions.
59 changes: 47 additions & 12 deletions t/GenomeUpdate/sp.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

=head1 NAME
tpf.t
A test for Bio::GenomeUpdate::SP class
sp.t - A test for Bio::GenomeUpdate::SP class
=cut

Expand All @@ -27,6 +26,8 @@ use warnings;
use autodie;

use Test::More tests => 1;
use Test::Exception;

BEGIN {use_ok( 'Bio::GenomeUpdate::SP' ); }
require_ok( 'Bio::GenomeUpdate::SP::SPLine' );

Expand All @@ -39,8 +40,8 @@ ok(my $sp_line1 = Bio::GenomeUpdate::SP::SPLine->new(
accession_suffix_orientation => '-',
accession_prefix_last_base => 100,
accession_suffix_first_base => 200,
comment => 'test line 1 comment'
));
comment => 'test line 1 comment some nonsense here and here too'
), 'created $sp_line1');
#create another sp line
ok(my $sp_line2 = Bio::GenomeUpdate::SP::SPLine->new(
chromosome => 1,
Expand All @@ -50,19 +51,53 @@ ok(my $sp_line2 = Bio::GenomeUpdate::SP::SPLine->new(
accession_suffix_orientation => '-',
accession_prefix_last_base => 300,
accession_suffix_first_base => 100,
comment => 'test line 1 comment'
));

#get various values and test

comment => 'test line 2 comment some nonsense here and here too'
),'created $sp_line2');

#get various values
is($sp_line1->get_chromosome(), 'Un', 'Got correct chr from $sp_line1');
is($sp_line1->get_accession_prefix(), 'accession1', 'Got correct accession_prefix from $sp_line1');
is($sp_line1->get_accession_suffix(), 'accession2', 'Got correct accession_suffix from $sp_line1');
is($sp_line1->get_accession_prefix_orientation(), '+', 'Got correct accession_prefix_orientation from $sp_line1');
is($sp_line1->get_accession_suffix_orientation(), '-', 'Got correct accession_suffix_orientation from $sp_line1');
is($sp_line1->get_accession_prefix_last_base(), 100, 'Got correct accession_prefix_last_base from $sp_line1');
is($sp_line1->get_accession_suffix_first_base(), 200, 'Got correct accession_suffix_first_base from $sp_line1');
is($sp_line1->get_comment(), 'test line 1 comment some nonsense here and here too', 'Got correct comment from $sp_line1');

#test for type checks
throws_ok{$sp_line1->set_chromosome(13)} qr/not a valid chromosome number/, "invalid chr exception caught";
throws_ok{$sp_line1->set_accession_prefix_orientation('3')} qr/not a valid orientation type/, "invalid orientation exception caught";
throws_ok{$sp_line1->set_accession_prefix_last_base(-1)} qr/not a positive coordinate/, "negative coordinate exception caught";
throws_ok{$sp_line1->set_accession_suffix_first_base('A')} qr/not a positive coordinate/, "character coordinate exception caught";
throws_ok{$sp_line1->set_comment('short comment')} qr/shorter than the minimum length/, "short comment exception caught";

#add to SP object

ok(my $sp = Bio::GenomeUpdate::SP->new(
taxid => '001',
assembly_group => 'TGP',
assembly_unit => 'Primary',
tpf_type => 'chromosome',
), 'Created sp object');
ok ($sp->add_line_to_end($sp_line1), 'added $sp_line1');
ok ($sp->add_line_to_end($sp_line2), 'added $sp_line2');

#print out SP object and compare to string

ok(my $sp_file_string = $sp->get_formatted_sp(), 'got switch point file content' );
print $sp_file_string;
my $expected_sp_file_string = q(001 TGP Primary Un chromosome accession1 accession2 + - 100 200 test line 1 comment some nonsense here and here too
001 TGP Primary 1 chromosome accession3 accession4 - - 300 100 test line 2 comment some nonsense here and here too
);
ok( $sp_file_string eq $expected_sp_file_string, 'switch point file content looks good ' );

#modify values for #sp_line1 and add to SP object

ok($sp_line1->set_accession_prefix_last_base(110), 'Set accession_prefix_last_base in $sp_line1');
ok($sp_line1->set_accession_suffix_first_base(210), 'Set accession_suffix_first_base in $sp_line1');
ok ($sp->add_line_to_end($sp_line1), 'added modified $sp_line1');

#print out SP object and compare to string
ok($sp_file_string = $sp->get_formatted_sp(), 'got switch point file content again' );
$expected_sp_file_string = q(001 TGP Primary Un chromosome accession1 accession2 + - 110 210 test line 1 comment some nonsense here and here too
001 TGP Primary 1 chromosome accession3 accession4 - - 300 100 test line 2 comment some nonsense here and here too
001 TGP Primary Un chromosome accession1 accession2 + - 110 210 test line 1 comment some nonsense here and here too
); #$sp_line1 also changes as its a hashref
ok( $sp_file_string eq $expected_sp_file_string, 'modified switch point file content looks good' );

0 comments on commit 88fed66

Please sign in to comment.