bio-nexml 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +0,0 @@
1
- module Bio
2
- module NeXML
3
- class TestParser < Test::Unit::TestCase
4
-
5
- def setup
6
- @doc = Parser.new( TEST_FILE, true )
7
- end
8
-
9
- def teardown
10
- @doc.close
11
- end
12
-
13
- def test_parse
14
- nexml = @doc.parse
15
- assert_instance_of Bio::NeXML::Nexml, nexml, "Should return an object of Bio::NeXML::Nexml"
16
- end
17
-
18
- end #end class TestParser
19
- end #end module NeXML
20
-
21
- end #end module Bio
@@ -1,118 +0,0 @@
1
- module Bio
2
- module NeXML
3
- class TestOtu < Test::Unit::TestCase
4
- def setup
5
- @otu = Bio::NeXML::Otu.new( 'taxon1', :label => 'A label for taxon1' )
6
- end
7
-
8
- def test_id
9
- assert_equal( 'taxon1', @otu.id )
10
- end
11
-
12
- def test_label
13
- assert_equal( 'A label for taxon1', @otu.label )
14
- end
15
-
16
- def test_id=
17
- @otu.id = 'taxon2'
18
- assert_equal( 'taxon2', @otu.id )
19
- end
20
-
21
- def test_label=
22
- @otu.label = 'New label for taxon1'
23
- assert_equal( 'New label for taxon1', @otu.label )
24
- end
25
- end
26
-
27
- class TestOtus < Test::Unit::TestCase
28
- def setup
29
- @otu1 = Bio::NeXML::Otu.new( 'taxon1', :label => 'A label for taxon1' )
30
- @otu2 = Bio::NeXML::Otu.new( 'taxon2', :label => 'A label for taxon2' )
31
- @otu3 = Bio::NeXML::Otu.new( 'taxon3', :label => 'A label for taxon3' )
32
- @otus = Bio::NeXML::Otus.new( 'taxa1', :label => 'A label for taxa1' )
33
- @otus << @otu1 << @otu2
34
- end
35
-
36
- def test_id
37
- assert_equal( 'taxa1', @otus.id )
38
- end
39
-
40
- def test_label
41
- assert_equal( 'A label for taxa1', @otus.label )
42
- end
43
-
44
- def test_id=
45
- @otus.id = 'taxa2'
46
- assert_equal( 'taxa2', @otus.id )
47
- end
48
-
49
- def test_label=
50
- @otus.label = 'New label for taxa1'
51
- assert_equal( 'New label for taxa1', @otus.label )
52
- end
53
-
54
- def test_hash_notation
55
- assert_equal( @otu1, @otus[ 'taxon1' ] )
56
- end
57
-
58
- def test_append_operator
59
- assert !@otus.include?( @otu3 )
60
- rvalue = @otus << @otu3
61
-
62
- # it should append otu to self
63
- assert @otus.include?( @otu3 )
64
-
65
- # it should return self, so that appends can be chained
66
- assert_instance_of Otus, rvalue
67
- end
68
-
69
- def test_delete
70
- rvalue = @otus.delete( @otu2 )
71
-
72
- # it should delete @otu2
73
- assert !@otus.include?( @otu2 )
74
-
75
- # it should return the deleted object
76
- assert_equal @otu2, rvalue
77
- end
78
-
79
- def test_otus
80
- [ @otu1, @otu2 ].each do |otu|
81
- @otus.otus.include?( otu )
82
- end
83
- end
84
-
85
- def test_otus=
86
- assert !@otus.include?( @otu3 )
87
- @otus.otus = [ @otu3 ]
88
- assert @otus.include?( @otu3 )
89
- end
90
-
91
- def test_each
92
- otus = [ @otu1, @otu2 ]
93
- @otus.each do |otu|
94
- assert otus.include?( otu )
95
- end
96
- end
97
-
98
- def test_each_with_id
99
- otus = [ @otu1, @otu2 ]
100
- @otus.each_with_id do |id, otu|
101
- assert otus.include?( otu )
102
- assert otus.include?( @otus[ id ] )
103
- end
104
- end
105
-
106
- def test_length
107
- assert_equal 2, @otus.length
108
- end
109
-
110
- def test_include
111
- # it should respond for an otu object
112
- assert @otus.include?( @otu1 )
113
-
114
- assert !@otus.include?( @otu3 )
115
- end
116
- end
117
- end
118
- end
@@ -1,370 +0,0 @@
1
- class TestNode < Test::Unit::TestCase
2
- def setup
3
- @otu = Bio::NeXML::Otu.new( 'o1' )
4
- @node = Bio::NeXML::Node.new( 'n1' )
5
- @node.otu = @otu
6
- end
7
-
8
- def test_id
9
- @node.id = 'foo'
10
- assert_equal( 'foo', @node.id )
11
- end
12
-
13
- def test_label
14
- @node.label = 'a node'
15
- assert_equal( 'a node', @node.label )
16
- end
17
-
18
- def test_root?
19
- assert( !@node.root? )
20
- end
21
-
22
- def test_root=
23
- @node.root = true
24
- assert( @node.root )
25
- end
26
-
27
- def test_otu
28
- otu = Bio::NeXML::Otu.new( 'o2' )
29
- @node.otu = otu
30
-
31
- assert_equal( otu, @node.otu )
32
- assert_equal( otu.nodes, [ @node ] )
33
- end
34
-
35
- end
36
-
37
- class TestEdge < Test::Unit::TestCase
38
- def setup
39
- @n1 = Bio::NeXML::Node.new( 'n1' )
40
- @n2 = Bio::NeXML::Node.new( 'n2' )
41
- @edge = Bio::NeXML::Edge.new( 'e1', :source => @n1, :target => @n2 )
42
- end
43
-
44
- def test_id
45
- @edge.id = 'e2'
46
- assert_equal( 'e2', @edge.id )
47
- end
48
-
49
- def test_label
50
- @edge.label = 'an edge'
51
- assert_equal( 'an edge', @edge.label )
52
- end
53
-
54
- def test_source
55
- n3 = Bio::NeXML::Node.new( 'n3' )
56
- @edge.source = n3
57
- assert_equal( n3, @edge.source )
58
- end
59
-
60
- def test_target
61
- n3 = Bio::NeXML::Node.new( 'n3' )
62
- @edge.target = n3
63
- assert_equal( n3, @edge.target )
64
- end
65
-
66
- def test_length
67
- @edge.length = 1
68
- assert_equal( 1, @edge.length )
69
- end
70
- end
71
-
72
- class TestRootEdge < TestEdge
73
- def setup
74
- @edge = Bio::NeXML::RootEdge.new( 're1', :target => @n1 )
75
- end
76
-
77
- def test_source
78
- assert !@re.respond_to?( :source= )
79
- end
80
- end
81
-
82
- class TestTree < Test::Unit::TestCase
83
-
84
- def setup
85
- @roots = %w|n1 n9|.map { |n| Bio::NeXML::Node.new( n, :root => true ) }
86
- @nodes = %w|n2 n3 n4 n5 n6 n7 n8|.map { |n| Bio::NeXML::Node.new( n ) }
87
- @nodes = @nodes + @roots
88
-
89
- @edges = %w|e12 e13 e34 e37 e45 e46 e78 e79|.map do |e|
90
- source = @nodes.find { |n| n.id == "n#{e[1,1]}" }
91
- target = @nodes.find { |n| n.id == "n#{e[2,1]}" }
92
- Bio::NeXML::Edge.new( e, :source => source, :target => target )
93
- end
94
-
95
- @re = Bio::NeXML::RootEdge.new( 're1', :target => @n1 )
96
-
97
- @tree = Bio::NeXML::Tree.new( 'tree1', :nodes => @nodes, :edges => @edges, :rootedge => @re )
98
- end
99
-
100
- def test_id
101
- assert_equal( 'tree1', @tree.id )
102
- @tree.id = 'tree2'
103
- assert_equal( 'tree2', @tree.id )
104
- end
105
-
106
- def test_label
107
- assert_nil( @tree.label )
108
- @tree.label = 'a tree'
109
- assert_equal( 'a tree', @tree.label )
110
- end
111
-
112
- def test_rootedge
113
- assert_equal( @re, @tree.rootedge )
114
- re = Bio::NeXML::RootEdge.new( 're2', :target => @n9 )
115
- @tree.rootedge = re
116
- assert_equal( re, @tree.rootedge )
117
- end
118
-
119
- def test_roots
120
- @roots.each do |r|
121
- assert @tree.roots.include?( r )
122
- end
123
- end
124
-
125
- def test_add_node
126
- node = Bio::NeXML::Node.new( 'node' )
127
- @tree.add_node( node )
128
- assert @tree.include?( node )
129
- assert_equal( @tree, node.tree )
130
- end
131
-
132
- def test_add_edge
133
- node1 = Bio::NeXML::Node.new( 'node1' )
134
- node2 = Bio::NeXML::Node.new( 'node2' )
135
- edge = Bio::NeXML::Edge.new( 'edge', :source => node1, :target => node2 )
136
- @tree << node1 << node2 << edge
137
-
138
- assert @tree.include?( edge )
139
- assert_equal( @tree, edge.tree )
140
- end
141
-
142
- def test_delete_node
143
- n = @nodes[ 2 ]
144
- @tree.delete_node( n )
145
- assert !@tree.include?( n )
146
- end
147
-
148
- def test_delete_edge
149
- @tree.delete_edge( @edges[ 1 ] )
150
- assert !@tree.include?( @edges[ 1 ] )
151
- end
152
-
153
- def test_append_operator
154
- n10 = Bio::NeXML::Node.new( 'n10' )
155
- e9 = Bio::NeXML::Edge.new( 'e9', :source => @n9, :target => n10 )
156
-
157
- @tree << n10
158
- @tree << e9
159
-
160
- @tree.include?( n10 )
161
- @tree.include?( e9 )
162
- end
163
-
164
- def test_get_node_by_id
165
- assert_equal( @nodes[ 0 ], @tree.get_node_by_id( 'n2' ) )
166
- end
167
-
168
- def test_get_edge_by_id
169
- assert_equal( @edges[ 0 ], @tree.get_edge_by_id( 'e12' ) )
170
- end
171
-
172
- def test_hash_notation
173
- assert_equal( @nodes[ 0 ], @tree[ 'n2' ] )
174
- assert_equal( @edges[ 0 ], @tree[ 'e12' ] )
175
- end
176
-
177
- def test_has_node
178
- assert @tree.has_node?( @nodes[ 0 ] )
179
- assert !@tree.has_node?( Bio::NeXML::Node.new( 'foo' ) )
180
- end
181
-
182
- def test_has_edge
183
- assert @tree.has_edge?( @edges[ 0 ] )
184
- assert !@tree.has_edge?( Bio::NeXML::Edge.new( 'foo' ) )
185
- end
186
-
187
- def test_include
188
- assert @tree.include?( @nodes[ 0 ] )
189
- assert @tree.include?( @edges[ 0 ] )
190
- end
191
-
192
- def test_each_node
193
- c = 0
194
- @tree.each_node do |n|
195
- assert @tree.include?( n )
196
- c +=1
197
- end
198
- assert @tree.number_of_nodes, c
199
- end
200
-
201
- def test_each_node_with_id
202
- c = 0
203
- @tree.each_node_with_id do |i, n|
204
- assert @tree.include?( n )
205
- assert_equal( n.id, i )
206
- c +=1
207
- end
208
- assert @tree.number_of_nodes, c
209
- end
210
-
211
- def test_each_edge
212
- c = 0
213
- @tree.each_edge do |e|
214
- assert @tree.include?( e )
215
- c +=1
216
- end
217
- assert @tree.number_of_edges, c
218
- end
219
-
220
- def test_each_edge_with_id
221
- c = 0
222
- @tree.each_edge_with_id do |i, e|
223
- assert @tree.include?( e )
224
- assert_equal( e.id, i )
225
- c +=1
226
- end
227
- assert @tree.number_of_edges, c
228
- end
229
- end #end class TestTree
230
-
231
- class TestTrees < Test::Unit::TestCase
232
-
233
- def setup
234
- @otus = Bio::NeXML::Otus.new( 'o1' )
235
- @tree = Bio::NeXML::Tree.new( 't1' )
236
- @network = Bio::NeXML::Network.new( 'n1' )
237
- @trees = Bio::NeXML::Trees.new( 'trees1', :label => 'Tree container' )
238
- @trees.add_tree( @tree )
239
- @trees.add_network( @network )
240
- end
241
-
242
- def test_id
243
- @trees.id = 'trees2'
244
- assert_equal( 'trees2', @trees.id )
245
- end
246
-
247
- def test_label
248
- @trees.label = 'Label changed'
249
- assert_equal( 'Label changed', @trees.label )
250
- end
251
-
252
- def test_hash_notation
253
- assert_equal( @trees[ 't1' ], @tree )
254
- assert_equal( @trees[ 'n1' ], @network )
255
- assert_nil( @trees[ 'foo' ] )
256
- end
257
-
258
- def test_append_operator
259
- tree = Bio::NeXML::Tree.new( 't2' )
260
- network = Bio::NeXML::Tree.new( 'n2' )
261
-
262
- @trees << tree << network
263
-
264
- assert( @trees.include?( tree ) )
265
- assert( @trees.include?( network ) )
266
-
267
- assert_equal( @trees, tree.trees )
268
- assert_equal( @trees, network.trees )
269
- end
270
-
271
- def test_trees
272
- assert_equal( [ @tree ], @trees.trees )
273
- end
274
-
275
- def test_network
276
- assert_equal( [ @network ], @trees.networks )
277
- end
278
-
279
- def test_add_tree
280
- tree = Bio::NeXML::Tree.new( 't2' )
281
- @trees << tree
282
- assert( @trees.include?( tree ) )
283
- assert_equal( @trees, tree.trees )
284
- end
285
-
286
- def test_add_network
287
- network = Bio::NeXML::Tree.new( 'n2' )
288
- @trees << network
289
- assert( @trees.include?( network ) )
290
- assert_equal( @trees, network.trees )
291
- end
292
-
293
- def test_has_tree?
294
- assert( @trees.has_tree?( @tree ) )
295
- end
296
-
297
- def test_has_network?
298
- assert( @trees.has_network?( @network ) )
299
- end
300
-
301
- def test_include?
302
- assert( @trees.include?( @tree ) )
303
- assert( @trees.include?( @network ) )
304
- assert( !@trees.include?( Bio::NeXML::Tree.new( 'foo' ) ) )
305
- end
306
-
307
- def test_number_of_trees
308
- assert_equal( 1, @trees.number_of_trees )
309
- end
310
-
311
- def test_number_of_networks
312
- assert_equal( 1, @trees.number_of_networks )
313
- end
314
-
315
- def test_count
316
- assert_equal 2, @trees.count
317
- end
318
-
319
- def test_get_tree_by_id
320
- assert_not_nil @trees.get_tree_by_id 't1'
321
- assert_nil @trees.get_tree_by_id 'foo'
322
- end
323
-
324
- def test_get_network_by_id
325
- assert_not_nil @trees.get_network_by_id 'n1'
326
- assert_nil @trees.get_network_by_id 'foo'
327
- end
328
-
329
- def test_each_tree
330
- c = 0
331
- @trees.each_tree {|t| c+=1 }
332
- assert_equal 1, c
333
- end
334
-
335
- def test_each_network
336
- c = 0
337
- @trees.each_network {|t| c+=1 }
338
- assert_equal 1, c
339
- end
340
-
341
- def test_each
342
- c = 0
343
- @trees.each {|t| c+=1 }
344
- assert_equal 2, c
345
- end
346
-
347
- end #end class TestTrees
348
-
349
- #class TestTree < Test::Unit::TestCase
350
-
351
- #def setup
352
- #@tree = Bio::NeXML::Tree.new 'tree'
353
- #end
354
-
355
- #def teardown
356
- #@tree = nil
357
- #end
358
-
359
- #def test_add_rootedge
360
- #target = Bio::NeXML::Node.new 'node1'
361
- #re = Bio::NeXML::RootEdge.new 're1', target, 2
362
- #@tree.add_rootedge re
363
- #assert @tree.rootedge
364
- #end
365
-
366
- #def test_target_cache
367
- #assert_instance_of Array, @tree.target_cache
368
- #end
369
-
370
- #end