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