[BioRuby-cvs] bioruby/test/unit/bio/sequence test_common.rb, NONE, 1.1 test_compat.rb, NONE, 1.1
Mitsuteru C. Nakao
nakao at pub.open-bio.org
Sun Feb 5 17:39:29 UTC 2006
Update of /home/repository/bioruby/bioruby/test/unit/bio/sequence
In directory pub.open-bio.org:/tmp/cvs-serv30733/test/unit/bio/sequence
Added Files:
test_common.rb test_compat.rb
Log Message:
* test_common.rb: added.
* test_compat.rb: added.
* test_sequence.rb: moved some test codes to test_common.rb or test_compat.rb.
--- NEW FILE: test_compat.rb ---
#
# test/unit/bio/sequence/test_compat.rb - Unit test for Bio::Sequencce::Compat
#
# Copyright (C) 2006 Mitsuteru C. Nakao <n at bioruby.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: test_compat.rb,v 1.1 2006/02/05 17:39:27 nakao Exp $
#
require 'pathname'
libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
$:.unshift(libpath) unless $:.include?(libpath)
require 'test/unit'
require 'bio/sequence'
require 'bio/sequence/compat'
module Bio
class TSequence < String
include Bio::Sequence::Common
end
class TestSequenceCompat < Test::Unit::TestCase
def setup
@obj = TSequence.new('atgcatgcatgcatgcaaaa')
end
def test_to_s
str = 'atgcatgcatgcatgcaaaa'
assert_equal(str, @obj.to_s)
end
end
class TestSequenceCommonCompat < Test::Unit::TestCase
# Test Sequence#to_fasta
def test_to_fasta
sequence = TSequence.new("agtc" * 10)
header = "the header"
str = ">the header\n" + ("agtc" * 5) + "\n" + ("agtc" * 5) + "\n"
assert_equal(str, sequence.to_fasta(header, 20))
end
end
require 'bio/sequence/na'
class TestSequenceNACompat < Test::Unit::TestCase
def test_na_self_randomize
composition = Bio::Sequence::NA.new("acgtacgt").composition
assert(Bio::Sequence::NA.randomize(composition))
end
end
require 'bio/sequence/aa'
class TestSequenceNACompat < Test::Unit::TestCase
def test_aa_self_randomize
composition = Bio::Sequence::AA.new("WWDTGAK").composition
assert(Bio::Sequence::AA.randomize(composition))
end
end
end
--- NEW FILE: test_common.rb ---
#
# test/unit/bio/sequence/test_common.rb - Unit test for Bio::Sequencce::Common
#
# Copyright (C) 2006 Mitsuteru C. Nakao <n at bioruby.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: test_common.rb,v 1.1 2006/02/05 17:39:27 nakao Exp $
#
require 'pathname'
libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
$:.unshift(libpath) unless $:.include?(libpath)
require 'test/unit'
require 'bio/sequence'
require 'bio/sequence/common'
module Bio
class TSequence < String
include Bio::Sequence::Common
end
class TestSequenceCommon < Test::Unit::TestCase
def setup
@obj = TSequence.new('atgcatgcatgcatgcaaaa')
end
def test_to_s
assert_equal('atgcatgcatgcatgcaaaa', @obj.to_s)
end
def test_seq
str = "atgcatgcatgcatgcaaaa"
assert_equal(str, @obj.seq)
end
# <<(*arg)
def test_push
str = "atgcatgcatgcatgcaaaaA"
assert_equal(str, @obj << "A")
end
# +(*arg)
def test_sum
str = "atgcatgcatgcatgcaaaaatgcatgcatgcatgcaaaa"
assert_equal(str, @obj + @obj)
end
# window_search(window_size, step_size = 1)
def test_window_search
@obj.window_search(4) do |subseq|
assert_equal(20, @obj.size)
end
end
#total(hash)
def test_total
hash = {'a' => 1, 'c' => 2, 'g' => 4, 't' => 3}
assert_equal(44.0, @obj.total(hash))
end
def test_composition
composition = {"a"=>8, "c"=>4, "g"=>4, "t"=>4}
assert_equal(composition, @obj.composition)
end
def test_splicing
#(position)
assert_equal("atgcatgc", @obj.splicing("join(1..4, 13..16)"))
end
end
class TestSequenceCommonNormalize < Test::Unit::TestCase
def test_no_normalize
str = "atgcatgcatgcatgcaaaA"
obj = Bio::TSequence.new(str)
assert_equal("atgcatgcatgcatgcaaaA", obj)
end
def test_normalize_A
str = "atgcatgcatgcatgcaaaA"
seq = Bio::TSequence.new(str)
assert_equal("atgcatgcatgcatgcaaaA", seq)
obj = seq.normalize!
assert_equal("atgcatgcatgcatgcaaaA", obj)
end
def test_normalize_a
str = "atgcatgcatgcatgcaaa"
seq = Bio::TSequence.new(str)
assert_equal("atgcatgcatgcatgcaaa", seq)
obj = seq.normalize!
assert_equal("atgcatgcatgcatgcaaa", obj)
end
end
class TestSequenceCommonRansomize < Test::Unit::TestCase
def test_self_randomize
# self.randomize(*arg, &block)
end
def test_randomize
#randomize(hash = nil)
end
end
class TestSequenceCommonSubseq < Test::Unit::TestCase
#def subseq(s = 1, e = self.length)
def test_to_s_returns_self_as_string
s = "abcefghijklmnop"
sequence = TSequence.new(s)
assert_equal(s, sequence.to_s, "wrong value")
assert_instance_of(String, sequence.to_s, "not a String")
end
def test_subseq_returns_nil_blank_sequence_default_end
sequence = TSequence.new("")
assert_equal(nil, sequence.subseq(5))
end
def test_subseq_returns_nil_start_less_than_one
sequence = TSequence.new("blahblah")
assert_nil(sequence.subseq(0))
end
def test_subseq_returns_subsequence
sequence = TSequence.new("hahasubhehe")
assert_equal("sub", sequence.subseq(5,7))
end
end
# Test Sequence#window_wearch
class TestSequenceCommonWindowSearch < Test::Unit::TestCase
def test_window_search_with_width_3_default_step_no_residual
sequence = TSequence.new("agtca")
windows = []
returned_value = sequence.window_search(3) { |window| windows << window }
assert_equal(["agt", "gtc", "tca"], windows, "windows wrong")
assert_equal("", returned_value, "returned value wrong")
end
# added
def test_window_search_with_width_3_step_two_with_residual
sequence = TSequence.new("agtcat")
windows = []
returned_value = sequence.window_search(3, 2) { |window| windows << window }
assert_equal(["agt", "tca"], windows, "windows wrong")
assert_equal("t", returned_value, "returned value wrong")
end
end
end
More information about the bioruby-cvs
mailing list