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