#!/usr/bin/env ruby
-$:.unshift File.join(File.dirname(__FILE__),'..','lib')
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
# Copyright (C) 2007-2011 Martin A. Hansen.
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
require 'test/unit'
+require 'test/helper'
require 'maasha/seq'
-require 'maasha/seq/backtrack'
-
-class Seq
- include BackTrack
-end
class BackTrackTest < Test::Unit::TestCase
def setup
- # 0 1
- # 01234567890123456789
- @seq = Seq.new("test", "tacgatgctagcatgcacgg")
+ # 0 1
+ # 01234567890123456789
+ @seq = Seq.new(seq: "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
+
+ 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_OK_pos_dont_raise
- [0, 19].each { |pos|
- assert_nothing_raised { @seq.patscan("N", pos) }
+ test "#patscan with bad stop raises" do
+ [-1, 20].each { |stop|
+ assert_raise(BackTrackError) { @seq.patscan("N", [0, stop]) }
}
end
- def test_BackTrack_patscan_with_bad_mis_raises
+ 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