From: martinahansen Date: Wed, 5 Dec 2012 10:22:29 +0000 (+0000) Subject: renamed patternmatcher to dynamic X-Git-Url: https://git.donarmstrong.com/?p=biopieces.git;a=commitdiff_plain;h=aa15d816187b3fc20c98a2d51a6bca507b26a2b1 renamed patternmatcher to dynamic git-svn-id: http://biopieces.googlecode.com/svn/trunk@2034 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/test/maasha/seq/test_dynamic.rb b/code_ruby/test/maasha/seq/test_dynamic.rb new file mode 100755 index 0000000..8e1121e --- /dev/null +++ b/code_ruby/test/maasha/seq/test_dynamic.rb @@ -0,0 +1,135 @@ +#!/usr/bin/env ruby +$:.unshift File.join(File.dirname(__FILE__),'..','lib') + +# Copyright (C) 2007-2010 Martin A. Hansen. + +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# http://www.gnu.org/copyleft/gpl.html + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# This software is part of the Biopieces framework (www.biopieces.org). + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +require 'maasha/seq' +require 'maasha/seq/dynamic' +require 'test/unit' +require 'pp' + +class Seq + include Dynamic +end + +class TestDynamic < Test::Unit::TestCase + def setup + @p = Seq.new("test", "atcg") + end + + def test_Dynamic_no_match_returns_nil + assert_nil(@p.patmatch("gggg")) + end + + def test_Dynamic_patmatch_perfect_returns_correctly + m = @p.patmatch("atcg") + assert_equal(0, m.beg) + assert_equal("atcg", m.match) + assert_equal(0, m.mis) + assert_equal(0, m.ins) + assert_equal(0, m.del) + assert_equal(4, m.length) + end + + def test_Dynamic_patmatch_perfect_with_ambiguity_codes_returns_correctly + m = @p.patmatch("nnnn") + assert_equal(0, m.beg) + assert_equal("atcg", m.match) + assert_equal(0, m.mis) + assert_equal(0, m.ins) + assert_equal(0, m.del) + assert_equal(4, m.length) + end + + def test_Dynamic_patmatch_with_one_mismatch_and_edit_dist_zero_returns_nil + assert_nil(@p.patmatch("aCcg")) + end + + def test_Dynamic_patmatch_with_one_mismatch_and_edit_dist_one_returns_correctly + m = @p.patmatch("aCcg", 0, 1) + assert_equal(0, m.beg) + assert_equal("atcg", m.match) + assert_equal(1, m.mis) + assert_equal(0, m.ins) + assert_equal(0, m.del) + assert_equal(4, m.length) + end + + def test_Dynamic_patmatch_with_two_mismatch_and_edit_dist_one_returns_nil + assert_nil(@p.patmatch("aGcA", 0, 1)) + end + + def test_Dynamic_patmatch_with_one_insertion_and_edit_dist_zero_returns_nil + assert_nil(@p.patmatch("atGcg")) + end + + def test_Dynamic_patmatch_with_one_insertion_and_edit_dist_one_returns_correctly + m = @p.patmatch("atGcg", 0, 1) + assert_equal(0, m.beg) + assert_equal("atcg", m.match) + assert_equal(0, m.mis) + assert_equal(1, m.ins) + assert_equal(0, m.del) + assert_equal(4, m.length) + end + + def test_Dynamic_patmatch_with_two_insertions_and_edit_dist_one_returns_nil + assert_nil(@p.patmatch("atGcTg", 0, 1)) + end + + def test_Dynamic_patmatch_with_two_insertions_and_edit_dist_two_returns_correctly + m = @p.patmatch("atGcTg", 0, 2) + assert_equal(0, m.beg) + assert_equal("atcg", m.match) + assert_equal(0, m.mis) + assert_equal(2, m.ins) + assert_equal(0, m.del) + assert_equal(4, m.length) + end + + def test_Dynamic_patmatch_with_one_deletion_and_edit_distance_zero_returns_nil + assert_nil(@p.patmatch("acg")) + end + + def test_Dynamic_patmatch_with_one_deletion_and_edit_distance_one_returns_correctly + m = @p.patmatch("acg", 0, 1) + assert_equal(0, m.beg) + assert_equal("atcg", m.match) + assert_equal(0, m.mis) + assert_equal(0, m.ins) + assert_equal(1, m.del) + assert_equal(4, m.length) + end + + def test_Dynamic_patscan_locates_three_patterns_ok + p = Seq.new("test", "ataacgagctagctagctagctgactac") + assert_equal(3, p.patscan("tag").count) + end + + def test_Dynamic_patscan_with_pos_locates_two_patterns_ok + p = Seq.new("test", "ataacgagctagctagctagctgactac") + assert_equal(2, p.patscan("tag", 10).count) + end +end diff --git a/code_ruby/test/maasha/seq/test_patternmatcher.rb b/code_ruby/test/maasha/seq/test_patternmatcher.rb deleted file mode 100755 index 8e1121e..0000000 --- a/code_ruby/test/maasha/seq/test_patternmatcher.rb +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env ruby -$:.unshift File.join(File.dirname(__FILE__),'..','lib') - -# Copyright (C) 2007-2010 Martin A. Hansen. - -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -# http://www.gnu.org/copyleft/gpl.html - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - -# This software is part of the Biopieces framework (www.biopieces.org). - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - -require 'maasha/seq' -require 'maasha/seq/dynamic' -require 'test/unit' -require 'pp' - -class Seq - include Dynamic -end - -class TestDynamic < Test::Unit::TestCase - def setup - @p = Seq.new("test", "atcg") - end - - def test_Dynamic_no_match_returns_nil - assert_nil(@p.patmatch("gggg")) - end - - def test_Dynamic_patmatch_perfect_returns_correctly - m = @p.patmatch("atcg") - assert_equal(0, m.beg) - assert_equal("atcg", m.match) - assert_equal(0, m.mis) - assert_equal(0, m.ins) - assert_equal(0, m.del) - assert_equal(4, m.length) - end - - def test_Dynamic_patmatch_perfect_with_ambiguity_codes_returns_correctly - m = @p.patmatch("nnnn") - assert_equal(0, m.beg) - assert_equal("atcg", m.match) - assert_equal(0, m.mis) - assert_equal(0, m.ins) - assert_equal(0, m.del) - assert_equal(4, m.length) - end - - def test_Dynamic_patmatch_with_one_mismatch_and_edit_dist_zero_returns_nil - assert_nil(@p.patmatch("aCcg")) - end - - def test_Dynamic_patmatch_with_one_mismatch_and_edit_dist_one_returns_correctly - m = @p.patmatch("aCcg", 0, 1) - assert_equal(0, m.beg) - assert_equal("atcg", m.match) - assert_equal(1, m.mis) - assert_equal(0, m.ins) - assert_equal(0, m.del) - assert_equal(4, m.length) - end - - def test_Dynamic_patmatch_with_two_mismatch_and_edit_dist_one_returns_nil - assert_nil(@p.patmatch("aGcA", 0, 1)) - end - - def test_Dynamic_patmatch_with_one_insertion_and_edit_dist_zero_returns_nil - assert_nil(@p.patmatch("atGcg")) - end - - def test_Dynamic_patmatch_with_one_insertion_and_edit_dist_one_returns_correctly - m = @p.patmatch("atGcg", 0, 1) - assert_equal(0, m.beg) - assert_equal("atcg", m.match) - assert_equal(0, m.mis) - assert_equal(1, m.ins) - assert_equal(0, m.del) - assert_equal(4, m.length) - end - - def test_Dynamic_patmatch_with_two_insertions_and_edit_dist_one_returns_nil - assert_nil(@p.patmatch("atGcTg", 0, 1)) - end - - def test_Dynamic_patmatch_with_two_insertions_and_edit_dist_two_returns_correctly - m = @p.patmatch("atGcTg", 0, 2) - assert_equal(0, m.beg) - assert_equal("atcg", m.match) - assert_equal(0, m.mis) - assert_equal(2, m.ins) - assert_equal(0, m.del) - assert_equal(4, m.length) - end - - def test_Dynamic_patmatch_with_one_deletion_and_edit_distance_zero_returns_nil - assert_nil(@p.patmatch("acg")) - end - - def test_Dynamic_patmatch_with_one_deletion_and_edit_distance_one_returns_correctly - m = @p.patmatch("acg", 0, 1) - assert_equal(0, m.beg) - assert_equal("atcg", m.match) - assert_equal(0, m.mis) - assert_equal(0, m.ins) - assert_equal(1, m.del) - assert_equal(4, m.length) - end - - def test_Dynamic_patscan_locates_three_patterns_ok - p = Seq.new("test", "ataacgagctagctagctagctgactac") - assert_equal(3, p.patscan("tag").count) - end - - def test_Dynamic_patscan_with_pos_locates_two_patterns_ok - p = Seq.new("test", "ataacgagctagctagctagctgactac") - assert_equal(2, p.patscan("tag", 10).count) - end -end