2 $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
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 test "#patmatch with no match returns nil" do
39 assert_nil(@p.patmatch("gggg"))
42 test "#patmatch with perfect match returns correctly" do
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 test "#patmatch with perfect match with ambiguity codes returns correctly" do
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 test "#patmatch with one mismatch and edit dist zero returns nil" do
63 assert_nil(@p.patmatch("aCcg"))
66 test "#patmatch with one mismatch and edit dist one returns correctly" do
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 test "#patmatch with two mismatch and edit dist one returns nil" do
77 assert_nil(@p.patmatch("aGcA", 0, 1))
80 test "#patmatch with one insertion and edit dist zero returns nil" do
81 assert_nil(@p.patmatch("atGcg"))
84 test "#patmatch with one insertion and edit dist one returns correctly" do
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 test "#patmatch with two insertions and edit dist one returns nil" do
95 assert_nil(@p.patmatch("atGcTg", 0, 1))
98 test "#patmatch with two insertions and edit dist two returns correctly" do
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 test "#patmatch with one deletion and edit distance zero returns nil" do
109 assert_nil(@p.patmatch("acg"))
112 test "#patmatch with one deletion and edit distance one returns correctly" do
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 test "#patscan locates three patterns ok" do
123 p = Seq.new("test", "ataacgagctagctagctagctgactac")
125 assert_equal(3, p.patscan("tag").count)
128 test "#patscan with pos locates two patterns ok" do
129 p = Seq.new("test", "ataacgagctagctagctagctgactac")
131 assert_equal(2, p.patscan("tag", 10).count)