]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/test/maasha/test_seq.rb
refactoring of ruby code converting sequences types to symbols
[biopieces.git] / code_ruby / test / maasha / test_seq.rb
index 4a68d67b080b0ed220ae8fb18d7dfed83c1750fa..eab90cb758f1a95a4d1f71a968f5681f63728da7 100755 (executable)
@@ -35,11 +35,11 @@ class TestSeq < Test::Unit::TestCase
   end
 
   test "Seq.new_bp returns correctly" do
-    record = {:SEQ_NAME => "test", :SEQ => "ATCG", :SEQ_TYPE => "dna", :SCORES => "hhhh"}
+    record = {:SEQ_NAME => "test", :SEQ => "ATCG", :SEQ_TYPE => :dna, :SCORES => "hhhh"}
     seq    = Seq.new_bp(record)
     assert_equal("test", seq.seq_name)
     assert_equal("ATCG", seq.seq)
-    assert_equal("dna",  seq.type)
+    assert_equal(:dna,  seq.type)
     assert_equal("hhhh", seq.qual)
   end
 
@@ -48,7 +48,7 @@ class TestSeq < Test::Unit::TestCase
   end
 
   test "#is_dna? with dna sequence type returns true" do
-    @entry.type = 'dna'
+    @entry.type = :dna
     assert(@entry.is_dna? == true)
   end
 
@@ -57,7 +57,7 @@ class TestSeq < Test::Unit::TestCase
   end
 
   test "#is_rna? with rna sequence type returns true" do
-    @entry.type = 'rna'
+    @entry.type = :rna
     assert(@entry.is_rna? == true)
   end
 
@@ -66,7 +66,7 @@ class TestSeq < Test::Unit::TestCase
   end
 
   test "#is_protein? with protein sequence type returns true" do
-    @entry.type = 'protein'
+    @entry.type = :protein
     assert_equal(true, @entry.is_protein?)
   end
 
@@ -76,17 +76,17 @@ class TestSeq < Test::Unit::TestCase
 
   test "#type_guess with protein returns protein" do
     @entry.seq = 'atcatcrFgatcg'
-    assert_equal('protein', @entry.type_guess)
+    assert_equal(:protein, @entry.type_guess)
   end
 
   test "#type_guess with rna returns rna" do
     @entry.seq = 'atcatcrUgatcg'
-    assert_equal('rna', @entry.type_guess)
+    assert_equal(:rna, @entry.type_guess)
   end
 
   test "#type_guess with dna returns dna" do
     @entry.seq = 'atcatcgatcg'
-    assert_equal('dna', @entry.type_guess)
+    assert_equal(:dna, @entry.type_guess)
   end
 
   test "#type_guess! without sequence raises" do
@@ -96,19 +96,19 @@ class TestSeq < Test::Unit::TestCase
   test "#type_guess! with protein returns protein" do
     @entry.seq = 'atcatcrFgatcg'
     @entry.type_guess!
-    assert_equal('protein', @entry.type)
+    assert_equal(:protein, @entry.type)
   end
 
   test "#type_guess! with rna returns rna" do
     @entry.seq = 'atcatcrUgatcg'
     @entry.type_guess!
-    assert_equal('rna', @entry.type)
+    assert_equal(:rna, @entry.type)
   end
 
   test "#type_guess! with dna returns dna" do
     @entry.seq = 'atcatcgatcg'
     @entry.type_guess!
-    assert_equal('dna', @entry.type)
+    assert_equal(:dna, @entry.type)
   end
 
   test "#length returns corretly" do
@@ -122,51 +122,51 @@ class TestSeq < Test::Unit::TestCase
   end
 
   test "#to_rna with no sequence raises" do
-    @entry.type = 'dna'
+    @entry.type = :dna
     assert_raise(SeqError) { @entry.to_rna }
   end
 
   test "#to_rna with bad type raises" do
     @entry.seq  = 'ATCG'
-    @entry.type = 'rna'
+    @entry.type = :rna
     assert_raise(SeqError) { @entry.to_rna }
   end
 
   test "#to_rna transcribes correctly" do
     @entry.seq  = 'ATCGatcg'
-    @entry.type = 'dna'
+    @entry.type = :dna
     assert_equal("AUCGaucg", @entry.to_rna)
   end
 
   test "#to_rna changes entry type to rna" do
     @entry.seq  = 'ATCGatcg'
-    @entry.type = 'dna'
+    @entry.type = :dna
     @entry.to_rna
-    assert_equal("rna", @entry.type)
+    assert_equal(:rna, @entry.type)
   end
 
   test "#to_dna with no sequence raises" do
-    @entry.type = 'rna'
+    @entry.type = :rna
     assert_raise(SeqError) { @entry.to_dna }
   end
 
   test "#to_dna with bad type raises" do
     @entry.seq  = 'AUCG'
-    @entry.type = 'dna'
+    @entry.type = :dna
     assert_raise(SeqError) { @entry.to_dna }
   end
 
   test "#to_dna transcribes correctly" do
     @entry.seq  = 'AUCGaucg'
-    @entry.type = 'rna'
+    @entry.type = :rna
     assert_equal("ATCGatcg", @entry.to_dna)
   end
 
   test "#to_dna changes entry type to dna" do
     @entry.seq  = 'AUCGaucg'
-    @entry.type = 'rna'
+    @entry.type = :rna
     @entry.to_dna
-    assert_equal("dna", @entry.type)
+    assert_equal(:dna, @entry.type)
   end
 
   test "#to_bp returns correct record" do
@@ -249,19 +249,19 @@ class TestSeq < Test::Unit::TestCase
   end
 
   test "#complement with no sequence raises" do
-    @entry.type = 'dna'
+    @entry.type = :dna
     assert_raise(SeqError) { @entry.complement }
   end
 
   test "#complement with bad type raises" do
     @entry.seq  = 'ATCG'
-    @entry.type = 'protein'
+    @entry.type = :protein
     assert_raise(SeqError) { @entry.complement }
   end
 
   test "#complement for DNA is correct" do
     @entry.seq  = 'ATCGatcg'
-    @entry.type = 'dna'
+    @entry.type = :dna
     comp        = @entry.complement
     assert_equal("TAGCtagc", comp.seq)
     assert_equal("ATCGatcg", @entry.seq)
@@ -269,32 +269,32 @@ class TestSeq < Test::Unit::TestCase
 
   test "#complement for RNA is correct" do
     @entry.seq  = 'AUCGaucg'
-    @entry.type = 'rna'
+    @entry.type = :rna
     comp        = @entry.complement
     assert_equal("UAGCuagc", comp.seq)
     assert_equal("AUCGaucg", @entry.seq)
   end
 
   test "#complement! with no sequence raises" do
-    @entry.type = 'dna'
+    @entry.type = :dna
     assert_raise(SeqError) { @entry.complement! }
   end
 
   test "#complement! with bad type raises" do
     @entry.seq  = 'ATCG'
-    @entry.type = 'protein'
+    @entry.type = :protein
     assert_raise(SeqError) { @entry.complement! }
   end
 
   test "#complement! for DNA is correct" do
     @entry.seq  = 'ATCGatcg'
-    @entry.type = 'dna'
+    @entry.type = :dna
     assert_equal("TAGCtagc", @entry.complement!.seq)
   end
 
   test "#complement! for RNA is correct" do
     @entry.seq  = 'AUCGaucg'
-    @entry.type = 'rna'
+    @entry.type = :rna
     assert_equal("UAGCuagc", @entry.complement!.seq)
   end
 
@@ -306,8 +306,8 @@ class TestSeq < Test::Unit::TestCase
   end
 
   test "#generate with length < 1 raises" do
-    assert_raise(SeqError) { @entry.generate(-10, "dna") }
-    assert_raise(SeqError) { @entry.generate(0, "dna") }
+    assert_raise(SeqError) { @entry.generate(-10, :dna) }
+    assert_raise(SeqError) { @entry.generate(0, :dna) }
   end
 
   test "#generate with bad type raises" do
@@ -315,8 +315,8 @@ class TestSeq < Test::Unit::TestCase
   end
 
   test "#generate with ok type dont raise" do
-    %w[dna DNA rna RNA protein Protein].each do |type|
-      assert_nothing_raised { @entry.generate(10, type) }
+    %w[dna rna protein].each do |type|
+      assert_nothing_raised { @entry.generate(10, type.to_sym) }
     end
   end
 
@@ -335,15 +335,15 @@ class TestSeq < Test::Unit::TestCase
 
   test "#<< with different types raises" do
     @entry.seq = "atcg"
-    assert_raise(SeqError) { @entry << Seq.new("test", "atcg", "dna") }
+    assert_raise(SeqError) { @entry << Seq.new("test", "atcg", :dna) }
   end
 
   test "#<< with missing qual in one entry raises" do
     @entry.seq  = "atcg"
-    @entry.type = "dna"
-    assert_raise(SeqError) { @entry << Seq.new("test", "atcg", "dna", "IIII") }
+    @entry.type = :dna
+    assert_raise(SeqError) { @entry << Seq.new("test", "atcg", :dna, "IIII") }
     @entry.qual = "IIII"
-    assert_raise(SeqError) { @entry << Seq.new("test", "atcg", "dna") }
+    assert_raise(SeqError) { @entry << Seq.new("test", "atcg", :dna) }
   end
 
   test "#<< with nil qual in both entries dont raise" do
@@ -353,9 +353,9 @@ class TestSeq < Test::Unit::TestCase
 
   test "#<< with qual in both entries dont raise" do
     @entry.seq  = "atcg"
-    @entry.type = "dna"
+    @entry.type = :dna
     @entry.qual = "IIII"
-    assert_nothing_raised { @entry << Seq.new("test", "atcg", "dna", "IIII") }
+    assert_nothing_raised { @entry << Seq.new("test", "atcg", :dna, "IIII") }
   end
 
   test "#<< without qual returns correctly" do
@@ -366,9 +366,9 @@ class TestSeq < Test::Unit::TestCase
 
   test "#<< with qual returns correctly" do
     @entry.seq  = "atcg"
-    @entry.type = "dna"
+    @entry.type = :dna
     @entry.qual = "HHHH"
-    @entry <<  Seq.new("test", "ATCG", "dna", "IIII")
+    @entry <<  Seq.new("test", "ATCG", :dna, "IIII")
     assert_equal("atcgATCG", @entry.seq)
     assert_equal("HHHHIIII", @entry.qual)
   end