2 $:.unshift File.join(File.dirname(__FILE__),'..','lib')
4 # Copyright (C) 2007-2010 Martin A. Hansen.
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.
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.
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.
20 # http://www.gnu.org/copyleft/gpl.html
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
24 # This software is part of the Biopieces framework (www.biopieces.org).
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
32 class TestDynamic < Test::Unit::TestCase
34 @p = Seq.new("test", "atcg")
38 def test_Dynamic_no_match_returns_nil
39 assert_nil(@p.patmatch("gggg"))
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)
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)
62 def test_Dynamic_patmatch_with_one_mismatch_and_edit_dist_zero_returns_nil
63 assert_nil(@p.patmatch("aCcg"))
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)
76 def test_Dynamic_patmatch_with_two_mismatch_and_edit_dist_one_returns_nil
77 assert_nil(@p.patmatch("aGcA", 0, 1))
80 def test_Dynamic_patmatch_with_one_insertion_and_edit_dist_zero_returns_nil
81 assert_nil(@p.patmatch("atGcg"))
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)
94 def test_Dynamic_patmatch_with_two_insertions_and_edit_dist_one_returns_nil
95 assert_nil(@p.patmatch("atGcTg", 0, 1))
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)
108 def test_Dynamic_patmatch_with_one_deletion_and_edit_distance_zero_returns_nil
109 assert_nil(@p.patmatch("acg"))
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)
122 def test_Dynamic_patscan_locates_three_patterns_ok
123 p = Seq.new("test", "ataacgagctagctagctagctgactac")
125 assert_equal(3, p.patscan("tag").count)
128 def test_Dynamic_patscan_with_pos_locates_two_patterns_ok
129 p = Seq.new("test", "ataacgagctagctagctagctgactac")
131 assert_equal(2, p.patscan("tag", 10).count)