]> git.donarmstrong.com Git - biopieces.git/blob - code_ruby/test/maasha/seq/test_patternmatcher.rb
added some text
[biopieces.git] / code_ruby / test / maasha / seq / test_patternmatcher.rb
1 #!/usr/bin/env ruby
2 $:.unshift File.join(File.dirname(__FILE__),'..','lib')
3
4 # Copyright (C) 2007-2010 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 'maasha/seq'
29 require 'maasha/seq/patternmatcher'
30 require 'test/unit'
31 require 'pp'
32
33 include PatternMatcher
34
35 class TestPatternMatcher < Test::Unit::TestCase
36   def setup
37     @p = Seq.new("test", "atcg")
38   end
39
40   def test_PatternMatcher_no_match_returns_nil
41     assert_nil(@p.match("gggg"))
42   end
43
44 #  def test_PatternMatcher_match_perfect_returns_correctly
45 #    m = @p.match("atcg")
46 #    assert_equal(0, m.pos)
47 #    assert_equal("atcg", m.match)
48 #    assert_equal(4, m.matches)
49 #    assert_equal(0, m.mismatches)
50 #    assert_equal(0, m.insertions)
51 #    assert_equal(0, m.deletions)
52 #    assert_equal(4, m.length)
53 #  end
54 #
55 #  def test_PatternMatcher_match_perfect_with_ambiguity_codes_returns_correctly
56 #    m = @p.match("nnnn")
57 #    assert_equal(0, m.pos)
58 #    assert_equal("atcg", m.match)
59 #    assert_equal(4, m.matches)
60 #    assert_equal(0, m.mismatches)
61 #    assert_equal(0, m.insertions)
62 #    assert_equal(0, m.deletions)
63 #    assert_equal(4, m.length)
64 #  end
65 #
66 #  def test_PatternMatcher_match_with_one_mismatch_and_edit_dist_zero_returns_nil
67 #    assert_nil(@p.match("aCcg"))
68 #  end
69 #
70 #  def test_PatternMatcher_match_with_one_mismatch_and_edit_dist_one_returns_correctly
71 #    m = @p.match("aCcg", 0, 1)
72 #    assert_equal(0, m.pos)
73 #    assert_equal("atcg", m.match)
74 #    assert_equal(3, m.matches)
75 #    assert_equal(1, m.mismatches)
76 #    assert_equal(0, m.insertions)
77 #    assert_equal(0, m.deletions)
78 #    assert_equal(4, m.length)
79 #  end
80 #
81 #  def test_PatternMatcher_match_with_two_mismatch_and_edit_dist_one_returns_nil
82 #    assert_nil(@p.match("aGcA", 0, 1))
83 #  end
84 #
85 #  def test_PatternMatcher_match_with_one_insertion_and_edit_dist_zero_returns_nil
86 #    assert_nil(@p.match("atGcg"))
87 #  end
88 #
89 #  def test_PatternMatcher_match_with_one_insertion_and_edit_dist_one_returns_correctly
90 #    m = @p.match("atGcg", 0, 1)
91 #    assert_equal(0, m.pos)
92 #    assert_equal("atcg", m.match)
93 #    assert_equal(4, m.matches)
94 #    assert_equal(0, m.mismatches)
95 #    assert_equal(1, m.insertions)
96 #    assert_equal(0, m.deletions)
97 #    assert_equal(4, m.length)
98 #  end
99 #
100 #  def test_PatternMatcher_match_with_two_insertions_and_edit_dist_one_returns_nil
101 #    assert_nil(@p.match("atGcTg", 0, 1))
102 #  end
103 #
104 #  def test_PatternMatcher_match_with_two_insertions_and_edit_dist_two_returns_correctly
105 #    m = @p.match("atGcTg", 0, 2)
106 #    assert_equal(0, m.pos)
107 #    assert_equal("atcg", m.match)
108 #    assert_equal(4, m.matches)
109 #    assert_equal(0, m.mismatches)
110 #    assert_equal(2, m.insertions)
111 #    assert_equal(0, m.deletions)
112 #    assert_equal(4, m.length)
113 #  end
114 #
115 #  def test_PatternMatcher_match_with_one_deletion_and_edit_distance_zero_returns_nil
116 #    assert_nil(@p.match("acg"))
117 #  end
118 #
119 #  def test_PatternMatcher_match_with_one_deletion_and_edit_distance_one_returns_correctly
120 #    m = @p.match("acg", 0, 1)
121 #    assert_equal(0, m.pos)
122 #    assert_equal("atcg", m.match)
123 #    assert_equal(3, m.matches)
124 #    assert_equal(0, m.mismatches)
125 #    assert_equal(0, m.insertions)
126 #    assert_equal(1, m.deletions)
127 #    assert_equal(4, m.length)
128 #  end
129 #
130 #  def test_PatternMatcher_scan_locates_three_patterns_ok
131 #    p = Seq.new("test", "ataacgagctagctagctagctgactac")
132 #    assert_equal(3, p.scan("tag").count)
133 #  end
134 #
135 #  def test_PatternMatcher_scan_with_pos_locates_two_patterns_ok
136 #    p = Seq.new("test", "ataacgagctagctagctagctgactac")
137 #    assert_equal(2, p.scan("tag", 10).count)
138 #  end
139 end