test/test_sequence.rb in scaffolder-0.2.6 vs test/test_sequence.rb in scaffolder-0.4.0
- old
+ new
@@ -1,123 +1,100 @@
require 'helper'
-class TestScaffolder < Test::Unit::TestCase
- context Scaffolder::Sequence do
+class TestSequence < Test::Unit::TestCase
+ context Scaffolder::Region::Sequence do
- setup do
- @options = { :name => "sequence1",
- :sequence => 'ATGCCAGATAACTGACTAGCATG' }
+ context "attributes" do
+ should_have_method_attribute Scaffolder::Region::Sequence
+ should_have_attribute Scaffolder::Region::Sequence, :source, :inserts
end
- context "processing a simple sequence tag" do
+ context "insert attribute method" do
- should "create sequence object" do
- sequence = Scaffolder::Sequence.new @options
- assert_equal(sequence.entry_type,:sequence)
- assert_equal(sequence.start,1)
- assert_equal(sequence.end,23)
- assert_equal(sequence.name,'sequence1')
- assert_equal(sequence.sequence,'ATGCCAGATAACTGACTAGCATG')
- assert_equal(sequence.raw_sequence,'ATGCCAGATAACTGACTAGCATG')
+ setup do
+ @sequence = Scaffolder::Region::Sequence.new
+ @hash = {'open' => 2, 'close' => 3}
+ @insert = Scaffolder::Region::Insert.new
+ @insert.open @hash['open']
+ @insert.close @hash['close']
end
- should "reverse sequence when passed the reverse option" do
- sequence = Scaffolder::Sequence.new @options.merge(:reverse => true)
- assert_equal(sequence.sequence,'CATGCTAGTCAGTTATCTGGCAT')
- assert_equal(sequence.raw_sequence,'ATGCCAGATAACTGACTAGCATG')
+ should "return empty array as default value" do
+ assert_equal(@sequence.inserts,Array.new)
end
- should "create subsequence object when passed sequence coordinates" do
- sequence = Scaffolder::Sequence.new @options.merge(:start => 5,:end => 20)
- assert_equal(sequence.start,5)
- assert_equal(sequence.end,20)
- assert_equal(sequence.sequence,'CAGATAACTGACTAGC')
+ should "allow array of inserts to be set as value" do
+ @sequence.inserts [@insert]
+ assert_equal(@sequence.inserts,[@insert])
end
- should "throw an error when the start position is outside the sequence length" do
- begin
- Scaffolder::Sequence.new @options.merge(:start => 0)
- flunk "Should throw an argument error"
- rescue ArgumentError
- end
+ should "process insert data hash into an array of inserts" do
+ @sequence.inserts [@hash]
+ insert = @sequence.inserts.first
+ assert_instance_of(Scaffolder::Region::Insert,insert)
+ assert_equal(@hash['close'],insert.close)
+ assert_equal(@hash['open'],insert.open)
end
- should "throw an error when the end position is outside the sequence length" do
- begin
- Scaffolder::Sequence.new @options.merge(:end => 24)
- flunk "Should throw an argument error"
- rescue ArgumentError
+ should "process mixed insert data into an array of inserts" do
+ @sequence.inserts [@hash,@insert]
+ @sequence.inserts.each do |insert|
+ assert_instance_of(Scaffolder::Region::Insert,insert)
+ assert_equal(@hash['close'],insert.close)
+ assert_equal(@hash['open'],insert.open)
end
end
- should "throw an error when the start is greater than the end" do
- begin
- Scaffolder::Sequence.new @options.merge(:end => 5,:start => 10)
- flunk "Should throw an argument error"
- rescue ArgumentError
- end
- end
-
end
- context "processing a sequence tag with inserts" do
+ context "with inserts added" do
setup do
- @insert = {:start => 5, :stop => 10, :sequence => 'GGTAGTA'}
- @sequence = Scaffolder::Sequence.new @options
+ @sequence = Scaffolder::Region::Sequence.new
+ @sequence.raw_sequence 'ATGCCAGATAACTGACTAGCATG'
+
+ @insert = Scaffolder::Region::Insert.new
+ @insert.raw_sequence 'GGTAGTA'
+ @insert.open 5
+ @insert.close 10
end
- should "raise when the insert start is after the sequence end" do
- @insert.update(:start => 24,:stop => nil)
- assert_raise(ArgumentError) do
- @sequence.add_inserts([Scaffolder::Insert.new @insert])
- end
+ should "raise when the insert open is after the sequence stop" do
+ @insert.open 24
+ @insert.close 25
+ @sequence.inserts [@insert]
+ assert_raise(Scaffolder::Errors::CoordinateError){ @sequence.sequence }
end
- should "raise when the insert stop is before the sequence start" do
- @insert.update(:start => -5,:stop => 0)
- assert_raise(ArgumentError) do
- @sequence.add_inserts([Scaffolder::Insert.new @insert])
- end
+ should "raise when the insert close is before the sequence start" do
+ @insert.open -5
+ @insert.close 0
+ @sequence.inserts [@insert]
+ assert_raise(Scaffolder::Errors::CoordinateError){ @sequence.sequence }
end
- should "raise when insert start is greater than end" do
- @insert.update(:start => 11)
- assert_raise(ArgumentError) do
- @sequence.add_inserts([Scaffolder::Insert.new @insert])
- end
+ should "raise when the insert open is greater than the insert close" do
+ @insert.open 11
+ @sequence.inserts [@insert]
+ assert_raise(Scaffolder::Errors::CoordinateError){ @sequence.sequence }
end
- should "update the sequence" do
- @sequence.add_inserts([Scaffolder::Insert.new @insert])
+ should "update the sequence with a simple insert" do
+ @sequence.inserts [@insert]
assert_equal(@sequence.sequence,'ATGCGGTAGTAACTGACTAGCATG')
- assert_equal(@sequence.end,24)
- assert_equal(@sequence.raw_sequence,'ATGCCAGATAACTGACTAGCATG')
end
- should "return added insert as an attribute" do
- inserts = [Scaffolder::Insert.new @insert]
- @sequence.add_inserts(inserts)
- assert_equal(@sequence.inserts,inserts)
+ should "update the sequence stop position after adding a simple insert" do
+ @sequence.inserts [@insert]
+ assert_equal(@sequence.stop,24)
end
- should "return empty array when no inserts and inserts method called" do
- assert_equal(@sequence.inserts,[])
- end
-
- should "update the sequence when reversed" do
- @sequence = Scaffolder::Sequence.new @options.update(:reverse => true)
- @sequence.add_inserts([Scaffolder::Insert.new @insert])
- assert_equal(@sequence.sequence,"CATGCTAGTCAGTTACTACCGCAT")
- assert_equal(@sequence.raw_sequence,'ATGCCAGATAACTGACTAGCATG')
- end
-
- should "update the sequence with two inserts" do
- @sequence.add_inserts([Scaffolder::Insert.new(@insert),
- Scaffolder::Insert.new(@insert.update(:start => 12, :stop => 15))])
+ should "update sequence with inserts in reverse order" do
+ insert_two = @insert.clone
+ insert_two.open 12
+ insert_two.close 15
+ @sequence.inserts [@insert,insert_two]
assert_equal(@sequence.sequence,"ATGCGGTAGTAAGGTAGTACTAGCATG")
- assert_equal(@sequence.end,27)
- assert_equal(@sequence.raw_sequence,'ATGCCAGATAACTGACTAGCATG')
end
end
end
end