]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/test/maasha/test_fasta.rb
changed layout of ruby source
[biopieces.git] / code_ruby / test / maasha / test_fasta.rb
diff --git a/code_ruby/test/maasha/test_fasta.rb b/code_ruby/test/maasha/test_fasta.rb
new file mode 100755 (executable)
index 0000000..d5ba7bd
--- /dev/null
@@ -0,0 +1,90 @@
+#!/usr/bin/env ruby
+$:.unshift File.join(File.dirname(__FILE__),'..','lib')
+
+# Copyright (C) 2007-2010 Martin A. Hansen.
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# http://www.gnu.org/copyleft/gpl.html
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# This software is part of the Biopieces framework (www.biopieces.org).
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+require 'test/unit'
+require 'maasha/fasta'
+require 'stringio'
+require 'pp'
+
+class FastaTest < Test::Unit::TestCase
+  def test_Fasta_get_entry_obtains_the_correct_seq_name
+    fasta = Fasta.new(StringIO.new(">test\nATCG\n"))
+    assert_equal(fasta.get_entry.seq_name, "test")
+  end
+
+  def test_Fasta_get_entry_obtains_the_correct_seq_without_trailing_newlines
+    fasta = Fasta.new(StringIO.new(">test\nATCG"))
+    assert_equal(fasta.get_entry.seq, "ATCG")
+  end
+
+  def test_Fasta_get_entry_obtains_the_correct_seq_with_trailing_newlines
+    fasta = Fasta.new(StringIO.new(">test\nATCG\n\n\n"))
+    assert_equal(fasta.get_entry.seq, "ATCG")
+  end
+
+  def test_Fasta_get_entry_obtains_the_correct_type
+    fasta = Fasta.new(StringIO.new(">test\nATCG\n"), 'DNA')
+    assert_equal(fasta.get_entry.type, "dna")
+  end
+
+  def test_Fasta_get_entry_rstrips_whitespace_from_seq_name
+    fasta = Fasta.new(StringIO.new(">test\n\r\t ATCG\n"))
+    assert_equal(fasta.get_entry.seq_name, "test")
+  end
+
+  def test_Fasta_get_entry_strips_whitespace_from_seq
+    fasta = Fasta.new(StringIO.new(">test\n\r\t AT\n\r\t CG\n\r\t "))
+    assert_equal(fasta.get_entry.seq, "ATCG")
+  end
+
+  def test_Fasta_get_entry_with_two_entries_obtain_correct
+    fasta = Fasta.new(StringIO.new(">test1\n\r\t AT\n\r\t CG\n\r\t \n>test2\n\r\t atcg\n"))
+    assert_equal(fasta.get_entry.seq, "ATCG")
+    assert_equal(fasta.get_entry.seq, "atcg")
+  end
+
+  def test_Fasta_get_entry_without_seq_name_raises
+    fasta = Fasta.new(StringIO.new("ATCG\n"))
+    assert_raise( FastaError ) { fasta.get_entry }
+  end
+
+  def test_Fasta_get_entry_without_seq_raises
+    fasta = Fasta.new(StringIO.new(">test\n\n"))
+    assert_raise( FastaError ) { fasta.get_entry }
+  end
+
+  def test_Fasta_get_entry_with_leading_newline_raises
+    fasta = Fasta.new(StringIO.new("\n>test\nATCG\n"))
+    assert_raise( FastaError ) { fasta.get_entry }
+  end
+
+# FIXME
+#  def test_Fasta_get_entry raises on missing > in seq_name
+#    fasta = Fasta.new(StringIO.new("test\nATCG\n"))
+#    assert_raise( FastaError ) { fasta.get_entry }
+#  end
+end