Permalink
Browse files

Error on out of bounds

  • Loading branch information...
1 parent d714c2b commit f35a5259b9b5ca49e14935fc27660e50dee9fddd @pjotrp committed May 20, 2014
Showing with 6 additions and 2 deletions.
  1. +4 −1 lib/bigbio/db/fasta/fastagenomereader.rb
  2. +2 −1 spec/fastareader_spec.rb
@@ -26,7 +26,10 @@ def value pos
def in_range? chr,pos
return false if chr != @chr
- @offset <= pos and pos < @offset+@buf.size
+ if pos < @offset
+ raise "Position <#{pos}> in #{chr} out of bounds! Can not look backwards beyond buffer offset #{@offset}"
+ end
+ pos < @offset+@buf.size
end
def move_offset
View
@@ -13,6 +13,7 @@
@genome.ref('X',112).should == 'A'
@genome.ref('X',119).should == 'T'
@genome.ref('X',120).should == 'C'
+ expect { @genome.ref('X',9) }.to raise_error
@genome.ref('X',479).should == 'T'
@genome.ref('X',480).should == 'T'
# Within the same record you can ref
@@ -22,7 +23,7 @@
@genome.ref('X',511).should == 'N'
@genome.ref('X',560).should == 'T' # <- reads into the 3rd sequence
@genome.ref('Y',29).should == nil
- @genome.ref('X',10).should == nil
+ expect { @genome.ref('X',10) }.to raise_error
@genome.ref('X',10000).should == nil
end

0 comments on commit f35a525

Please sign in to comment.