]> git.donarmstrong.com Git - biopieces.git/blob - code_ruby/test/maasha/seq/test_backtrack.rb
08fba496d323875a1490a157b165f006bbc0eaf5
[biopieces.git] / code_ruby / test / maasha / seq / test_backtrack.rb
1 #!/usr/bin/env ruby
2 $:.unshift File.join(File.dirname(__FILE__),'..','lib')
3
4 # Copyright (C) 2007-2011 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 'test/unit'
29 require 'maasha/seq'
30 require 'maasha/seq/backtrack'
31
32 include BackTrack
33
34 class BackTrackTest < Test::Unit::TestCase
35   def setup
36     #                       0         1
37     #                       01234567890123456789
38     @seq = Seq.new("test", "tacgatgctagcatgcacgg")
39   end
40
41   def test_BackTrack_patscan_with_bad_pattern_raises
42     ["", "X", "1"].each { |pattern|
43       assert_raise(BackTrackError) { @seq.patscan(pattern) }
44     }
45   end
46
47   def test_BackTrack_patscan_with_OK_pattern_dont_raise
48     ["N", "atcg"].each { |pattern|
49       assert_nothing_raised { @seq.patscan(pattern) }
50     }
51   end
52
53   def test_BackTrack_patscan_with_bad_pos_raises
54     [-1, 20].each { |pos| 
55       assert_raise(BackTrackError) { @seq.patscan("N", pos) }
56     }
57   end
58
59   def test_BackTrack_patscan_with_OK_pos_dont_raise
60     [0, 19].each { |pos| 
61       assert_nothing_raised { @seq.patscan("N", pos) }
62     }
63   end
64
65   def test_BackTrack_patscan_with_bad_mis_raises
66     [-1, 6].each { |mis| 
67       assert_raise(BackTrackError) { @seq.patscan("N", 0, mis) }
68     }
69   end
70
71   def test_BackTrack_patscan_with_OK_mis_dont_raise
72     [0, 5].each { |mis| 
73       assert_nothing_raised { @seq.patscan("N", 0, mis) }
74     }
75   end
76
77   def test_BackTrack_patscan_with_bad_ins_raises
78     [-1, 6].each { |ins| 
79       assert_raise(BackTrackError) { @seq.patscan("N", 0, 0, ins) }
80     }
81   end
82
83   def test_BackTrack_patscan_with_OK_ins_dont_raise
84     [0, 5].each { |ins| 
85       assert_nothing_raised { @seq.patscan("N", 0, 0, ins) }
86     }
87   end
88
89   def test_BackTrack_patscan_with_bad_del_raises
90     [-1, 6].each { |del| 
91       assert_raise(BackTrackError) { @seq.patscan("N", 0, 0, 0, del) }
92     }
93   end
94
95   def test_BackTrack_patscan_with_OK_del_dont_raise
96     [0, 5].each { |del| 
97       assert_nothing_raised { @seq.patscan("N", 0, 0, 0, del) }
98     }
99   end
100
101   def test_BackTrack_patscan_perfect_left_is_ok
102     assert_equal("0:7:tacgatg", @seq.patscan("TACGATG").first.to_s)
103   end
104
105   def test_BackTrack_patscan_perfect_right_is_ok
106     assert_equal("13:7:tgcacgg", @seq.patscan("TGCACGG").first.to_s)
107   end
108
109   def test_BackTrack_patscan_ambiguity_is_ok
110     assert_equal("13:7:tgcacgg", @seq.patscan("TGCACNN").first.to_s)
111   end
112
113   def test_BackTrack_patscan_pos_is_ok
114     assert_equal("10:1:g", @seq.patscan("N", 10).first.to_s)
115     assert_equal("19:1:g", @seq.patscan("N", 10).last.to_s)
116   end
117
118   def test_BackTrack_patscan_mis_left_is_ok
119     assert_equal("0:7:tacgatg", @seq.patscan("Aacgatg", 0, 1).first.to_s)
120   end
121
122   def test_BackTrack_patscan_mis_right_is_ok
123     assert_equal("13:7:tgcacgg", @seq.patscan("tgcacgA", 0, 1).first.to_s)
124   end
125
126   def test_BackTrack_patscan_ins_left_is_ok
127     assert_equal("0:7:tacgatg", @seq.patscan("Atacgatg", 0, 0, 1).first.to_s)
128   end
129
130   def test_BackTrack_patscan_ins_right_is_ok
131     assert_equal("13:7:tgcacgg", @seq.patscan("tgcacggA", 0, 0, 1).first.to_s)
132   end
133
134   def test_BackTrack_patscan_del_left_is_ok
135     assert_equal("0:7:tacgatg", @seq.patscan("acgatg", 0, 0, 0, 1).first.to_s)
136   end
137
138   def test_BackTrack_patscan_del_right_is_ok
139     assert_equal("12:8:atgcacgg", @seq.patscan("tgcacgg", 0, 0, 0, 1).first.to_s)
140   end
141
142   def test_BackTrack_patscan_ambiguity_mis_ins_del_all_ok
143     assert_equal("0:20:tacgatgctagcatgcacgg", @seq.patscan("tacatgcNagGatgcCacgg", 0, 1, 1, 1).first.to_s)
144   end
145 end
146