]> git.donarmstrong.com Git - biopieces.git/blob - code_ruby/test/maasha/seq/test_dynamic.rb
fixed unit tests
[biopieces.git] / code_ruby / test / maasha / seq / test_dynamic.rb
1 #!/usr/bin/env ruby
2 $:.unshift File.join(File.dirname(__FILE__),'..','lib')
3
4 # Copyright (C) 2007-2010 Martin A. Hansen.
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 # http://www.gnu.org/copyleft/gpl.html
21
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
23
24 # This software is part of the Biopieces framework (www.biopieces.org).
25
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
27
28 require 'maasha/seq'
29 require 'test/unit'
30 require 'pp'
31
32 class TestDynamic < Test::Unit::TestCase
33   def setup
34     @p = Seq.new("test", "atcg")
35     @p.extend(Dynamic)
36   end
37
38   def test_Dynamic_no_match_returns_nil
39     assert_nil(@p.patmatch("gggg"))
40   end
41
42   def test_Dynamic_patmatch_perfect_returns_correctly
43     m = @p.patmatch("atcg")
44     assert_equal(0, m.beg)
45     assert_equal("atcg", m.match)
46     assert_equal(0, m.mis)
47     assert_equal(0, m.ins)
48     assert_equal(0, m.del)
49     assert_equal(4, m.length)
50   end
51
52   def test_Dynamic_patmatch_perfect_with_ambiguity_codes_returns_correctly
53     m = @p.patmatch("nnnn")
54     assert_equal(0, m.beg)
55     assert_equal("atcg", m.match)
56     assert_equal(0, m.mis)
57     assert_equal(0, m.ins)
58     assert_equal(0, m.del)
59     assert_equal(4, m.length)
60   end
61
62   def test_Dynamic_patmatch_with_one_mismatch_and_edit_dist_zero_returns_nil
63     assert_nil(@p.patmatch("aCcg"))
64   end
65
66   def test_Dynamic_patmatch_with_one_mismatch_and_edit_dist_one_returns_correctly
67     m = @p.patmatch("aCcg", 0, 1)
68     assert_equal(0, m.beg)
69     assert_equal("atcg", m.match)
70     assert_equal(1, m.mis)
71     assert_equal(0, m.ins)
72     assert_equal(0, m.del)
73     assert_equal(4, m.length)
74   end
75
76   def test_Dynamic_patmatch_with_two_mismatch_and_edit_dist_one_returns_nil
77     assert_nil(@p.patmatch("aGcA", 0, 1))
78   end
79
80   def test_Dynamic_patmatch_with_one_insertion_and_edit_dist_zero_returns_nil
81     assert_nil(@p.patmatch("atGcg"))
82   end
83
84   def test_Dynamic_patmatch_with_one_insertion_and_edit_dist_one_returns_correctly
85     m = @p.patmatch("atGcg", 0, 1)
86     assert_equal(0, m.beg)
87     assert_equal("atcg", m.match)
88     assert_equal(0, m.mis)
89     assert_equal(1, m.ins)
90     assert_equal(0, m.del)
91     assert_equal(4, m.length)
92   end
93
94   def test_Dynamic_patmatch_with_two_insertions_and_edit_dist_one_returns_nil
95     assert_nil(@p.patmatch("atGcTg", 0, 1))
96   end
97
98   def test_Dynamic_patmatch_with_two_insertions_and_edit_dist_two_returns_correctly
99     m = @p.patmatch("atGcTg", 0, 2)
100     assert_equal(0, m.beg)
101     assert_equal("atcg", m.match)
102     assert_equal(0, m.mis)
103     assert_equal(2, m.ins)
104     assert_equal(0, m.del)
105     assert_equal(4, m.length)
106   end
107
108   def test_Dynamic_patmatch_with_one_deletion_and_edit_distance_zero_returns_nil
109     assert_nil(@p.patmatch("acg"))
110   end
111
112   def test_Dynamic_patmatch_with_one_deletion_and_edit_distance_one_returns_correctly
113     m = @p.patmatch("acg", 0, 1)
114     assert_equal(0, m.beg)
115     assert_equal("atcg", m.match)
116     assert_equal(0, m.mis)
117     assert_equal(0, m.ins)
118     assert_equal(1, m.del)
119     assert_equal(4, m.length)
120   end
121
122   def test_Dynamic_patscan_locates_three_patterns_ok
123     p = Seq.new("test", "ataacgagctagctagctagctgactac")
124     p.extend(Dynamic)
125     assert_equal(3, p.patscan("tag").count)
126   end
127
128   def test_Dynamic_patscan_with_pos_locates_two_patterns_ok
129     p = Seq.new("test", "ataacgagctagctagctagctgactac")
130     p.extend(Dynamic)
131     assert_equal(2, p.patscan("tag", 10).count)
132   end
133 end