File: test_aa.rb

package info (click to toggle)
ruby-bio 2.0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,108 kB
  • sloc: ruby: 68,331; perl: 13; makefile: 11; sh: 1
file content (105 lines) | stat: -rw-r--r-- 2,594 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#
# = test/unit/bio/sequence/test_aa.rb - Unit test for Bio::Sequencce::AA
#
# Copyright::   Copyright (C) 2006 
#               Mitsuteru C. Nakao <n@bioruby.org>
# License::     The Ruby License
#
# $Id:$
#

# loading helper routine for testing bioruby
require 'pathname'
load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 3,
                            'bioruby_test_helper.rb')).cleanpath.to_s

# libraries needed for the tests
require 'test/unit'
require 'bio/sequence'
require 'bio/sequence/aa'


module Bio

  class TestSequenceAANew < Test::Unit::TestCase

    def test_new
      str = "RRLEHTFVFL RNFSLMLLRY"
      assert(Bio::Sequence::AA.new(str))
    end

    def test_new_t
      str = "RRLEHTFVFLRNFSLMLLRY"
      str_t = "RRLEHTFVFL\tRNFSLMLLRY"
      assert_equal(str, Bio::Sequence::AA.new(str_t))
    end

    def test_new_n
      str = "RRLEHTFVFLRNFSLMLLRY"
      str_n = "RRLEHTFVFL\nRNFSLMLLRY"
      assert_equal(str, Bio::Sequence::AA.new(str_n))
    end

    def test_new_r
      str = "RRLEHTFVFLRNFSLMLLRY"
      str_r = "RRLEHTFVFL\n\rRNFSLMLLRY"
      assert_equal(str, Bio::Sequence::AA.new(str_r))
    end

  end

  
  class TestSequenceAA < Test::Unit::TestCase

    def setup
      str = "RRLEHTFVFLRNFSLMLLRY"
      @obj = Bio::Sequence::AA.new(str)
    end

    def test_to_s
      str = "RRLEHTFVFLRNFSLMLLRY"
      assert_equal(str, @obj.to_s)
    end

    def test_molecular_weight
      assert_in_delta(2612.105, @obj.molecular_weight, 1e-4)
    end
    
    def test_to_re
      re = /RRLEHTFVFLRNFSLMLLRY/
      assert_equal(re, @obj.to_re)
      @obj[1, 1] = 'B'
      re = /R[DNB]LEHTFVFLRNFSLMLLRY/
      assert_equal(re, @obj.to_re)
    end

    def test_codes
      ary = ["Arg", "Arg", "Leu", "Glu", "His", "Thr", "Phe", "Val", 
             "Phe", "Leu", "Arg", "Asn", "Phe", "Ser", "Leu", "Met", 
             "Leu", "Leu", "Arg", "Tyr"]
      assert_equal(ary, @obj.codes)
    end

    def test_names
      ary = ["arginine", "arginine", "leucine", "glutamic acid", 
             "histidine", "threonine", "phenylalanine", "valine", 
             "phenylalanine", "leucine", "arginine", "asparagine", 
             "phenylalanine", "serine", "leucine", "methionine", 
             "leucine", "leucine", "arginine", "tyrosine"]
      assert_equal(ary, @obj.names)
    end

  end



  require 'bio/sequence/aa'  

  class TestSequenceAACompat < Test::Unit::TestCase
    def test_aa_self_randomize
      composition = Bio::Sequence::AA.new("WWDTGAK").composition
      assert(Bio::Sequence::AA.randomize(composition))
    end
  end

end