File: test_feature.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 (147 lines) | stat: -rw-r--r-- 3,237 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#
# test/unit/bio/test_feature.rb - Unit test for Features/Feature classes
#
# Copyright::  Copyright (C) 2005 
#              Mitsuteru 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__), ['..'] * 2,
                            'bioruby_test_helper.rb')).cleanpath.to_s

# libraries needed for the tests
require 'test/unit'
require 'bio/feature'
require 'bio/compat/features'


module Bio

  class TestQualifier < Test::Unit::TestCase
    def setup
      qualifier = 'gene'
      value = 'CDS'
      @obj = Bio::Feature::Qualifier.new(qualifier, value)
    end

    def test_qualifier
      assert_equal('gene', @obj.qualifier)
    end

    def test_value
      assert_equal('CDS', @obj.value)
    end
  end


  class TestFeature < Test::Unit::TestCase
    def setup
      @qualifier = Bio::Feature::Qualifier.new('organism', 'Arabidopsis thaliana')
      feature = "source"
      position = '1..615'
      qualifiers = [@qualifier]
      @obj = Bio::Feature.new(feature, position, qualifiers)
    end

    def test_new
      assert(Bio::Feature.new)
    end

    def test_feature
      assert_equal("source", @obj.feature)
    end

    def test_position
      assert_equal('1..615', @obj.position)
    end

    def test_qualifiers
      assert_equal([@qualifier], @obj.qualifiers)
    end
    
    def test_locations
      assert_equal(1, @obj.locations.first.from)
      assert_equal(615, @obj.locations.first.to)
    end

    def test_append_nil
      assert(@obj.append(nil))
      assert_equal(1, @obj.qualifiers.size)
    end

    def test_append
      qualifier = Bio::Feature::Qualifier.new('db_xref', 'taxon:3702')
      assert(@obj.append(qualifier))
      assert_equal('db_xref', @obj.qualifiers.last.qualifier)
    end

    def test_each
      @obj.each do |qua| 
        assert_equal('Arabidopsis thaliana', qua.value)
      end
    end

    def test_assoc
      @obj.append(Bio::Feature::Qualifier.new("organism", "Arabidopsis thaliana"))
      assert_equal({"organism" => "Arabidopsis thaliana"}, @obj.assoc)
    end
  end

  class TestFeatures < Test::Unit::TestCase

    class NullStderr
      def initialize
        @log = []
      end

      def write(*arg)
        #p arg
        @log.push([ :write, *arg ])
        nil
      end

      def method_missing(*arg)
        #p arg
        @log.push arg
        nil
      end
    end #class NullStderr

    def setup
      # To suppress warning messages, $stderr is replaced by dummy object.
      @stderr_orig = $stderr
      $stderr = NullStderr.new

      @obj = Bio::Features.new([Bio::Feature.new('gene', '1..615', [])])
    end

    def teardown
      # bring back $stderr
      $stderr = @stderr_orig
    end
    
    def test_features
      assert_equal(1, @obj.features.size)
    end

    def test_append
      assert(@obj.append(Bio::Feature.new('gene', '1..615', [])))
      assert_equal(2, @obj.features.size)
    end

    def test_each
      @obj.each do |feature| 
        assert_equal('gene', feature.feature)
      end
    end

    def test_arg # def [](*arg)
      assert_equal('gene', @obj[0].feature)
    end
  end

end