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 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
29 require 'maasha/seq/dynamic'
37 class TestDynamic < Test::Unit::TestCase
39 @p = Seq.new("test", "atcg")
42 def test_Dynamic_no_match_returns_nil
43 assert_nil(@p.patmatch("gggg"))
46 def test_Dynamic_patmatch_perfect_returns_correctly
47 m = @p.patmatch("atcg")
48 assert_equal(0, m.beg)
49 assert_equal("atcg", m.match)
50 assert_equal(0, m.mis)
51 assert_equal(0, m.ins)
52 assert_equal(0, m.del)
53 assert_equal(4, m.length)
56 def test_Dynamic_patmatch_perfect_with_ambiguity_codes_returns_correctly
57 m = @p.patmatch("nnnn")
58 assert_equal(0, m.beg)
59 assert_equal("atcg", m.match)
60 assert_equal(0, m.mis)
61 assert_equal(0, m.ins)
62 assert_equal(0, m.del)
63 assert_equal(4, m.length)
66 def test_Dynamic_patmatch_with_one_mismatch_and_edit_dist_zero_returns_nil
67 assert_nil(@p.patmatch("aCcg"))
70 def test_Dynamic_patmatch_with_one_mismatch_and_edit_dist_one_returns_correctly
71 m = @p.patmatch("aCcg", 0, 1)
72 assert_equal(0, m.beg)
73 assert_equal("atcg", m.match)
74 assert_equal(1, m.mis)
75 assert_equal(0, m.ins)
76 assert_equal(0, m.del)
77 assert_equal(4, m.length)
80 def test_Dynamic_patmatch_with_two_mismatch_and_edit_dist_one_returns_nil
81 assert_nil(@p.patmatch("aGcA", 0, 1))
84 def test_Dynamic_patmatch_with_one_insertion_and_edit_dist_zero_returns_nil
85 assert_nil(@p.patmatch("atGcg"))
88 def test_Dynamic_patmatch_with_one_insertion_and_edit_dist_one_returns_correctly
89 m = @p.patmatch("atGcg", 0, 1)
90 assert_equal(0, m.beg)
91 assert_equal("atcg", m.match)
92 assert_equal(0, m.mis)
93 assert_equal(1, m.ins)
94 assert_equal(0, m.del)
95 assert_equal(4, m.length)
98 def test_Dynamic_patmatch_with_two_insertions_and_edit_dist_one_returns_nil
99 assert_nil(@p.patmatch("atGcTg", 0, 1))
102 def test_Dynamic_patmatch_with_two_insertions_and_edit_dist_two_returns_correctly
103 m = @p.patmatch("atGcTg", 0, 2)
104 assert_equal(0, m.beg)
105 assert_equal("atcg", m.match)
106 assert_equal(0, m.mis)
107 assert_equal(2, m.ins)
108 assert_equal(0, m.del)
109 assert_equal(4, m.length)
112 def test_Dynamic_patmatch_with_one_deletion_and_edit_distance_zero_returns_nil
113 assert_nil(@p.patmatch("acg"))
116 def test_Dynamic_patmatch_with_one_deletion_and_edit_distance_one_returns_correctly
117 m = @p.patmatch("acg", 0, 1)
118 assert_equal(0, m.beg)
119 assert_equal("atcg", m.match)
120 assert_equal(0, m.mis)
121 assert_equal(0, m.ins)
122 assert_equal(1, m.del)
123 assert_equal(4, m.length)
126 def test_Dynamic_patscan_locates_three_patterns_ok
127 p = Seq.new("test", "ataacgagctagctagctagctgactac")
128 assert_equal(3, p.patscan("tag").count)
131 def test_Dynamic_patscan_with_pos_locates_two_patterns_ok
132 p = Seq.new("test", "ataacgagctagctagctagctgactac")
133 assert_equal(2, p.patscan("tag", 10).count)