]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/test/maasha/test_bits.rb
changed layout of ruby source
[biopieces.git] / code_ruby / test / maasha / test_bits.rb
diff --git a/code_ruby/test/maasha/test_bits.rb b/code_ruby/test/maasha/test_bits.rb
new file mode 100755 (executable)
index 0000000..5a589f5
--- /dev/null
@@ -0,0 +1,77 @@
+#!/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 'maasha/bits'
+require 'test/unit'
+require 'pp'
+
+class TestBits < Test::Unit::TestCase 
+  def test_Bits_hamming_dist_with_uneven_lengths_raises
+    assert_raises(StringError) { String.hamming_dist("ATCG", "ATC") }
+  end
+
+  def test_Bits_hamming_dist_with_even_lengths_dont_raise
+    assert_nothing_raised { String.hamming_dist("ATCG", "ATCG") }
+  end
+
+  def test_Bits_hamming_dist_returns_correctly
+    assert_equal(0, String.hamming_dist("ATCG", "ATCG"))
+    assert_equal(1, String.hamming_dist("ATCX", "ATCG"))
+    assert_equal(2, String.hamming_dist("ATXX", "ATCG"))
+    assert_equal(2, String.hamming_dist("ATcg", "ATCG"))
+    assert_equal(3, String.hamming_dist("AXXX", "ATCG"))
+    assert_equal(4, String.hamming_dist("XXXX", "ATCG"))
+  end
+
+  def test_Bits_AND_with_equal_length_returns_correctly
+    assert_equal("ABCD", "abcd" & "____")
+  end
+
+  def test_Bits_AND_with_unequal_length_returns_correctly
+    assert_equal("JAPH\n", "japh\nJunk" & '_____')
+    assert_equal("JAPH\n", '_____' & "japh\nJunk")
+  end
+
+  def test_Bits_OR_with_equal_length_returns_correctly
+    assert_equal("abcd", "ab  " | "  cd")
+  end
+
+  def test_Bits_OR_with_unequal_length_returns_correctly
+    assert_equal("japh\n", "JA" | "  ph\n")
+    assert_equal("japh\n", "  ph\n" | "JA")
+  end
+
+  def test_Bits_XOR_with_equal_length_returns_correctly
+    assert_equal("ABCD", "ab  " ^ "  cd")
+  end
+
+  def test_Bits_XOR_with_unequal_length_returns_correctly
+    assert_equal("JAPH", "j p \n" ^ " a h")
+    assert_equal("JAPH", " a h" ^ "j p \n")
+  end
+end