]> git.donarmstrong.com Git - biopieces.git/blob - code_ruby/Maasha/test/test_bits.rb
added hamming_dist method to bits.rb
[biopieces.git] / code_ruby / Maasha / test / test_bits.rb
1 #!/usr/bin/env ruby
2
3 require 'bits'
4 require 'test/unit'
5 require 'pp'
6
7 class TestBits < Test::Unit::TestCase 
8   def test_Bits_hamming_dist_with_uneven_lengths_raises
9     assert_raises(StringError) { String.hamming_dist("ATCG", "ATC") }
10   end
11
12   def test_Bits_hamming_dist_with_even_lengths_dont_raise
13     assert_nothing_raised { String.hamming_dist("ATCG", "ATCG") }
14   end
15
16   def test_Bits_hamming_dist_returns_correctly
17     assert_equal(0, String.hamming_dist("ATCG", "ATCG"))
18     assert_equal(1, String.hamming_dist("ATCX", "ATCG"))
19     assert_equal(2, String.hamming_dist("ATXX", "ATCG"))
20     assert_equal(2, String.hamming_dist("ATcg", "ATCG"))
21     assert_equal(3, String.hamming_dist("AXXX", "ATCG"))
22     assert_equal(4, String.hamming_dist("XXXX", "ATCG"))
23   end
24
25   def test_Bits_AND_with_equal_length_returns_correctly
26     assert_equal("ABCD", "abcd" & "____")
27   end
28
29   def test_Bits_AND_with_unequal_length_returns_correctly
30     assert_equal("JAPH\n", "japh\nJunk" & '_____')
31     assert_equal("JAPH\n", '_____' & "japh\nJunk")
32   end
33
34   def test_Bits_OR_with_equal_length_returns_correctly
35     assert_equal("abcd", "ab  " | "  cd")
36   end
37
38   def test_Bits_OR_with_unequal_length_returns_correctly
39     assert_equal("japh\n", "JA" | "  ph\n")
40     assert_equal("japh\n", "  ph\n" | "JA")
41   end
42
43   def test_Bits_XOR_with_equal_length_returns_correctly
44     assert_equal("ABCD", "ab  " ^ "  cd")
45   end
46
47   def test_Bits_XOR_with_unequal_length_returns_correctly
48     assert_equal("JAPH", "j p \n" ^ " a h")
49     assert_equal("JAPH", " a h" ^ "j p \n")
50   end
51 end