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,78 +0,0 @@
1
- module Bio
2
- module NeXML
3
- class TestMapper < Test::Unit::TestCase
4
-
5
- class Target
6
- include Bio::NeXML::Mapper
7
-
8
- attr_accessor :id
9
- belongs_to :source
10
- end
11
-
12
- class Source
13
- include Bio::NeXML::Mapper
14
-
15
- attr_accessor :id
16
- has_n :targets
17
- end
18
-
19
- def setup
20
- @s = Source.new
21
- @t1 = Target.new
22
- @t1.id = 't1'
23
- @t2 = Target.new
24
- @t2.id = 't2'
25
- @s.add_target( @t1 )
26
- end
27
-
28
- def test_has_target
29
- t2 = Target.new
30
- assert @s.has_target?( @t1 )
31
- assert !@s.has_target?( t2 )
32
- end
33
-
34
- def test_get_target_by_id
35
- assert_equal( @t1, @s.get_target_by_id( 't1' ) )
36
- assert_nil( @s.get_target_by_id( 't2' ) )
37
- end
38
-
39
- def test_add_target
40
- t2 = Target.new
41
- t2.id = 't2'
42
- @s.add_target( t2 )
43
-
44
- assert @s.has_target?( t2 )
45
- assert_equal( @s, t2.source )
46
- end
47
-
48
- def test_target
49
- assert_equal( [ @t1 ], @s.targets )
50
- end
51
-
52
- def test_target=
53
- t2 = Target.new
54
- @s.targets = [ t2 ]
55
- assert_equal( [ t2 ], @s.targets )
56
- assert_equal( @s, t2.source )
57
- end
58
-
59
- def test_delete_target
60
- assert_equal( @t1, @s.delete_target( @t1 ) )
61
- assert_nil( @t1.source )
62
- end
63
-
64
- def test_source
65
- assert_equal( @s, @t1.source )
66
- assert( @s.has_target?( @t1 ) )
67
- end
68
-
69
- def test_source=
70
- t2 = Target.new
71
- t2.id = 't2'
72
- t2.source = @s
73
- assert_equal( @s, t2.source )
74
- assert( @s.has_target?( t2 ) )
75
- end
76
- end #end TestOtu
77
- end #end NeXML
78
- end #end Bio
@@ -1,551 +0,0 @@
1
- module Bio
2
- module NeXML
3
- class TestState < Test::Unit::TestCase
4
- def setup
5
- @state = Bio::NeXML::State.new( 'stateA', 'A' )
6
- end
7
-
8
- def test_new1
9
- # if one argument given use it as id
10
- s = Bio::NeXML::State.new( 'stateA' )
11
- assert_equal 'stateA', s.id
12
- end
13
-
14
- def test_new2
15
- # if two argument given use them as id and sybmol respectively
16
- s = Bio::NeXML::State.new( 'stateA', 'A' )
17
- assert_equal 'stateA', s.id
18
- assert_equal 'A', s.symbol
19
- end
20
-
21
- def test_new3
22
- # options hash as third argument
23
- # preferred
24
- s = Bio::NeXML::State.new( 'stateA', 'A', :label => 'A label' )
25
- assert_equal 'stateA', s.id
26
- assert_equal 'A', s.symbol
27
- assert_equal 'A label', s.label
28
- end
29
-
30
- def test_new4
31
- # options hash as second argument
32
- s = Bio::NeXML::State.new( 'stateA', :symbol => 'A', :label => 'A label' )
33
- assert_equal 'stateA', s.id
34
- assert_equal 'A', s.symbol
35
- assert_equal 'A label', s.label
36
- end
37
-
38
- def test_id
39
- @state.id = 'state1'
40
- assert_equal 'state1', @state.id
41
- end
42
-
43
- def test_symbol
44
- @state.symbol = 1
45
- assert_equal 1, @state.symbol
46
- end
47
-
48
- def test_label
49
- @state.label = 'State'
50
- assert_equal 'State', @state.label
51
- end
52
-
53
- def test_ambiguous
54
- assert !@state.ambiguous?
55
- end
56
-
57
- def test_ambiguity
58
- assert_nil @state.ambiguity
59
- end
60
-
61
- def test_to_str
62
- assert_equal 'A', @state.to_str
63
- end
64
- end
65
-
66
- class TestAmbiguousState < TestState
67
- def setup
68
- @members = [
69
- %w|s1 A|,
70
- %w|s2 B|,
71
- %w|s3 C|,
72
- %w|s4 D|,
73
- %w|s5 E|
74
- ].map { | pair | Bio::NeXML::State.new( *pair ) }
75
-
76
- @state = Bio::NeXML::State.uncertain( 'state1', '?' )
77
- @state.members = @members
78
- end
79
-
80
- def test_new5
81
- s = Bio::NeXML::State.new( 'stateA', 'A', :ambiguity => :polymorphic )
82
- assert s.ambiguous?
83
- assert_equal :polymorphic, s.ambiguity
84
- end
85
-
86
- def test_new6
87
- s = Bio::NeXML::State.new( 'stateA', 'A', :ambiguity => :uncertain, :members => @members )
88
- assert_equal @members, s.members
89
- end
90
-
91
- def test_uncertain
92
- s = Bio::NeXML::State.uncertain( 'stateA', 'A', :members => @members )
93
- assert s.ambiguous?
94
- assert_equal :uncertain, s.ambiguity
95
- assert_equal @members, s.members
96
- end
97
-
98
- def test_polymorphic
99
- s = Bio::NeXML::State.polymorphic( 'stateA', 'A', :members => @members )
100
- assert s.ambiguous?
101
- assert_equal :polymorphic, s.ambiguity
102
- assert_equal @members, s.members
103
- end
104
-
105
- def test_ambiguous
106
- assert @state.ambiguous?
107
- end
108
-
109
- def test_ambiguity
110
- assert_equal :uncertain, @state.ambiguity
111
- end
112
-
113
- def test_add_member
114
- s = Bio::NeXML::State.new( 's6', 'F' )
115
- @state.add_member( s )
116
- assert @state.has_member?( s )
117
- assert_equal @state, s.state_set
118
- end
119
-
120
- def test_delete_member
121
- s = @members[ 0 ]
122
- assert_equal( s, @state.delete_member( s ) )
123
- assert_nil s.state_set
124
- end
125
-
126
- def test_members
127
- s = @members[ 0 ]
128
- @state.members = [ s ]
129
- assert_equal [ s ], @state.members
130
- assert_equal @state, s.state_set
131
- end
132
-
133
- def test_include
134
- assert @state.include?( @members[ 0 ] )
135
- end
136
-
137
- def test_count
138
- assert_equal @members.length, @state.count
139
- end
140
-
141
- def test_each
142
- end
143
-
144
- def test_each_with_symbol
145
- end
146
-
147
- def test_to_str
148
- assert_equal '?', @state.to_str
149
- end
150
- end #end class TestAmbiguousState
151
-
152
- class TestChar < Test::Unit::TestCase
153
- def setup
154
- @states = Bio::NeXML::States.new( 'states' )
155
- @char = Bio::NeXML::Char.new( 'char1' )
156
- end
157
-
158
- def test_new1
159
- # if one argument given use it as id
160
- c = Bio::NeXML::Char.new( 'char1' )
161
- assert_equal 'char1', c.id
162
- end
163
-
164
- def test_new2
165
- # if two arguments given use the second as states
166
- c = Bio::NeXML::Char.new( 'char1', @states )
167
- assert_equal 'char1', c.id
168
- assert_equal @states, c.states
169
- end
170
-
171
- def test_new3
172
- # 3rd argument as optional hash
173
- c = Bio::NeXML::Char.new( 'char1', @states, :label => 'A label' )
174
- assert_equal 'char1', c.id
175
- assert_equal @states, c.states
176
- assert_equal 'A label', c.label
177
- end
178
-
179
- def test_new4
180
- # 2nd argument as optional hash
181
- c = Bio::NeXML::Char.new( 'char1', :states => @states, :label => 'A label' )
182
- assert_equal 'char1', c.id
183
- assert_equal @states, c.states
184
- assert_equal 'A label', c.label
185
- end
186
-
187
- def test_id
188
- @char.id = 'char2'
189
- assert_equal 'char2', @char.id
190
- end
191
-
192
- def test_label
193
- @char.label = 'A label'
194
- assert_equal 'A label', @char.label
195
- end
196
-
197
- def test_states
198
- @char.states = @states
199
- assert_equal @states, @char.states
200
- assert @states.has_char?( @char )
201
- end
202
-
203
- def test_cells
204
- cell = Bio::NeXML::Cell.new( @char )
205
- assert_equal [ cell ], @char.cells
206
- end
207
- end
208
-
209
- class TestStates < Test::Unit::TestCase
210
- def setup
211
- @ss = [
212
- %w|s1 A|,
213
- %w|s2 B|,
214
- %w|s3 C|,
215
- %w|s4 D|,
216
- %w|s5 E|
217
- ].map { | pair | Bio::NeXML::State.new( *pair ) }
218
- @states = Bio::NeXML::States.new( 'states', :states => @ss )
219
- end
220
-
221
- def test_new1
222
- # one argument => id
223
- states = Bio::NeXML::States.new( 'states' )
224
- assert_equal 'states', states.id
225
- end
226
-
227
- def test_new2
228
- # second argument => optional hash
229
- states = Bio::NeXML::States.new( 'states', :label => 'state container' )
230
- assert_equal 'states', states.id
231
- assert_equal 'state container', states.label
232
- end
233
-
234
- def test_id
235
- @states.id = 'states1'
236
- assert_equal 'states1', @states.id
237
- end
238
-
239
- def test_label
240
- @states.label = 'a label'
241
- assert_equal 'a label', @states.label
242
- end
243
-
244
- def test_add_state
245
- s = Bio::NeXML::State.new( 's6', 'F' )
246
- @states.add_state( s )
247
- assert @states.include?( s )
248
- assert_equal @states, s.states
249
- end
250
-
251
- def test_delete_state
252
- s = @ss[ 0 ]
253
- assert_equal s, @states.delete_state( s )
254
- assert_nil s.states
255
- end
256
-
257
- def test_states
258
- s = @ss[ 0 ]
259
- @states.states = [ s ]
260
- assert_equal [ s ], @states.states
261
- assert_equal @states, s.states
262
- end
263
-
264
- def test_get_state_by_id
265
- s = @ss[ 0 ]
266
- assert_equal s, @states.get_state_by_id( s.id )
267
- end
268
-
269
- def test_has_state
270
- assert @states.has_state?( @ss[ 0 ] )
271
- end
272
-
273
- def test_chars
274
- char = Bio::NeXML::Char.new( 'char', @states )
275
- assert_equal @states, char.states
276
- assert_equal [ char ], @states.chars
277
- end
278
- end
279
-
280
- class TestCell_new < Test::Unit::TestCase
281
- # test Bio::NeXML::Cell.new as a cell can be initialized in mulitple ways
282
- # depending on type( bound/ unbound ) and need.
283
-
284
- def test_new1
285
- # unbound cell, no options
286
- cell = Bio::NeXML::Cell.new( 'A' )
287
- assert_equal 'A', cell.value
288
- end
289
-
290
- def test_new2
291
- # unbound cell, with options
292
- cell = Bio::NeXML::Cell.new( 'A', :label => 'label' )
293
- assert_equal 'A', cell.value
294
- assert_equal 'label', cell.label
295
- end
296
-
297
- def test_new3
298
- # bound cell, no options
299
- ch = Bio::NeXML::Char.new( 'ch' )
300
- s = Bio::NeXML::State.new( 'ss' )
301
- cell = Bio::NeXML::Cell.new( ch, s )
302
- assert_equal ch, cell.char
303
- assert_equal s, cell.state
304
- end
305
-
306
- def test_new4
307
- # bound cell, with options
308
- ch = Bio::NeXML::Char.new( 'ch' )
309
- s = Bio::NeXML::State.new( 'ss' )
310
- cell = Bio::NeXML::Cell.new( ch, s, :label => 'label' )
311
- assert_equal ch, cell.char
312
- assert_equal s, cell.state
313
- assert_equal 'label', cell.label
314
- end
315
-
316
- def test_new5
317
- # all keyword args
318
- ch = Bio::NeXML::Char.new( 'ch' )
319
- s = Bio::NeXML::State.new( 'ss' )
320
- cell = Bio::NeXML::Cell.new( :char => ch, :state => s, :label => 'label' )
321
- assert_equal ch, cell.char
322
- assert_equal s, cell.state
323
- assert_equal 'label', cell.label
324
- end
325
- end
326
-
327
- class TestUnboundCell < Test::Unit::TestCase
328
- def setup
329
- @cell = Bio::NeXML::Cell.new( 'A', :label => 'label' )
330
- end
331
-
332
- def test_state
333
- assert_nil @cell.state
334
- end
335
-
336
- def test_char
337
- assert_nil @cell.char
338
- end
339
-
340
- def test_bound
341
- assert !@cell.bound?
342
- end
343
-
344
- def test_value
345
- @cell.value = 'B'
346
- assert_equal 'B', @cell.value
347
- end
348
- end
349
-
350
- class TestBoundCell < Test::Unit::TestCase
351
- def setup
352
- @stateA = Bio::NeXML::State.new( 'stateA', 'A' )
353
- @char = Bio::NeXML::Char.new( 'char' )
354
- @cell = Bio::NeXML::Cell.new( :char => @char, :state => @stateA )
355
- end
356
-
357
- def test_state
358
- s = Bio::NeXML::State.new( 'stateB', 'B' )
359
- @cell.state = s
360
- assert_equal s, @cell.state
361
- end
362
-
363
- def test_char
364
- c = Bio::NeXML::Char.new( 'ch' )
365
- @cell.char = c
366
- assert_equal c, @cell.char
367
- end
368
-
369
- def test_value
370
- assert_equal @stateA.symbol, @cell.value
371
- @cell.value = 'B'
372
- assert_not_equal 'B', @cell.value # since it is a bound cell
373
- @stateA.symbol = 'B'
374
- assert_equal 'B', @cell.value # a bound cell reflects the value of its state
375
- end
376
- end
377
-
378
- class TestRow < Test::Unit::TestCase
379
- def setup
380
- @row = Bio::NeXML::Row.new( 'seq' )
381
- end
382
-
383
- def test_id
384
- @row.id = 'seq1'
385
- assert_equal 'seq1', @row.id
386
- end
387
-
388
- def test_label
389
- @row.label = 'a sequence'
390
- assert_equal 'a sequence', @row.label
391
- end
392
-
393
- def test_otu
394
- otu = Bio::NeXML::Otu.new( 'otu' )
395
- @row.otu = otu
396
- assert_equal otu, @row.otu
397
- assert_equal [ @row ], otu.rows
398
- end
399
- end
400
-
401
- class TestMatrix < Test::Unit::TestCase
402
- def setup
403
- @ss = [
404
- %w|s1 A|,
405
- %w|s2 B|,
406
- %w|s3 C|,
407
- %w|s4 D|,
408
- %w|s5 E|
409
- ].map { | pair | Bio::NeXML::State.new( *pair ) }
410
- @states = Bio::NeXML::States.new( 'states', :states => @ss )
411
-
412
- @char1 = Bio::NeXML::Char.new( 'char1', :states => @states )
413
- @char2 = Bio::NeXML::Char.new( 'char2', :states => @states )
414
-
415
- @sequence = Bio::NeXML::Sequence.new( :value => 'ABCDE' )
416
- @row = Bio::NeXML::SeqRow.new( 'row1' )
417
- @matrix = Bio::NeXML::Protein.new( 'matrix1' )
418
- @format = Bio::NeXML::Format.new
419
- @format.add_states( @states )
420
- @format.chars = [ @char1, @char2 ]
421
- @row.add_sequence( @sequence )
422
- end
423
-
424
- def test_id
425
- @matrix.id = 'id'
426
- assert_equal 'id', @matrix.id
427
- end
428
-
429
- def test_label
430
- @matrix.label = 'label'
431
- assert_equal 'label', @matrix.label
432
- end
433
-
434
- def test_nexml; end
435
-
436
- def test_otus
437
- otus = Bio::NeXML::Otus.new( 'otus' )
438
- @matrix.otus = otus
439
- assert_equal otus, @matrix.otus
440
- assert_equal [ @matrix ], otus.characters
441
- end
442
-
443
- def test_add_states
444
- ss = Bio::NeXML::States.new( 'ss' )
445
- @format.add_states( ss )
446
- assert @format.has_states?( ss )
447
- assert_equal @format, ss.format
448
- end
449
-
450
- def test_add_char
451
- ch = Bio::NeXML::Char.new( 'ch' )
452
- @format.add_char( ch )
453
- assert @format.has_char?( ch )
454
- assert_equal @format, ch.format
455
- end
456
-
457
- def test_add_sequence
458
- seq = Bio::NeXML::Sequence.new
459
- @row.add_sequence( seq )
460
- assert @row.has_sequence?( seq )
461
- assert_equal @row, seq.seqrow
462
- end
463
-
464
- def test_delete_states
465
- assert_equal @states, @format.delete_states( @states )
466
- assert !@format.has_states?( @states )
467
- assert_nil @states.format
468
- end
469
-
470
- def test_delete_char
471
- assert_equal @char1, @format.delete_char( @char1 )
472
- assert !@format.has_char?( @char1 )
473
- assert_nil @char1.format
474
- end
475
-
476
- def test_delete_sequence
477
- assert_equal @sequence, @row.delete_sequence( @sequence )
478
- assert !@row.has_sequence?( @sequence )
479
- assert_nil @sequence.row
480
- end
481
-
482
- def test_states
483
- assert_equal [ @states ], @format.states
484
- ss = Bio::NeXML::States.new( 'ss' )
485
- @format.states = [ ss ]
486
- assert_equal [ ss ], @format.states
487
- end
488
-
489
- def test_chars
490
- assert_equal [ @char1, @char2 ], @format.chars
491
- ch = Bio::NeXML::Char.new( 'ch' )
492
- @format.chars = [ ch ]
493
- assert_equal [ ch ], @format.chars
494
- end
495
-
496
- def test_sequences
497
- assert_equal [ @sequence ], @row.sequences
498
- seq = Bio::NeXML::Sequence.new
499
- @row.sequences = [ seq ]
500
- assert_equal [ seq ], @row.sequences
501
- end
502
-
503
- def test_get_states_by_id
504
- assert_equal @states, @format.get_states_by_id( 'states' )
505
- end
506
-
507
- def test_get_char_by_id
508
- assert_equal @char1, @format.get_char_by_id( 'char1' )
509
- end
510
-
511
- def test_each_states
512
- c = 0
513
- @format.each_states do |s|
514
- assert @format.has_states?( s )
515
- c += 1
516
- end
517
- assert_equal 1, c
518
- end
519
-
520
- def test_each_char
521
- c = 0
522
- @format.each_char do |ch|
523
- assert @format.has_char?( ch )
524
- c += 1
525
- end
526
- assert_equal 2, c
527
- end
528
-
529
- def test_each_sequence
530
- c = 0
531
- @row.each_sequence do |s|
532
- assert @row.has_sequence?( s )
533
- c += 1
534
- end
535
- assert_equal 1, c
536
- end
537
-
538
- def test_number_of_states
539
- assert_equal 1, @format.number_of_states
540
- end
541
-
542
- def test_number_of_chars
543
- assert_equal 2, @format.number_of_chars
544
- end
545
-
546
- def test_number_of_sequences
547
- assert_equal 1, @row.number_of_sequences
548
- end
549
- end
550
- end #end module NeXML
551
- end #end module Bio