X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=code_ruby%2Ftest%2Fmaasha%2Fseq%2Ftest_backtrack.rb;h=f244aab38a5ea1cc1ecf0ba283283746229238a7;hb=4c74f0aa5b9a572a2552767d4c4c0c15166e092a;hp=b2bc7f7067cac626fa499c0a35bb9fd1b08130e7;hpb=acacd4528370a90149f57965f03b07c57ec8ee05;p=biopieces.git diff --git a/code_ruby/test/maasha/seq/test_backtrack.rb b/code_ruby/test/maasha/seq/test_backtrack.rb index b2bc7f7..f244aab 100644 --- a/code_ruby/test/maasha/seq/test_backtrack.rb +++ b/code_ruby/test/maasha/seq/test_backtrack.rb @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -$:.unshift File.join(File.dirname(__FILE__),'..','lib') +$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..') # Copyright (C) 2007-2011 Martin A. Hansen. @@ -26,6 +26,7 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib') # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< require 'test/unit' +require 'test/helper' require 'maasha/seq' class BackTrackTest < Test::Unit::TestCase @@ -33,110 +34,128 @@ class BackTrackTest < Test::Unit::TestCase # 0 1 # 01234567890123456789 @seq = Seq.new("test", "tacgatgctagcatgcacgg") + @seq.extend(BackTrack) end - def test_BackTrack_patscan_with_bad_pattern_raises + test "#patscan with bad pattern raises" do ["", "X", "1"].each { |pattern| assert_raise(BackTrackError) { @seq.patscan(pattern) } } end - def test_BackTrack_patscan_with_OK_pattern_dont_raise + test "#patscan with OK pattern dont raise" do ["N", "atcg"].each { |pattern| assert_nothing_raised { @seq.patscan(pattern) } } end - def test_BackTrack_patscan_with_bad_pos_raises - [-1, 20].each { |pos| - assert_raise(BackTrackError) { @seq.patscan("N", pos) } + test "#patscan with bad start raises" do + [-1, 20].each { |start| + assert_raise(BackTrackError) { @seq.patscan("N", start) } } end - def test_BackTrack_patscan_with_OK_pos_dont_raise - [0, 19].each { |pos| - assert_nothing_raised { @seq.patscan("N", pos) } + test "#patscan with OK start dont raise" do + [0, 19].each { |start| + assert_nothing_raised { @seq.patscan("N", start) } } end - def test_BackTrack_patscan_with_bad_mis_raises + test "#patscan with bad stop raises" do + [-1, 20].each { |stop| + assert_raise(BackTrackError) { @seq.patscan("N", [0, stop]) } + } + end + + test "#patscan with OK stop dont raise" do + [0, 19].each { |stop| + assert_nothing_raised { @seq.patscan("N", [0, stop]) } + } + end + + test "#patscan with stop returns correctly" do + assert_nil(@seq.patmatch("G", [0, 2])) + assert_equal("3:1:g", @seq.patmatch("G", [0, 3]).to_s) + end + + test "#patscan with bad mis raises" do [-1, 6].each { |mis| assert_raise(BackTrackError) { @seq.patscan("N", 0, mis) } } end - def test_BackTrack_patscan_with_OK_mis_dont_raise + test "#patscan with OK mis dont raise" do [0, 5].each { |mis| assert_nothing_raised { @seq.patscan("N", 0, mis) } } end - def test_BackTrack_patscan_with_bad_ins_raises + test "#patscan with bad ins raises" do [-1, 6].each { |ins| assert_raise(BackTrackError) { @seq.patscan("N", 0, 0, ins) } } end - def test_BackTrack_patscan_with_OK_ins_dont_raise + test "#patscan with OK ins dont raise" do [0, 5].each { |ins| assert_nothing_raised { @seq.patscan("N", 0, 0, ins) } } end - def test_BackTrack_patscan_with_bad_del_raises + test "#patscan with bad del raises" do [-1, 6].each { |del| assert_raise(BackTrackError) { @seq.patscan("N", 0, 0, 0, del) } } end - def test_BackTrack_patscan_with_OK_del_dont_raise + test "#patscan with OK del dont raise" do [0, 5].each { |del| assert_nothing_raised { @seq.patscan("N", 0, 0, 0, del) } } end - def test_BackTrack_patscan_perfect_left_is_ok + test "#patscan perfect left is ok" do assert_equal("0:7:tacgatg", @seq.patscan("TACGATG").first.to_s) end - def test_BackTrack_patscan_perfect_right_is_ok + test "#patscan perfect right is ok" do assert_equal("13:7:tgcacgg", @seq.patscan("TGCACGG").first.to_s) end - def test_BackTrack_patscan_ambiguity_is_ok + test "#patscan ambiguity is ok" do assert_equal("13:7:tgcacgg", @seq.patscan("TGCACNN").first.to_s) end - def test_BackTrack_patscan_pos_is_ok + test "#patscan start is ok" do assert_equal("10:1:g", @seq.patscan("N", 10).first.to_s) assert_equal("19:1:g", @seq.patscan("N", 10).last.to_s) end - def test_BackTrack_patscan_mis_left_is_ok + test "#patscan mis left is ok" do assert_equal("0:7:tacgatg", @seq.patscan("Aacgatg", 0, 1).first.to_s) end - def test_BackTrack_patscan_mis_right_is_ok + test "#patscan mis right is ok" do assert_equal("13:7:tgcacgg", @seq.patscan("tgcacgA", 0, 1).first.to_s) end - def test_BackTrack_patscan_ins_left_is_ok + test "#patscan ins left is ok" do assert_equal("0:7:tacgatg", @seq.patscan("Atacgatg", 0, 0, 1).first.to_s) end - def test_BackTrack_patscan_ins_right_is_ok + test "#patscan ins right is ok" do assert_equal("13:7:tgcacgg", @seq.patscan("tgcacggA", 0, 0, 1).first.to_s) end - def test_BackTrack_patscan_del_left_is_ok + test "#patscan del left is ok" do assert_equal("0:7:tacgatg", @seq.patscan("acgatg", 0, 0, 0, 1).first.to_s) end - def test_BackTrack_patscan_del_right_is_ok + test "#patscan del right is ok" do assert_equal("12:8:atgcacgg", @seq.patscan("tgcacgg", 0, 0, 0, 1).first.to_s) end - def test_BackTrack_patscan_ambiguity_mis_ins_del_all_ok + test "#patscan ambiguity mis ins del all ok" do assert_equal("0:20:tacgatgctagcatgcacgg", @seq.patscan("tacatgcNagGatgcCacgg", 0, 1, 1, 1).first.to_s) end end